All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] make prefix_path() never return NULL
@ 2008-10-05  0:40 Dmitry Potapov
  2008-10-05  2:14 ` [PATCH] do not segfault if make_cache_entry failed Dmitry Potapov
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Potapov @ 2008-10-05  0:40 UTC (permalink / raw)
  To: Shawn O. Pearce, git

There are 9 places where prefix_path is called, and only in one of
them the returned pointer was checked to be non-zero and only to
call exit(128) as it is usually done by die(). In other 8 places,
the returned value was not checked and it caused SIGSEGV when a
path outside of the working tree was used. For instance, running
  git update-index --add /some/path/outside
caused SIGSEGV.

This patch changes prefix_path() to die if the path is outside of
the repository, so it never returns NULL.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
 setup.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/setup.c b/setup.c
index 2e3248a..78a8041 100644
--- a/setup.c
+++ b/setup.c
@@ -110,9 +110,7 @@ const char *prefix_path(const char *prefix, int len, const char *path)
 		if (strncmp(sanitized, work_tree, len) ||
 		    (sanitized[len] != '\0' && sanitized[len] != '/')) {
 		error_out:
-			error("'%s' is outside repository", orig);
-			free(sanitized);
-			return NULL;
+			die("'%s' is outside repository", orig);
 		}
 		if (sanitized[len] == '/')
 			len++;
@@ -216,10 +214,7 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
 	prefixlen = prefix ? strlen(prefix) : 0;
 	while (*src) {
 		const char *p = prefix_path(prefix, prefixlen, *src);
-		if (p)
-			*(dst++) = p;
-		else
-			exit(128); /* error message already given */
+		*(dst++) = p;
 		src++;
 	}
 	*dst = NULL;
-- 
1.6.0.2.445.g1198

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-10-11 16:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-05  0:40 [PATCH] make prefix_path() never return NULL Dmitry Potapov
2008-10-05  2:14 ` [PATCH] do not segfault if make_cache_entry failed Dmitry Potapov
2008-10-05  2:14   ` [PATCH] error out if path is invalid Dmitry Potapov
2008-10-06  7:02     ` Johannes Sixt
2008-10-07  0:22       ` Dmitry Potapov
2008-10-07  6:03         ` Johannes Sixt
2008-10-11 16:39           ` [PATCH] print an error message for invalid path Dmitry Potapov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.