mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -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,11 +748,14 @@ read_args() {
|
||||
#elif defined(IS_FREEBSD)
|
||||
// In FreeBSD, we can use sysctl to determine the command-line arguments.
|
||||
|
||||
size_t bufsize = 4096;
|
||||
char buffer[4096];
|
||||
size_t bufsize = 0;
|
||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0};
|
||||
mib[3] = getpid();
|
||||
if (sysctl(mib, 4, (void*) buffer, &bufsize, nullptr, 0) == -1) {
|
||||
if (sysctl(mib, 4, nullptr, &bufsize, nullptr, 0) == -1) {
|
||||
perror("sysctl");
|
||||
} else {
|
||||
char *buffer = (char *)alloca(bufsize);
|
||||
if (sysctl(mib, 4, buffer, &bufsize, nullptr, 0) == -1) {
|
||||
perror("sysctl");
|
||||
} else {
|
||||
if (_binary_name.empty()) {
|
||||
@ -765,6 +768,7 @@ read_args() {
|
||||
idx += newidx + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(HAVE_GLOBAL_ARGV)
|
||||
int argc = GLOBAL_ARGC;
|
||||
|
Loading…
x
Reference in New Issue
Block a user