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

4 messages from 2019-05-21 to 2019-05-28. Participants: Johannes Schindelin via GitGitGadget, Junio C Hamano.
Thread: https://gitlist.dev/t/51143

## Johannes Schindelin via GitGitGadget, 2019-05-21 17:50

Subject: [PATCH 0/2] Fix two issues pointed out by Coverity
Message-ID: <pull.221.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.221.git.gitgitgadget%40gmail.com

```
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, 2019-05-21 17:50

Subject: [PATCH 1/2] rebase: replace incorrect logical negation by correct bitwise one
Message-ID: <aa0acf4c5ff843a480afdb5715fa03186d82a6d1.1558461018.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/aa0acf4c5ff843a480afdb5715fa03186d82a6d1.1558461018.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.221.git.gitgitgadget@gmail.com>

```
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;
 	}
 
-- 
gitgitgadget


```

## Johannes Schindelin via GitGitGadget, 2019-05-21 17:50

Subject: [PATCH 2/2] bisect--helper: verify HEAD could be parsed before continuing
Message-ID: <f5fa20d2a33e0cacc649c86b540d7d8eeff30a45.1558461018.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/f5fa20d2a33e0cacc649c86b540d7d8eeff30a45.1558461018.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.221.git.gitgitgadget@gmail.com>

```
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(-)

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

```

## Junio C Hamano, 2019-05-28 18:25

Subject: Re: [PATCH 1/2] rebase: replace incorrect logical negation by correct bitwise one
Message-ID: <xmqq5zpu308g.fsf@gitster-ct.c.googlers.com>
URL: https://gitlist.dev/e/xmqq5zpu308g.fsf%40gitster-ct.c.googlers.com
In-Reply-To: <aa0acf4c5ff843a480afdb5715fa03186d82a6d1.1558461018.git.gitgitgadget@gmail.com>

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

> 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...



```
