popen: fix memcpy(dst, NULL, 0)
The `popen_new()` function may be called with inherit_fds = NULL, nr_inherit_fds = 0. The lua/popen.c code actually does this. It leads to the following memcpy() call. ``` memcpy(dst, NULL, 0); ``` According to the C11 standard (n1256, 7.21.1), the pointer argument should have a valid value, which means pointing to some area in the program's address space, not NULL. The standard doesn't make an exception for a zero size array. Personally I doubt that any memcpy() implementation attempts to dereference the source pointer in case of a zero size, but it is my assumption, while the standard is the standard. The problem is found by Coverity. Follows up #8926 NO_DOC=it is a bug NO_CHANGELOG=this code is not released yet NO_TEST=verified by existing test cases, which call popen.new() without the inherit_fds option
Please register or sign in to comment