Skip to contentSkip to conversation

Fix two issues pointed out by Coverity

PATCH In review Johannes Schindelin via GitGitGadget 2 participants 4 messages May 21, 2019 – May 28, 2019

lore
Share & tools
lore
#0 lore raw

cover Fix two issues pointed out by Coverity

I looked very briefly over the issues pointed out by Coverity, and decided to pluck these two low-hanging pieces of fruit.

Johannes Schindelin (2):
rebase: replace incorrect logical negation by correct bitwise one
bisect--helper: verify HEAD could be parsed before continuing

 builtin/bisect--helper.c | 5 ++++-
 builtin/rebase.c         | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

base-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-221%2Fdscho%2Faddress-coverity-reports-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-221/dscho/address-coverity-reports-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/221

Signature · 1 line
gitgitgadget
#1 lore raw

PATCH 1/2 rebase: replace incorrect logical negation by correct bitwise one

From: Johannes Schindelin <[email protected]>

In bff014dac7d9 (builtin rebase: support the verbose and diffstat options, 2018-09-04), we added a line that wanted to remove the REBASE_DIFFSTAT bit from the flags, but it used an incorrect negation.

Found by Coverity.

---
 builtin/rebase.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rebase.c +1 -1
index ba3a574e40..db6ca9bd7d 100644
@@ -1203,7 +1203,7 @@ static int rebase_config(const char *var, const char *value, void *data)
 		if (git_config_bool(var, value))
 			opts->flags |= REBASE_DIFFSTAT;
 		else
-			opts->flags &= !REBASE_DIFFSTAT;
+			opts->flags &= ~REBASE_DIFFSTAT;
 		return 0;
 	}
 
Signature · 1 line
gitgitgadget
#3 lore raw

PATCH 2/2 bisect--helper: verify HEAD could be parsed before continuing

In reply to Johannes Schindelin via GitGitGadget

From: Johannes Schindelin <[email protected]>

In 06f5608c14e6 (bisect--helper: bisect_start shell function partially in C, 2019-01-02), we introduced a call to get_oid() and did not check whether it succeeded before using its output.

---
 builtin/bisect--helper.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
builtin/bisect--helper.c +4 -1
index e7325fe37f..1fbe156e67 100644
@@ -570,7 +570,10 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
 	write_file(git_path_bisect_start(), "%s\n", start_head.buf);
 
 	if (no_checkout) {
-		get_oid(start_head.buf, &oid);
+		if (get_oid(start_head.buf, &oid) < 0) {
+			retval = error(_("invalid ref: '%s'"), start_head.buf);
+			goto finish;
+		}
 		if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
 			       UPDATE_REFS_MSG_ON_ERR)) {
 			retval = -1;
Signature · 1 line
gitgitgadget
#2 lore raw

Re: [PATCH 1/2] rebase: replace incorrect logical negation by correct bitwise one

In reply to Johannes Schindelin via GitGitGadget

"Johannes Schindelin via GitGitGadget" <[email protected]>

Quoted 18 lines · writes:

From: Johannes Schindelin <[email protected]>

In bff014dac7d9 (builtin rebase: support the verbose and diffstat options, 2018-09-04), we added a line that wanted to remove the REBASE_DIFFSTAT bit from the flags, but it used an incorrect negation.

Found by Coverity.

---
 builtin/rebase.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rebase.c +0 -0
index ba3a574e40..db6ca9bd7d 100644

builtin/rebase.c static int rebase_config(const char *var, const char *value, void *data) · line 1208

Quoted 7 lines
builtin/rebase.c +1 -1
@@ -1203,7 +1203,7 @@ static int rebase_config(const char *var, const char *value, void *data)
 		if (git_config_bool(var, value))
 			opts->flags |= REBASE_DIFFSTAT;
 		else
-			opts->flags &= !REBASE_DIFFSTAT;
+			opts->flags &= ~REBASE_DIFFSTAT;
 		return 0;
 	}

Obviously correct. Thanks.

At this point in the codeflow, the .flags field is not touched by parse_options() yet, the configuration codepath only touches that field for REBASE_DIFFSTAT, and because REBASE_DIFFSTAT is not 0, "[rebase] stat = no", which would want only the REBASE_DIFFSTAT bit cleared in the word, can afford to instead assign 0 to the whole word without causing any damage, which is funny way for this bug to be hidden for a long time...