threads / patch / 51143

patch, 2 partsFix two issues pointed out by Coverity

Subject: [PATCH 0/2] Fix two issues pointed out by Coverity

## tl;dr

4 messages between May 21, 2019 and May 28, 2019. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Johannes Schindelin via GitGitGadget· May 21, 2019, 17:50 UTC · lore

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
-- 
gitgitgadget
Johannes Schindelin via GitGitGadget· May 21, 2019, 17:50 UTC · re: Johannes Schindelin via GitGitGadget · lore

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

From: Johannes Schindelin <johannes.schindelin@gmx.de>

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.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/rebase.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/rebase.c +1 −1
diff --git a/builtin/rebase.c b/builtin/rebase.c
index ba3a574e40..db6ca9bd7d 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -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;
 	}
 
-- 
gitgitgadget
Junio C Hamano· May 28, 2019, 18:25 UTC · re: Johannes Schindelin via GitGitGadget · lore

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

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

Show 25 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> 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.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  builtin/rebase.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index ba3a574e40..db6ca9bd7d 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -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...

Johannes Schindelin via GitGitGadget· May 21, 2019, 17:50 UTC · re: Johannes Schindelin via GitGitGadget · lore

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

From: Johannes Schindelin <johannes.schindelin@gmx.de>

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.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/bisect--helper.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Show changes to builtin/bisect--helper.c +4 −1
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index e7325fe37f..1fbe156e67 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -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;
-- 
gitgitgadget

← back to recent threads