mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
dtoolutil: fix buffer overrun on FreeBSD extracting long cmdline args
This happens when compiling with CMake, which passes very long command-lines.
This commit is contained in:
parent
b5d0e9eafc
commit
68d094dba4
@ -748,21 +748,25 @@ read_args() {
|
|||||||
#elif defined(IS_FREEBSD)
|
#elif defined(IS_FREEBSD)
|
||||||
// In FreeBSD, we can use sysctl to determine the command-line arguments.
|
// In FreeBSD, we can use sysctl to determine the command-line arguments.
|
||||||
|
|
||||||
size_t bufsize = 4096;
|
size_t bufsize = 0;
|
||||||
char buffer[4096];
|
|
||||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0};
|
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0};
|
||||||
mib[3] = getpid();
|
mib[3] = getpid();
|
||||||
if (sysctl(mib, 4, (void*) buffer, &bufsize, nullptr, 0) == -1) {
|
if (sysctl(mib, 4, nullptr, &bufsize, nullptr, 0) == -1) {
|
||||||
perror("sysctl");
|
perror("sysctl");
|
||||||
} else {
|
} else {
|
||||||
if (_binary_name.empty()) {
|
char *buffer = (char *)alloca(bufsize);
|
||||||
_binary_name = buffer;
|
if (sysctl(mib, 4, buffer, &bufsize, nullptr, 0) == -1) {
|
||||||
}
|
perror("sysctl");
|
||||||
size_t idx = strlen(buffer) + 1;
|
} else {
|
||||||
while (idx < bufsize) {
|
if (_binary_name.empty()) {
|
||||||
_args.push_back((char*)(buffer + idx));
|
_binary_name = buffer;
|
||||||
size_t newidx = strlen(buffer + idx);
|
}
|
||||||
idx += newidx + 1;
|
size_t idx = strlen(buffer) + 1;
|
||||||
|
while (idx < bufsize) {
|
||||||
|
_args.push_back((char*)(buffer + idx));
|
||||||
|
size_t newidx = strlen(buffer + idx);
|
||||||
|
idx += newidx + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user