about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2016-08-13 11:54:46 +0100
committerJohn Keeping <john@keeping.me.uk>2016-10-01 11:46:55 +0100
commite18a85b6a298feef88da8085ef16fd20ce971071 (patch)
tree617a64efc192421222549ffe7ae522f5959c9ec5
parentui-tag: clean up taginfo (diff)
downloadcgit-pink-e18a85b6a298feef88da8085ef16fd20ce971071.tar.gz
cgit-pink-e18a85b6a298feef88da8085ef16fd20ce971071.zip
ui-tree: remove a fixed size buffer
As libgit.a moves away from using fixed size buffers, there is no
guarantee that PATH_MAX is sufficient for all of the paths in a Git
tree, so we should use a dynamically sized buffer here.

Coverity-Id: 141884
Signed-off-by: John Keeping <john@keeping.me.uk>
-rw-r--r--ui-tree.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ui-tree.c b/ui-tree.c
index 5c31e6a..b98a7f0 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -324,22 +324,25 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
 		const char *pathname, unsigned mode, int stage, void *cbdata)
 {
 	struct walk_tree_context *walk_tree_ctx = cbdata;
-	static char buffer[PATH_MAX];
 
 	if (walk_tree_ctx->state == 0) {
-		memcpy(buffer, base->buf, base->len);
-		strcpy(buffer + base->len, pathname);
-		if (strcmp(walk_tree_ctx->match_path, buffer))
+		struct strbuf buffer = STRBUF_INIT;
+
+		strbuf_addbuf(&buffer, base);
+		strbuf_addstr(&buffer, pathname);
+		if (strcmp(walk_tree_ctx->match_path, buffer.buf))
 			return READ_TREE_RECURSIVE;
 
 		if (S_ISDIR(mode)) {
 			walk_tree_ctx->state = 1;
-			set_title_from_path(buffer);
+			set_title_from_path(buffer.buf);
+			strbuf_release(&buffer);
 			ls_head();
 			return READ_TREE_RECURSIVE;
 		} else {
 			walk_tree_ctx->state = 2;
-			print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev);
+			print_object(sha1, buffer.buf, pathname, walk_tree_ctx->curr_rev);
+			strbuf_release(&buffer);
 			return 0;
 		}
 	}
as a fallback. 2005-10-30[JOBS] Fixed support for disabling job controlHerbert Xu Since nobody has compiled with JOBS turned off for quite a while, it has bit-rotted. This patch makes it build again. 2005-10-29[SYSTEM] Fixed fallback stpcpy implementationHerbert Xu The implementation has an off-by-one bug. This results in random memory corruption. In one particular case, it caused certain bits of a function body to go missing. 2005-10-29[SYSTEM] Added out-of-line ctypes functions for klibcHerbert Xu Unfortunately klibc doesn't provide out-of-line versions of ctypes functions such as isalpha. This is a nasty hack to create them. 2005-10-29[SYSTEM] Include system.h for stpcpy in nodes.cHerbert Xu Since we have a fallback implementation for stpcpy we can now use it unconditionally in nodes.c.pat. This also fixes a link error with klibc. 2005-10-29[SYSTEM] Added dummy sysconf implementationHerbert Xu Add a dummy sysconf implementation that always fails for klibc. 2005-10-29[BUILTIN] Removed standalone/csh support from testHerbert Xu Let's remove the support for standalone support from test for the same reason as printf. 2005-10-29[SYSTEM] Added dummy strtod implementationHerbert Xu klibc doesn't have strtod or atof. So add an implementation that always fails by setting the end pointer to the input string. 2005-10-29[BUILTIN] Removed standalone/csh support from printfHerbert Xu The support for standalone/csh printf only serves to complicate maintainence. 2005-10-29[SYSTEM] Added default definition for SSIZE_MAXHerbert Xu klibc doesn't define the macro SSIZE_MAX. 2005-10-29[BUILTIN] Disable histcmd completely when SMALL is definedHerbert Xu Now that mkbuiltins correctly disabled histcmd we don't need the dummy histcmd implementation anymore. 2005-10-29[BUILTIN] Disable ulimit if there is no getrlimitHerbert Xu For systems without getrlimit (e.g., klibc) we will disable ulimit. In order to achieve this, builtins.def is now produced by cpp which allows us to use macros such as HAVE_GETRLIMIT in it. Thie also means that we can get rid of the cflags parsing code in mkbuiltins. 2005-10-29[SIGNAL] Added default implementation of killpgHerbert Xu klibc doesn't have killpg. Since we only call it for valid values of pid, we can call kill instead. 2005-10-29[SIGNAL] Added default implementation of strsignalHerbert Xu klibc doesn't have strsignal but it does have sys_siglist. 2005-10-29Added missing system.h inclusion for mempcpyHerbert Xu All users of mempcpy must include system.h. 2005-10-29Fixed gcc 4.0 compilation problemsHerbert Xu Removed obsolete extern declaration on funcnest. This conflits with the correct static definition. Changed memtodest prototype to use char * instead of unsigned char *. Perform the unsigned char cast inside memtodest instead. 2005-10-29[EXPAND] Added getpwhome as a wrapper for getpwnamHerbert Xu klibc doesn't have and doesn't need getpwnam. This change creates getpwhome which always returns NULL if getpwnam doesn't exist. 2005-10-29[SYSTEM] Added default implementation of bsearchHerbert Xu Added impelmentation of bsearch since klibc doesn't have it yet. 2005-10-29Use stat if stat64 does not existHerbert Xu 64-bit file calls such as stat64 don't exist on all architectures for dietlibc, and they don't exist at all for klibc. In those cases the normal calls such as stat are already 64-bit. So simply define stat64 as stat if it doesn't exist. Do the same for all other 64-bit calls as well. 2005-10-29[BUILTIN] Stop using sysexits.h in commandcmdHerbert Xu This gets rid of the only reference of sysexits.h in dash which is from commandcmd. This is needed for klibc support since it doesn't have sysexits.h. The only uses of sysexits.h in commandcmd is superfluous anyway. In fact, it is overly sensitive about usages such as 'command -vV ls'. By making its behaviour close to that of bash/ksh, we end up saving a bit of space too. 2005-10-29[SIGNAL] Use bsd_signal if it exists and signal does notHerbert Xu klibc has bsd_signal instead of signal. So we will define signal as bsd_signal if 1) signal does not exist. 2) bsd_signal exists. 2005-10-29[SIGNAL] Removed use of __P from error.hHerbert Xu This is the only instance of __P in the entire source so it makes sense to get rid of it rather than making it work with klibc. 2005-10-29Copyright/licence updates and remove all traces of sys/cdefs.hHerbert Xu This change updates the BSD licence to the three-clause version since NetBSD has already done so. This makes dash GPL-compatible. It also adds Christos Zoulas (NetBSD ash maintainer) to the COPYING file. I've added "copyright by Herbert Xu" to most files. Finally all CVS IDs and inclusion of sys/cdefs.h have been removed. The latter is needed for support of klibc. 2005-10-26[INPUT] Size optimisations in preadbuffer()Herbert Xu Added unlikely markers. Reduced switch coverage. Removed p since we now erase NULs as soon as we see them. Use more to store parselleft. 2005-10-01[INPUT] Fix NUL skipping in preadbufferHerbert Xu On Sun, Sep 25, 2005 at 07:50:54PM +0000, Gerrit Pape wrote: > On Sat, Sep 03, 2005 at 02:56:00PM +0200, Martin Dickopp wrote: > > When analysing the bug I came to the following conclusion: The loop > > beginning at input.c:302 overwrites a single input line with itself, > > skipping NUL characters. Therefore, after the loop the line buffer > > has less characters than originally read if and only if the input line > > contains NUL characters. > > yes. Thanks a lot for the details and patch. > > > The pointer that is used to read from the buffer, 'parsenextc' (cf. > > input.h:66), is also used as the beginning of the next line in > > input.c:296. This fails if the buffer contains less characters > > than originally read into it due to NUL characters. > > > > The proposed patch (attached) keeps track of the number of skipped > > characters and advances 'parsenextc' accordingly before processing > > the next input line. > > Hi Herbert, please see > http://bugs.debian.org/317516 Instead of moving the characters in the loop, we will do memmove every time we see a NUL character. This hurts if there are a lot of NUL characters, but should be a win in normal situations. 2005-09-26Added eflag fixes for trap and minusc.herbert Let evaltree handle traps from cmdloop. Reset evalskip after minusc is executed. Stop executing traps once SKIPEVAL is seen. 2005-09-26Removed unnecessary inclusion of eval.h from parser.c.herbert 2005-09-26Let evaltree handle traps from cmdloop.herbert 2005-09-26Handle SKIPEVAL in read_profile by exiting.herbert 2005-09-26Removed unnecessary inclusion of main.h from eval.c.herbert 2005-09-26Generalise setinputfile for use in read_profile/readcmdfile.herbert 2005-09-26Removed some unnecessary inclusions of input.h.herbert 2005-09-26Turn evalskip into a bit field.herbert This allows SKIPEVAL and SKIPFUNC to coexist which is needed for eval return 1. 2005-09-26Eliminate first null termination in setvar.herbert 2005-09-26Add trailing equal sign in setvar for variables set to null.pape 2005-09-26Get rid of duplicate -g -O2 in CFLAGS.herbert 2005-09-26Cleaned up src/Makefile.am.herbert 2005-09-26Fixed support for cross-compilation.gilles.chanteperdrix 2005-09-26Do not clobber exit status in dotcmd.herbert 2005-09-26Removed redundant setstackmark from dotcmd.herbert 2005-09-26Removed qflag.herbert 2005-09-26Invert return value of test_eaccess and rename it to test_st_mode.herbert 2005-09-26Eliminate duplicate stat in test_eaccess.herbert