mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-22 16:06:30 -05:00
Sanitize addr2line binary path via strspn whitelist before system call
This commit is contained in:
parent
9098e1c4fd
commit
2fbfbc1eae
1 changed files with 18 additions and 6 deletions
24
os/unix.c
24
os/unix.c
|
|
@ -1605,17 +1605,29 @@ void os_abort(void)
|
||||||
if (messages) {
|
if (messages) {
|
||||||
int ret;
|
int ret;
|
||||||
char addr2line[1024];
|
char addr2line[1024];
|
||||||
|
char path[1024];
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
while (msg[j] != '(' && msg[j] != ' ' && msg[j] != 0)
|
while (msg[j] != '(' && msg[j] != ' ' && msg[j] != 0)
|
||||||
++j;
|
++j;
|
||||||
|
|
||||||
snprintf(addr2line, sizeof(addr2line), "addr2line %p -e %.*s", stack[i], (unsigned)j, msg);
|
if (j >= sizeof(path))
|
||||||
|
j = sizeof(path) - 1;
|
||||||
|
memcpy(path, msg, j);
|
||||||
|
path[j] = 0;
|
||||||
|
|
||||||
ret = system(addr2line);
|
/*
|
||||||
if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0)
|
* Verify that the path consists only of safe characters (alphanumeric, slash, dot, dash, underscore).
|
||||||
printf("exit:%d\n", WEXITSTATUS(ret));
|
* This prevents arbitrary command execution via crafted executable names or directories.
|
||||||
if (WIFSIGNALED(ret))
|
*/
|
||||||
printf("signal:%d\n", WTERMSIG(ret));
|
if (j > 0 && strspn(path, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.-_") == j) {
|
||||||
|
snprintf(addr2line, sizeof(addr2line), "addr2line %p -e %s", stack[i], path);
|
||||||
|
|
||||||
|
ret = system(addr2line);
|
||||||
|
if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0)
|
||||||
|
printf("exit:%d\n", WEXITSTATUS(ret));
|
||||||
|
if (WIFSIGNALED(ret))
|
||||||
|
printf("signal:%d\n", WTERMSIG(ret));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue