[PATCH] Fix segfault in maybe_script_execute.

Stefan Liebler stli@linux.ibm.com
Wed Sep 5 13:38:00 GMT 2018


Hi,

If glibc is built with gcc 8 and -march=z900,
the testcase posix/tst-spawn4-compat crashes with a segfault.

In function maybe_script_execute, the new_argv array is dynamically
initialized on stack with (argc + 1) elements.
The function wants to add _PATH_BSHELL as the first argument.
But if argc == 1, it writes three instead of two elements:
new_argv[0] = (char *) _PATH_BSHELL;
new_argv[1] = (char *) args->file;
new_argv[2] = NULL;

The latter write access writes to the same location where the
pointer args is stored on stack.  Then it segfaults while accessing args:
args->exec (new_argv[0], new_argv, args->envp);

If argc > 1, the arguments inclusive the NULL termination of new_argv
is copied from argv with memcpy.

The implementation assumes that argc == 0 will never happen!

Okay to commit?

Bye
Stefan

---

ChangeLog:

	* sysdeps/unix/sysv/linux/spawni.c (maybe_script_execute):
	Increment size of new_argv by one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20180905_maybe_script_execute.patch
Type: text/x-patch
Size: 1721 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20180905/cd02771c/attachment.bin>


More information about the Libc-alpha mailing list