Skip to content

Commit 766d84f

Browse files
committed
fix: buffer size in sscanf format strings
1 parent 89c171b commit 766d84f

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/checksum/checksum.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ verify_crc32sums(const char *pkg_dir, const char *sums_path)
5858
char hash_str[9] = {0};
5959
char rel_path[PATH_MAX];
6060

61-
if (sscanf(line, "%8s %4095s", hash_str, rel_path) != 2)
61+
char fmt[32];
62+
snprintf(fmt, sizeof(fmt), "%%8s %%%zus", sizeof(rel_path) - 1);
63+
if (sscanf(line, fmt, hash_str, rel_path) != 2)
6264
continue;
6365

6466
char *full_path = concat_dirs(pkg_dir, rel_path);
@@ -99,7 +101,9 @@ verify_md5sums(const char *pkg_dir, const char *sums_path)
99101
char hash_str[33] = {0};
100102
char rel_path[PATH_MAX];
101103

102-
if (sscanf(line, "%32s %4095s", hash_str, rel_path) != 2)
104+
char fmt[32];
105+
snprintf(fmt, sizeof(fmt), "%%32s %%%zus", sizeof(rel_path) - 1);
106+
if (sscanf(line, fmt, hash_str, rel_path) != 2)
103107
continue;
104108

105109
char *full_path = concat_dirs(pkg_dir, rel_path);
@@ -148,7 +152,9 @@ verify_sha256sums(const char *pkg_dir, const char *sums_path)
148152
char hash_str[65] = {0};
149153
char rel_path[PATH_MAX];
150154

151-
if (sscanf(line, "%64s %4095s", hash_str, rel_path) != 2)
155+
char fmt[32];
156+
snprintf(fmt, sizeof(fmt), "%%64s %%%zus", sizeof(rel_path) - 1);
157+
if (sscanf(line, fmt, hash_str, rel_path) != 2)
152158
continue;
153159

154160
char *full_path = concat_dirs(pkg_dir, rel_path);

src/install/scripts.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#elif defined(__FreeBSD__)
2121

2222
#include <fcntl.h>
23-
#include <sys/capsicum.h>
2423
#endif
2524

2625
#include "../../include/apg/scripts.h"
@@ -253,14 +252,6 @@ exec_script(const char *path, const char *root_path)
253252
}
254253
}
255254

256-
if (cap_enter() < 0)
257-
{
258-
uint8_t err = 1;
259-
(void)write(pipefd[1], &err, 1);
260-
close(pipefd[1]);
261-
_exit(1);
262-
}
263-
264255
close(pipefd[1]);
265256
char *const argv[] = {(char *)exec_path, NULL};
266257
char *const envp[] = {NULL};

0 commit comments

Comments
 (0)