Skip to content

Commit 1b0a108

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 4ddb4a0 commit 1b0a108

File tree

15 files changed

+32
-32
lines changed

15 files changed

+32
-32
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
@@ -2086,7 +2086,7 @@ int cmd_commit(int argc,
20862086
if (!stat(git_path_merge_mode(the_repository), &statbuf)) {
20872087
if (strbuf_read_file(&sb, git_path_merge_mode(the_repository), 0) < 0)
20882088
die_errno(_("could not read MERGE_MODE"));
2089-
if (!strcmp(sb.buf, "no-ff"))
2089+
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
20902090
allow_fast_forward = 0;
20912091
}
20922092
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)

diagnose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ int create_diagnostics_archive(struct repository *r,
332332
res = error_errno(_("could not read '%s'"), path.buf);
333333
goto diagnose_cleanup;
334334
}
335-
strvec_push(&archiver_args, buf.buf);
335+
strvec_push(&archiver_args, 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
336336
}
337337
closedir(dir);
338338
}

mailinfo.c

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

12361236
int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
12371237
{
1238-
if (!strcmp(actionstr, "nowarn"))
1238+
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
12391239
*action = quoted_cr_nowarn;
1240-
else if (!strcmp(actionstr, "warn"))
1240+
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
12411241
*action = quoted_cr_warn;
1242-
else if (!strcmp(actionstr, "strip"))
1242+
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
12431243
*action = quoted_cr_strip;
12441244
else
12451245
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
@@ -2969,7 +2969,7 @@ static int have_finished_the_last_pick(void)
29692969
}
29702970
}
29712971
/* If there is only one line then we are done */
2972-
eol = strchr(buf.buf, '\n');
2972+
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
29732973
if (!eol || !eol[1])
29742974
ret = 1;
29752975

@@ -3202,9 +3202,9 @@ static int read_populate_opts(struct replay_opts *opts)
32023202

32033203
if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(),
32043204
READ_ONELINER_SKIP_IF_EMPTY)) {
3205-
if (!strcmp(buf.buf, "--rerere-autoupdate"))
3205+
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
32063206
opts->allow_rerere_auto = RERERE_AUTOUPDATE;
3207-
else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
3207+
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
32083208
opts->allow_rerere_auto = RERERE_NOAUTOUPDATE;
32093209
strbuf_reset(&buf);
32103210
}
@@ -3249,7 +3249,7 @@ static int read_populate_opts(struct replay_opts *opts)
32493249
READ_ONELINER_SKIP_IF_EMPTY)) {
32503250
const char *p = ctx->current_fixups.buf;
32513251
ctx->current_fixup_count = 1;
3252-
while ((p = strchr(p, '\n'))) {
3252+
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
32533253
ctx->current_fixup_count++;
32543254
p++;
32553255
}

0 commit comments

Comments
 (0)