Skip to content

Commit 13898b7

Browse files
authored
More CodeQL stuff (#777)
The idea is to move this into the `codeql` sub-branch upon the next rebase.
2 parents a2a1657 + 5c69efd commit 13898b7

File tree

21 files changed

+78
-64
lines changed

21 files changed

+78
-64
lines changed

.github/codeql/codeql-config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: "CodeQL config"
33
queries:
44
- uses: security-extended
55

6+
paths-ignore:
7+
- gitweb/**/*.js # GitWeb is not distributed
8+
69
query-filters:
710
- exclude:
811
# yes, this extra indentation is intentional

.github/workflows/codeql.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
language: ["cpp"]
20+
language: ["cpp", "javascript", "go"]
2121

2222
steps:
2323
- name: Checkout repository
@@ -29,7 +29,10 @@ jobs:
2929
env:
3030
jobname: codeql
3131

32-
# Initializes the CodeQL tools for scanning.
32+
- uses: actions/setup-go@v5
33+
if: matrix.language == 'go'
34+
35+
# Initializes the CodeQL tools for scanning.
3336
- name: Initialize CodeQL
3437
uses: github/codeql-action/init@v3
3538
with:
@@ -42,6 +45,14 @@ jobs:
4245
cat /proc/cpuinfo
4346
make -j$(nproc)
4447
48+
- name: Build (Go)
49+
if: matrix.language == 'go'
50+
run: |
51+
cat /proc/cpuinfo
52+
cd contrib/persistent-https &&
53+
go mod init git-remote-persistent-https &&
54+
make -j$(nproc)
55+
4556
- name: Perform CodeQL Analysis
4657
uses: github/codeql-action/analyze@v3
4758
with:
@@ -55,10 +66,10 @@ jobs:
5566
- name: publish sarif for debugging
5667
uses: actions/upload-artifact@v4
5768
with:
58-
name: sarif-results
69+
name: sarif-results-${{ matrix.language }}
5970
path: sarif-results
6071

6172
- name: Upload SARIF
6273
uses: github/codeql-action/upload-sarif@v3
6374
with:
64-
sarif_file: sarif-results/cpp.sarif
75+
sarif_file: sarif-results/${{ matrix.language }}.sarif

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/help.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static void exec_woman_emacs(const char *path, const char *page)
277277
if (!path)
278278
path = "emacsclient";
279279
strbuf_addf(&man_page, "(woman \"%s\")", page);
280-
execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL);
280+
execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL); // CodeQL [SM01925] justification: Git's help system safely consumes user-controlled environment variables and paths
281281
warning_errno(_("failed to exec '%s'"), path);
282282
strbuf_release(&man_page);
283283
}
@@ -299,7 +299,7 @@ static void exec_man_konqueror(const char *path, const char *page)
299299
} else
300300
path = "kfmclient";
301301
strbuf_addf(&man_page, "man:%s(1)", page);
302-
execlp(path, filename, "newTab", man_page.buf, (char *)NULL);
302+
execlp(path, filename, "newTab", man_page.buf, (char *)NULL); // CodeQL [SM01925] justification: Git's help system safely consumes user-controlled environment variables and paths
303303
warning_errno(_("failed to exec '%s'"), path);
304304
strbuf_release(&man_page);
305305
}
@@ -309,7 +309,7 @@ static void exec_man_man(const char *path, const char *page)
309309
{
310310
if (!path)
311311
path = "man";
312-
execlp(path, "man", page, (char *)NULL);
312+
execlp(path, "man", page, (char *)NULL); // CodeQL [SM01925] justification: Git's help system safely consumes user-controlled environment variables and paths
313313
warning_errno(_("failed to exec '%s'"), path);
314314
}
315315

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)

date.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,14 @@ static int set_date(int year, int month, int day, struct tm *now_tm, time_t now,
524524
if (year == -1) {
525525
if (!now_tm)
526526
return 1;
527-
r->tm_year = now_tm->tm_year;
527+
r->tm_year = now_tm->tm_year; // CodeQL [SM03231] justification: Git's custom date parser intentionally handles years without leap year validation
528528
}
529529
else if (year >= 1970 && year < 2100)
530530
r->tm_year = year - 1900;
531531
else if (year > 70 && year < 100)
532532
r->tm_year = year;
533533
else if (year < 38)
534-
r->tm_year = year + 100;
534+
r->tm_year = year + 100; // CodeQL [SM03231] justification: Git's date parser handles century offsets without leap year validation by design
535535
else
536536
return -1;
537537
if (!now_tm)
@@ -548,7 +548,7 @@ static int set_date(int year, int month, int day, struct tm *now_tm, time_t now,
548548
tm->tm_mon = r->tm_mon;
549549
tm->tm_mday = r->tm_mday;
550550
if (year != -1)
551-
tm->tm_year = r->tm_year;
551+
tm->tm_year = r->tm_year; // CodeQL [SM03231] justification: Git's date parser copies year values without requiring leap year validation
552552
return 0;
553553
}
554554
return -1;
@@ -780,11 +780,11 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
780780
/* Two-digit year? */
781781
if (n == 2 && tm->tm_year < 0) {
782782
if (num < 10 && tm->tm_mday >= 0) {
783-
tm->tm_year = num + 100;
783+
tm->tm_year = num + 100; // CodeQL [SM03231] justification: Git's digit parser handles century calculation without leap year validation
784784
return n;
785785
}
786786
if (num >= 70) {
787-
tm->tm_year = num;
787+
tm->tm_year = num; // CodeQL [SM03231] justification: Git's legacy date parser handles two-digit years without leap year validation by design
788788
return n;
789789
}
790790
}
@@ -1083,7 +1083,7 @@ static time_t update_tm(struct tm *tm, struct tm *now, time_t sec)
10831083
if (tm->tm_year < 0) {
10841084
tm->tm_year = now->tm_year;
10851085
if (tm->tm_mon > now->tm_mon)
1086-
tm->tm_year--;
1086+
tm->tm_year--; // CodeQL [SM03231] justification: Git's date parser adjusts year to handle month comparisons without leap year validation
10871087
}
10881088

10891089
n = mktime(tm) - sec;
@@ -1110,9 +1110,9 @@ static void pending_number(struct tm *tm, int *num)
11101110
if (number > 1969 && number < 2100)
11111111
tm->tm_year = number - 1900;
11121112
else if (number > 69 && number < 100)
1113-
tm->tm_year = number;
1113+
tm->tm_year = number; // CodeQL [SM03231] justification: Git's approxidate parser intentionally assigns years without leap year checks
11141114
else if (number < 38)
1115-
tm->tm_year = 100 + number;
1115+
tm->tm_year = 100 + number; // CodeQL [SM03231] justification: Git's approxidate parser handles century calculation without leap year validation
11161116
/* We screw up for number = 00 ? */
11171117
}
11181118
}
@@ -1304,7 +1304,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
13041304
*num = 0;
13051305
while (n < 0) {
13061306
n += 12;
1307-
tm->tm_year--;
1307+
tm->tm_year--; // CodeQL [SM03231] justification: Git's approxidate parser adjusts years for month calculations without leap year concerns
13081308
}
13091309
tm->tm_mon = n;
13101310
*touched = 1;
@@ -1313,7 +1313,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
13131313

13141314
if (match_string(date, "years") >= 4) {
13151315
update_tm(tm, now, 0); /* fill in date fields if needed */
1316-
tm->tm_year -= *num;
1316+
tm->tm_year -= *num; // CodeQL [SM03231] justification: Git's approxidate parser subtracts years without leap year validation by design
13171317
*num = 0;
13181318
*touched = 1;
13191319
return end;

0 commit comments

Comments
 (0)