Skip to content

Commit 0bb7d99

Browse files
committed
strbuf_read: help with CodeQL misunderstanding that strbuf_read() does NUL-terminate correctly
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 021ddf8 commit 0bb7d99

File tree

14 files changed

+31
-31
lines changed

14 files changed

+31
-31
lines changed

builtin/am.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,33 +434,33 @@ static void am_load(struct am_state *state)
434434
}
435435

436436
read_state_file(&sb, state, "keep", 1);
437-
if (!strcmp(sb.buf, "t"))
437+
if (!strcmp(sb.buf, "t")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
438438
state->keep = KEEP_TRUE;
439-
else if (!strcmp(sb.buf, "b"))
439+
else if (!strcmp(sb.buf, "b")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
440440
state->keep = KEEP_NON_PATCH;
441441
else
442442
state->keep = KEEP_FALSE;
443443

444444
read_state_file(&sb, state, "messageid", 1);
445-
state->message_id = !strcmp(sb.buf, "t");
445+
state->message_id = !strcmp(sb.buf, "t"); // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
446446

447447
read_state_file(&sb, state, "scissors", 1);
448-
if (!strcmp(sb.buf, "t"))
448+
if (!strcmp(sb.buf, "t")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
449449
state->scissors = SCISSORS_TRUE;
450-
else if (!strcmp(sb.buf, "f"))
450+
else if (!strcmp(sb.buf, "f")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
451451
state->scissors = SCISSORS_FALSE;
452452
else
453453
state->scissors = SCISSORS_UNSET;
454454

455455
read_state_file(&sb, state, "quoted-cr", 1);
456456
if (!*sb.buf)
457457
state->quoted_cr = quoted_cr_unset;
458-
else if (mailinfo_parse_quoted_cr_action(sb.buf, &state->quoted_cr) != 0)
458+
else if (mailinfo_parse_quoted_cr_action(sb.buf, &state->quoted_cr) != 0) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
459459
die(_("could not parse %s"), am_path(state, "quoted-cr"));
460460

461461
read_state_file(&sb, state, "apply-opt", 1);
462462
strvec_clear(&state->git_apply_opts);
463-
if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0)
463+
if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
464464
die(_("could not parse %s"), am_path(state, "apply-opt"));
465465

466466
state->rebasing = !!file_exists(am_path(state, "rebasing"));

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
120120
continue;
121121
len = read_in_full(fd, signature, 8);
122122
close(fd);
123-
if (len != 8 || strncmp(signature, "gitdir: ", 8))
123+
if (len != 8 || strncmp(signature, "gitdir: ", 8)) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
124124
continue;
125125
dst = read_gitfile(path->buf);
126126
if (dst) {

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ int cmd_commit(int argc,
18681868
if (!stat(git_path_merge_mode(the_repository), &statbuf)) {
18691869
if (strbuf_read_file(&sb, git_path_merge_mode(the_repository), 0) < 0)
18701870
die_errno(_("could not read MERGE_MODE"));
1871-
if (!strcmp(sb.buf, "no-ff"))
1871+
if (!strcmp(sb.buf, "no-ff")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
18721872
allow_fast_forward = 0;
18731873
}
18741874
if (allow_fast_forward)

builtin/rebase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,9 @@ static int read_basic_state(struct rebase_options *opts)
483483
if (!read_oneliner(&buf, state_dir_path("allow_rerere_autoupdate", opts),
484484
READ_ONELINER_WARN_MISSING))
485485
return -1;
486-
if (!strcmp(buf.buf, "--rerere-autoupdate"))
486+
if (!strcmp(buf.buf, "--rerere-autoupdate")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
487487
opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE;
488-
else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
488+
else if (!strcmp(buf.buf, "--no-rerere-autoupdate")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
489489
opts->allow_rerere_autoupdate = RERERE_NOAUTOUPDATE;
490490
else
491491
warning(_("ignoring invalid allow_rerere_autoupdate: "

bundle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int parse_bundle_signature(struct bundle_header *header, const char *line
6666
int i;
6767

6868
for (i = 0; i < ARRAY_SIZE(bundle_sigs); i++) {
69-
if (!strcmp(line, bundle_sigs[i].signature)) {
69+
if (!strcmp(line, bundle_sigs[i].signature)) { // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
7070
header->version = bundle_sigs[i].version;
7171
return 0;
7272
}
@@ -82,7 +82,7 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
8282

8383
/* The bundle header begins with the signature */
8484
if (strbuf_getwholeline_fd(&buf, fd, '\n') ||
85-
parse_bundle_signature(header, buf.buf)) {
85+
parse_bundle_signature(header, buf.buf)) { // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
8686
if (report_path)
8787
error(_("'%s' does not look like a v2 or v3 bundle file"),
8888
report_path);

credential.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static char *credential_ask_one(const char *what, struct credential *c,
258258

259259
strbuf_release(&desc);
260260
strbuf_release(&prompt);
261-
return xstrdup(r);
261+
return xstrdup(r); // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
262262
}
263263

264264
static int credential_getpass(struct repository *r, struct credential *c)

mailinfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,11 +1238,11 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
12381238

12391239
int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
12401240
{
1241-
if (!strcmp(actionstr, "nowarn"))
1241+
if (!strcmp(actionstr, "nowarn")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
12421242
*action = quoted_cr_nowarn;
1243-
else if (!strcmp(actionstr, "warn"))
1243+
else if (!strcmp(actionstr, "warn")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
12441244
*action = quoted_cr_warn;
1245-
else if (!strcmp(actionstr, "strip"))
1245+
else if (!strcmp(actionstr, "strip")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
12461246
*action = quoted_cr_strip;
12471247
else
12481248
return -1;

prompt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static char *do_askpass(const char *cmd, const char *prompt)
3737
return NULL;
3838
}
3939

40-
strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
40+
strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n")); // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
4141

4242
return buffer.buf;
4343
}

sequencer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,7 @@ static int have_finished_the_last_pick(void)
29712971
}
29722972
}
29732973
/* If there is only one line then we are done */
2974-
eol = strchr(buf.buf, '\n');
2974+
eol = strchr(buf.buf, '\n'); // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
29752975
if (!eol || !eol[1])
29762976
ret = 1;
29772977

@@ -3204,9 +3204,9 @@ static int read_populate_opts(struct replay_opts *opts)
32043204

32053205
if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(),
32063206
READ_ONELINER_SKIP_IF_EMPTY)) {
3207-
if (!strcmp(buf.buf, "--rerere-autoupdate"))
3207+
if (!strcmp(buf.buf, "--rerere-autoupdate")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
32083208
opts->allow_rerere_auto = RERERE_AUTOUPDATE;
3209-
else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
3209+
else if (!strcmp(buf.buf, "--no-rerere-autoupdate")) // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
32103210
opts->allow_rerere_auto = RERERE_NOAUTOUPDATE;
32113211
strbuf_reset(&buf);
32123212
}
@@ -3251,7 +3251,7 @@ static int read_populate_opts(struct replay_opts *opts)
32513251
READ_ONELINER_SKIP_IF_EMPTY)) {
32523252
const char *p = ctx->current_fixups.buf;
32533253
ctx->current_fixup_count = 1;
3254-
while ((p = strchr(p, '\n'))) {
3254+
while ((p = strchr(p, '\n'))) { // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
32553255
ctx->current_fixup_count++;
32563256
p++;
32573257
}

strvec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void strvec_push_nodup(struct strvec *array, char *value)
2222

2323
const char *strvec_push(struct strvec *array, const char *value)
2424
{
25-
strvec_push_nodup(array, xstrdup(value));
25+
strvec_push_nodup(array, xstrdup(value)); // CodeQL [SM01932] justification: CodeQL is wrong here because the value is read from a file via strbuf_read() which does NUL-terminate the string, something CodeQL fails to understand
2626
return array->v[array->nr - 1];
2727
}
2828

0 commit comments

Comments
 (0)