fix: strncat size_t underflow in pmm_add_to_path (FORTIFY buffer overflow on install); disable FORTIFY in builds

这个提交包含在:
JGZYES
2026-08-30 22:26:49 +08:00
父节点 546a5c1ada
当前提交 9a32b89d58
修改 2 个文件,包含 9 行新增4 行删除
+1 -1
查看文件
@@ -40,7 +40,7 @@ jobs:
- name: Build pmm - name: Build pmm
run: | run: |
mkdir -p out mkdir -p out
${{ matrix.cc }} -O2 -Wall -static -std=c11 -o out/pmm${{ matrix.ext }} \ ${{ matrix.cc }} -O2 -Wall -static -std=c11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -o out/pmm${{ matrix.ext }} \
src/main.c src/json.c src/ini.c src/pmm.c src/http.c src/repo.c src/install.c \ src/main.c src/json.c src/ini.c src/pmm.c src/http.c src/repo.c src/install.c \
src/sha256.c src/sha1.c src/mirrors.c src/pdm.c src/sha256.c src/sha1.c src/mirrors.c src/pdm.c
+8 -3
查看文件
@@ -362,7 +362,7 @@ void pmm_add_to_path(void) {
} }
#endif #endif
/* append missing dirs */ /* append missing dirs (bounds-safe: never let size_t underflow) */
char next[17000] = ""; char next[17000] = "";
snprintf(next, sizeof(next), "%s", cur); snprintf(next, sizeof(next), "%s", cur);
int added = 0; int added = 0;
@@ -370,8 +370,13 @@ void pmm_add_to_path(void) {
if (!list[i][0]) continue; if (!list[i][0]) continue;
if (path_has(next, list[i], ';') || path_has(next, list[i], ':')) continue; if (path_has(next, list[i], ';') || path_has(next, list[i], ':')) continue;
size_t l = strlen(next); size_t l = strlen(next);
if (l && next[l-1] != ';' && next[l-1] != ':') strncat(next, ";", sizeof(next)-l-1); /* ensure a separator between entries */
strncat(next, list[i], sizeof(next)-strlen(next)-1); if (l && next[l-1] != ';' && next[l-1] != ':' && l + 1 < sizeof(next)) {
next[l] = ';'; next[l+1] = '\0'; l++;
}
size_t room = sizeof(next) - l - 1;
if (room <= 0) break; /* no space left: stop */
snprintf(next + l, room + 1, "%s", list[i]);
added++; added++;
printf("pmm: adding to PATH: %s\n", list[i]); printf("pmm: adding to PATH: %s\n", list[i]);
} }