From 5743350f696745a48dfe7976c98dc8eb5c842d72 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 26 May 2011 15:54:18 +0200 Subject: rerere.c: diagnose a corrupt MERGE_RR when hitting EOF between TAB and '\0' If we reach EOF after the SHA1-then-TAB, yet before the NUL that terminates each file name, we would fill the file name buffer with \255 bytes resulting from the repeatedly-failing fgetc (returns EOF/-1) and ultimately complain about "filename too long", because no NUL was encountered. Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- rerere.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rerere.c b/rerere.c index d26084347..283a0024b 100644 --- a/rerere.c +++ b/rerere.c @@ -42,8 +42,14 @@ static void read_rr(struct string_list *rr) name = xstrdup(buf); if (fgetc(in) != '\t') die("corrupt MERGE_RR"); - for (i = 0; i < sizeof(buf) && (buf[i] = fgetc(in)); i++) - ; /* do nothing */ + for (i = 0; i < sizeof(buf); i++) { + int c = fgetc(in); + if (c < 0) + die("corrupt MERGE_RR"); + buf[i] = c; + if (c == 0) + break; + } if (i == sizeof(buf)) die("filename too long"); string_list_insert(rr, buf)->util = name; -- cgit v1.2.1 From 5dd564895e84eacfc728183fb5a9215665ff59a3 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 26 May 2011 15:58:16 +0200 Subject: remove tests of always-false condition * fsck.c (fsck_error_function): Don't test obj->sha1 == 0. It can never be true, since that sha1 member is an array. * transport.c (set_upstreams): Likewise for ref->new_sha1. Signed-off-by: Jim Meyering Signed-off-by: Junio C Hamano --- fsck.c | 2 +- transport.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsck.c b/fsck.c index 3d05d4a79..c17a538de 100644 --- a/fsck.c +++ b/fsck.c @@ -350,7 +350,7 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...) int len; struct strbuf sb = STRBUF_INIT; - strbuf_addf(&sb, "object %s:", obj->sha1?sha1_to_hex(obj->sha1):"(null)"); + strbuf_addf(&sb, "object %s:", sha1_to_hex(obj->sha1)); va_start(ap, fmt); len = vsnprintf(sb.buf + sb.len, strbuf_avail(&sb), fmt, ap); diff --git a/transport.c b/transport.c index 007866061..26d4e5234 100644 --- a/transport.c +++ b/transport.c @@ -156,7 +156,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs, continue; if (!ref->peer_ref) continue; - if (!ref->new_sha1 || is_null_sha1(ref->new_sha1)) + if (is_null_sha1(ref->new_sha1)) continue; /* Follow symbolic refs (mainly for HEAD). */ -- cgit v1.2.1 From b1905aeac5aded421cd90f8d264e27bb39672b36 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 26 May 2011 12:28:44 -0400 Subject: read_gitfile_gently: use ssize_t to hold read result Otherwise, a negative error return becomes a very large read value. We catch this in practice because we compare the expected and actual numbers of bytes (and you are not likely to be reading (size_t)-1 bytes), but this makes the correctness a little more obvious. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.c b/setup.c index dadc66659..a975c8b10 100644 --- a/setup.c +++ b/setup.c @@ -272,7 +272,7 @@ const char *read_gitfile_gently(const char *path) const char *slash; struct stat st; int fd; - size_t len; + ssize_t len; if (stat(path, &st)) return NULL; -- cgit v1.2.1 From 7a45c313964e293f45384ca0a2ae1d326c83a061 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 26 May 2011 13:46:56 -0700 Subject: Documentation/technical/api-diff.txt: correct name of diff_unmerge() Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- Documentation/technical/api-diff.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/technical/api-diff.txt b/Documentation/technical/api-diff.txt index 20b0241d3..2d2ebc04b 100644 --- a/Documentation/technical/api-diff.txt +++ b/Documentation/technical/api-diff.txt @@ -32,7 +32,7 @@ Calling sequence * As you find different pairs of files, call `diff_change()` to feed modified files, `diff_addremove()` to feed created or deleted files, - or `diff_unmerged()` to feed a file whose state is 'unmerged' to the + or `diff_unmerge()` to feed a file whose state is 'unmerged' to the API. These are thin wrappers to a lower-level `diff_queue()` function that is flexible enough to record any of these kinds of changes. @@ -50,7 +50,7 @@ Data structures This is the internal representation for a single file (blob). It records the blob object name (if known -- for a work tree file it typically is a NUL SHA-1), filemode and pathname. This is what the -`diff_addremove()`, `diff_change()` and `diff_unmerged()` synthesize and +`diff_addremove()`, `diff_change()` and `diff_unmerge()` synthesize and feed `diff_queue()` function with. * `struct diff_filepair` -- cgit v1.2.1 From f5799e05c0e7fbee32ca32995c7c4a627eeff469 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 26 May 2011 13:52:04 -0700 Subject: git-submodule.sh: separate parens by a space to avoid confusing some shells Some shells interpret '(( ))' according to the rules for arithmetic expansion. This may not follow POSIX, but is prevalent in commonly used shells. Bash does not have a problem with this particular instance of '((', likely because it is not followed by a '))', but the public domain ksh does, and so does ksh on IRIX 6.5. So, add a space between the parenthesis to avoid confusing these shells. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- git-submodule.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-submodule.sh b/git-submodule.sh index b010a6730..4361ae418 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -491,7 +491,7 @@ cmd_update() # Run fetch only if $sha1 isn't present or it # is not reachable from a ref. (clear_local_git_env; cd "$path" && - ((rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) && + ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) && test -z "$rev") || git-fetch)) || die "Unable to fetch in submodule path '$path'" fi -- cgit v1.2.1