Skip to content

Commit 0b03b30

Browse files
committed
strbuf_read: help with CodeQL misunderstanding that strbuf_read() does NUL-terminate correctly
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent d62134b commit 0b03b30

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
@@ -1875,7 +1875,7 @@ int cmd_commit(int argc,
18751875
if (!stat(git_path_merge_mode(the_repository), &statbuf)) {
18761876
if (strbuf_read_file(&sb, git_path_merge_mode(the_repository), 0) < 0)
18771877
die_errno(_("could not read MERGE_MODE"));
1878-
if (!strcmp(sb.buf, "no-ff"))
1878+
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
18791879
allow_fast_forward = 0;
18801880
}
18811881
if (allow_fast_forward)

builtin/rebase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ static int read_basic_state(struct rebase_options *opts)
482482
if (!read_oneliner(&buf, state_dir_path("allow_rerere_autoupdate", opts),
483483
READ_ONELINER_WARN_MISSING))
484484
return -1;
485-
if (!strcmp(buf.buf, "--rerere-autoupdate"))
485+
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
486486
opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE;
487-
else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
487+
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
488488
opts->allow_rerere_autoupdate = RERERE_NOAUTOUPDATE;
489489
else
490490
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
@@ -2960,7 +2960,7 @@ static int have_finished_the_last_pick(void)
29602960
}
29612961
}
29622962
/* If there is only one line then we are done */
2963-
eol = strchr(buf.buf, '\n');
2963+
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
29642964
if (!eol || !eol[1])
29652965
ret = 1;
29662966

@@ -3193,9 +3193,9 @@ static int read_populate_opts(struct replay_opts *opts)
31933193

31943194
if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(),
31953195
READ_ONELINER_SKIP_IF_EMPTY)) {
3196-
if (!strcmp(buf.buf, "--rerere-autoupdate"))
3196+
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
31973197
opts->allow_rerere_auto = RERERE_AUTOUPDATE;
3198-
else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
3198+
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
31993199
opts->allow_rerere_auto = RERERE_NOAUTOUPDATE;
32003200
strbuf_reset(&buf);
32013201
}
@@ -3240,7 +3240,7 @@ static int read_populate_opts(struct replay_opts *opts)
32403240
READ_ONELINER_SKIP_IF_EMPTY)) {
32413241
const char *p = ctx->current_fixups.buf;
32423242
ctx->current_fixup_count = 1;
3243-
while ((p = strchr(p, '\n'))) {
3243+
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
32443244
ctx->current_fixup_count++;
32453245
p++;
32463246
}

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)