git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Karl Chen <quarl@cs.berkeley.edu>
Cc: Jeff King <peff@peff.net>, Johannes Sixt <j.sixt@viscovery.net>,
	git@vger.kernel.org
Subject: Re: [PATCH v4] Expand ~ and ~user in core.excludesfile, commit.template
Date: Fri, 29 Aug 2008 09:08:35 -0700	[thread overview]
Message-ID: <7vsksn4xdo.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <quack.20080829T0229.lthhc94rwyr_-_@roar.cs.berkeley.edu> (Karl Chen's message of "Fri, 29 Aug 2008 02:29:00 -0700")

Karl Chen <quarl@cs.berkeley.edu> writes:

> These config variables are parsed to substitute ~ and ~user with getpw
> entries.
>
> user_path() refactored into new function expand_user_path(), to allow
> dynamically allocating the return buffer.
>
> Signed-off-by: Karl Chen <quarl@quarl.org>

Thanks.

> ... Anyway, I accept the color you picked for this
> bikeshed.

I do not think Documentation/CodingStyle is bikesheding but just behaving
like Romans do while in Rome, so that the end result will blend in better.

>     Hannes> You really should use the strbuf API here. Look for
>     Hannes> strbuf_detach() in the existing code.
>
> Unfortunately expand_user_path() needs to support both a fixed
> buffer and mallocing return.  I don't think the strbuf API can do
> that easily?

I do not see any strong reason why the single caller of user_path() has to
keep using the static allocation.  Would it help to reduce the complexity
of your expand_user_path() implementation, if we fixed the caller along
the lines of this patch (untested, but just to illustrate the point)?

 path.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git i/path.c w/path.c
index 76e8872..c5b253c 100644
--- i/path.c
+++ w/path.c
@@ -221,19 +221,22 @@ char *enter_repo(char *path, int strict)
 		if (PATH_MAX <= len)
 			return NULL;
 		if (path[0] == '~') {
-			if (!user_path(used_path, path, PATH_MAX))
+			char *newpath = expand_user_path(path);
+			if (!newpath || (PATH_MAX <= strlen(newpath))) {
+				if (path != newpath)
+					free(newpath);
 				return NULL;
+			}
 			strcpy(validated_path, path);
-			path = used_path;
-		}
-		else if (PATH_MAX - 10 < len)
-			return NULL;
-		else {
+			path = newpath;
+		} else {
 			path = strcpy(used_path, path);
 			strcpy(validated_path, path);
 		}
 		len = strlen(path);
 		for (i = 0; suffix[i]; i++) {
+			if (PATH_MAX <= strlen(suffix[i] + len))
+				continue;
 			strcpy(path + len, suffix[i]);
 			if (!access(path, F_OK)) {
 				strcat(validated_path, suffix[i]);

  reply	other threads:[~2008-08-29 16:09 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-22  4:14 [PATCH] Support "core.excludesfile = ~/.gitignore" Karl Chen
2008-08-22 16:58 ` Eric Raible
2008-08-22 17:56   ` Bert Wesarg
2008-08-22 21:10 ` Junio C Hamano
2008-08-24  8:40   ` Karl Chen
2008-08-24 18:11     ` Junio C Hamano
2008-08-24 22:08       ` Jeff King
2008-08-24 22:59         ` Junio C Hamano
2008-08-24 23:13           ` Jeff King
2008-08-24 23:40             ` Junio C Hamano
2008-08-24 23:51               ` limiting relationship of git dir and worktree (was Re: [PATCH] Support "core.excludesfile = ~/.gitignore") Jeff King
2008-08-25  0:30                 ` Dropping core.worktree and GIT_WORK_TREE support (was Re: limiting relationship of git dir and worktree) Junio C Hamano
2008-08-25  2:00                   ` Miklos Vajna
2008-08-25  3:05                     ` Dropping core.worktree and GIT_WORK_TREE support Junio C Hamano
2008-08-25 12:52                       ` Miklos Vajna
2008-08-25 13:52                         ` Nguyen Thai Ngoc Duy
2008-08-25 14:43                           ` [PATCH] git diff/diff-index/diff-files: call setup_work_tree() Miklos Vajna
2008-08-25 14:46                             ` Nguyen Thai Ngoc Duy
2008-08-25 14:50                               ` Miklos Vajna
2008-08-25 15:11                                 ` Miklos Vajna
2008-08-25 15:26                                   ` Nguyen Thai Ngoc Duy
2008-08-26 23:58                                     ` Junio C Hamano
2008-08-28 13:02                                       ` [PATCH] diff*: fix worktree setup Nguyễn Thái Ngọc Duy
2008-08-25 21:21                         ` Dropping core.worktree and GIT_WORK_TREE support Junio C Hamano
2008-08-25 21:37                           ` Miklos Vajna
2008-08-26  7:35                   ` Dropping core.worktree and GIT_WORK_TREE support (was Re: limiting relationship of git dir and worktree) Michael J Gruber
2008-08-27  0:49                     ` Jeff King
2008-08-25 19:07               ` [PATCH v2] Support "core.excludesfile = ~/.gitignore" Karl Chen
2008-08-26  6:42                 ` Johannes Sixt
2008-08-27  0:25                 ` Jeff King
2008-08-27  3:12                   ` Karl Chen
2008-08-27  5:01                     ` Junio C Hamano
2008-08-28  9:09                       ` [PATCH v3] Expand ~ and ~user in core.excludesfile, commit.template Karl Chen
2008-08-29  3:26                         ` Jeff King
2008-08-29  4:08                           ` Junio C Hamano
2008-08-29  9:29                             ` [PATCH v4] " Karl Chen
2008-08-29 16:08                               ` Junio C Hamano [this message]
2008-08-29 19:01                                 ` Karl Chen
2008-08-29 19:28                                   ` Junio C Hamano
2008-08-29 22:34                                     ` Karl Chen
2008-08-30  5:31                                       ` Junio C Hamano
2008-08-30  6:02                               ` Jeff King
2008-08-29  7:00                         ` [PATCH v3] " Johannes Sixt
2008-08-27  3:18                   ` [PATCH v2] Support "core.excludesfile = ~/.gitignore" Karl Chen
2008-08-27  4:50                     ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2009-11-18  7:29 [PATCH v3] Expand ~ and ~user in core.excludesfile, commit.template Matthieu Moy
2009-11-18  8:58 ` [PATCH v4] " Matthieu Moy
2009-11-19 18:12   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vsksn4xdo.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    --cc=peff@peff.net \
    --cc=quarl@cs.berkeley.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).