mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Replace malloc with alloca in fork child exec path for async-signal safety
This commit is contained in:
parent
19173754ec
commit
84297fc6dc
3 changed files with 8 additions and 4 deletions
|
|
@ -70,7 +70,7 @@ dnl Checks for header files.
|
|||
AC_HEADER_ASSERT
|
||||
AC_HEADER_DIRENT
|
||||
AC_HEADER_SYS_WAIT
|
||||
AC_CHECK_HEADERS([stdint.h inttypes.h unistd.h math.h execinfo.h strings.h getopt.h syslog.h grp.h pwd.h io.h])
|
||||
AC_CHECK_HEADERS([stdint.h inttypes.h unistd.h math.h execinfo.h strings.h getopt.h syslog.h grp.h pwd.h io.h alloca.h])
|
||||
AC_CHECK_HEADERS([sys/file.h sys/sysctl.h sys/ioctl.h sys/time.h sys/types.h sys/mkdev.h sys/sysmacros.h sys/stat.h sys/prctl.h sys/sysinfo.h sys/utsname.h])
|
||||
AC_CHECK_HEADERS([linux/fs.h linux/btrfs.h linux/fiemap.h mach/mach_time.h])
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,10 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
||||
#if TIME_WITH_SYS_TIME
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
|
|
|||
|
|
@ -863,9 +863,9 @@ int os_script(char** argv, char** envp, const char* run_as_user)
|
|||
++envv_count;
|
||||
}
|
||||
int scrubbed_count = sizeof(envp_scrubbed) / sizeof(envp_scrubbed[0]) - 1;
|
||||
char** envp_dynamic = malloc((size_t)(scrubbed_count + envv_count + 1) * sizeof(char*));
|
||||
if (!envp_dynamic)
|
||||
_exit(126);
|
||||
|
||||
/* use alloca instead of malloc after fork for async-signal safety in multithreaded process */
|
||||
char** envp_dynamic = alloca((size_t)(scrubbed_count + envv_count + 1) * sizeof(char*));
|
||||
for (int i = 0; i < scrubbed_count; ++i) {
|
||||
envp_dynamic[i] = envp_scrubbed[i];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue