Skip to content

Commit

Permalink
loader: fix page fault at /init scan
Browse files Browse the repository at this point in the history
scandir() syscall can fail returning -1 , if e.g. rootfs was not mounted.
In that case subsequent free() call try to deallocate some garbage pointer
in namelist variable, leading to page faults.

Initialize namelist to nullptr so that free() always gets valid pointer value.

Signed-off-by: Sergiy Kibrik <sergiy.kibrik@globallogic.com>
Message-Id: <1486655734-4431-1-git-send-email-sergiy.kibrik@globallogic.com>
  • Loading branch information
Sergiy Kibrik' via OSv Development authored and myechuri committed Jun 22, 2017
1 parent 1420429 commit dcd5c83
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ void* do_main_thread(void *_main_args)
// Run command lines in /init/* before the manual command line
if (opt_init) {
std::vector<std::vector<std::string>> init_commands;
struct dirent **namelist;
struct dirent **namelist = nullptr;
int count = scandir("/init", &namelist, NULL, alphasort);
for (int i = 0; i < count; i++) {
if (!strcmp(".", namelist[i]->d_name) ||
Expand Down

0 comments on commit dcd5c83

Please sign in to comment.