List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 4/4] ui-tree: remove a fixed size buffer
Date: Sat, 13 Aug 2016 12:04:32 +0100	[thread overview]
Message-ID: <d54055a11c050b4f7724885ccc83a0bf5999d988.1471085819.git.john@keeping.me.uk> (raw)
In-Reply-To: <057c333e857a0fb1583cbeb68906df3ac80e18c4.1471085819.git.john@keeping.me.uk>

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 at keeping.me.uk>
---
 ui-tree.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/ui-tree.c b/ui-tree.c
index 120066c..9966f75 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -258,22 +258,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;
 		}
 	}
-- 
2.9.2.639.g855ae9f



      parent reply	other threads:[~2016-08-13 11:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-13 11:04 [PATCH 1/4] shared: remove return value from cgit_free_commitinfo() john
2016-08-13 11:04 ` [PATCH 2/4] shared: make cgit_free_taginfo() public john
2016-08-13 11:04 ` [PATCH 3/4] ui-tag: clean up taginfo john
2016-08-13 11:04 ` john [this message]

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=d54055a11c050b4f7724885ccc83a0bf5999d988.1471085819.git.john@keeping.me.uk \
    --to=cgit@lists.zx2c4.com \
    /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).