Opened 6 years ago

Closed 6 years ago

#11618 closed bug (invalid)

[libroot] readdir crashes

Reported by: waddlesplash Owned by: nobody
Priority: normal Milestone: R1/beta1
Component: System/POSIX Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All


Not sure what the cause is. This is triggered repeatedly by Mupen64 (port recipe is currently in a pull request) [main/plugin.c line 240].

Backtrace attached.

Attachments (1) (10.6 KB ) - added by waddlesplash 6 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by anevilyak, 6 years ago

Looks more likely to be an application-side bug (I.e. passing in a null pointer for one of the parameters).

comment:2 by waddlesplash, 6 years ago

Here's the snippet of code:

   DIR *dir;
   char cwd[1024];
   struct dirent *entry;

   liste_plugins = (plugins*)malloc(sizeof(plugins));
   liste_plugins->type = -1;
   liste_plugins->next = NULL;

   strcpy(cwd, directory);
   strcat(cwd, "plugins");
   dir = opendir(cwd);
   while((entry = readdir(dir)) != NULL)

It's known to work on at least Linux & FreeBSD. An older version of this code (that is identical as far as opendir/readdir is concerned) also works on BeOS (the binary does not run on Haiku due to different libsdl/libzs).

EDIT: directory is a const char * that is an argument to this function.

Last edited 6 years ago by waddlesplash (previous) (diff)

comment:3 by anevilyak, 6 years ago

And the value of directory in this case is? It should be noted that the code's not checking the result of opendir(), so if it's passing a value to it that's not correct for Haiku (i.e. a hardcoded path that may have been OK on BeOS, but has changed due to differences in Haiku's directory hierarchy), then the subsequent readdir() will indeed crash due to being passed an invalid pointer.

comment:4 by waddlesplash, 6 years ago

Unfortunately after doing a clean build with a printf just before the opendir call, I get a totally different behavior and it doesn't crash (a prior function creates the directory and then it works). Probably there was some patching mixup on my part that caused the issue.

Sorry for the noise!

comment:5 by anevilyak, 6 years ago

Resolution: invalid
Status: newclosed

Thanks for the update!

Note: See TracTickets for help on using tickets.