zos: fix scandir() error path NULL pointer deref
Commit b5155dd2 ("zos: return on realloc failure in scandir()")
introduced a bug where `nl` is dereferenced when it's NULL after
reallocation fails.
PR-URL: https://github.com/libuv/libuv/pull/2734
Refs: https://github.com/libuv/libuv/pull/2693
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
parent
b5155dd2ac
commit
a9974da019
@ -43,6 +43,7 @@ int scandir(const char* maindir, struct dirent*** namelist,
|
||||
int (*compar)(const struct dirent**,
|
||||
const struct dirent **)) {
|
||||
struct dirent** nl;
|
||||
struct dirent** nl_copy;
|
||||
struct dirent* dirent;
|
||||
unsigned count;
|
||||
size_t allocated;
|
||||
@ -66,11 +67,13 @@ int scandir(const char* maindir, struct dirent*** namelist,
|
||||
goto error;
|
||||
memcpy(copy, dirent, sizeof(*copy));
|
||||
|
||||
nl = uv__realloc(nl, sizeof(*copy) * (count + 1));
|
||||
if (nl == NULL) {
|
||||
nl_copy = uv__realloc(nl, sizeof(*copy) * (count + 1));
|
||||
if (nl_copy == NULL) {
|
||||
uv__free(copy);
|
||||
goto error;
|
||||
}
|
||||
|
||||
nl = nl_copy;
|
||||
nl[count++] = copy;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user