Ticket #1097: 0001-Fix-stack-overflow.patch

File 0001-Fix-stack-overflow.patch, 809 bytes (added by Matt Fischer, 6 years ago)
  • src/util.c

    old new lilv_dir_for_each(const char* path, 
    517517#else
    518518    DIR* dir = opendir(path);
    519519    if (dir) {
    520         struct dirent  entry;
     520        long name_max = pathconf(path, _PC_NAME_MAX);
     521        if (name_max == -1)         /* Limit not defined, or error */
     522            name_max = 255;         /* Take a guess */
     523        long len = offsetof(struct dirent, d_name) + name_max + 1;
     524        struct dirent *entryp = malloc(len);
    521525        struct dirent* result;
    522         while (!readdir_r(dir, &entry, &result) && result) {
    523             f(path, entry.d_name, data);
     526        while (!readdir_r(dir, entryp, &result) && result) {
     527            f(path, entryp->d_name, data);
    524528        }
     529        free(entryp);
    525530        closedir(dir);
    526531    }
    527532#endif