Ticket #2185: module.cpp.diff

File module.cpp.diff, 1.2 KB (added by kaoutsis, 16 years ago)
  • src/system/kernel/module.cpp

     
    958958                    image->name)) != NULL) {
    959959            // even if strlcpy() is used here, it's by no means safe
    960960            // against buffer overflows
    961             size_t length = strlcpy(path, "/boot/beos/system/add-ons/kernel/",
    962                 sizeof(path));
    963             strlcpy(path + length, name, strlen(image->name)
    964                 + 1 + (suffix - name));
     961            KPath addonsKernelPath;
     962            status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, gBootDevice,
     963                false, addonsKernelPath.LockBuffer(), addonsKernelPath.BufferSize());
     964            if (status < B_OK) {
     965                dprintf("register_preloaded_module_image: Failed when find_directory \"%s\"\n",
     966                    strerror(status));
     967            } else {
     968                addonsKernelPath.UnlockBuffer();
     969                addonsKernelPath.Append("kernel/");
     970                size_t length = strlcpy(path, addonsKernelPath.Path(), sizeof(path));
     971                strlcpy(path + length, name, strlen(image->name)
     972                    + 1 + (suffix - name));
    965973
    966             moduleImage->path = strdup(path);
     974                moduleImage->path = strdup(path);
     975            }
    967976        } else
    968977            moduleImage->path = strdup(image->name);
    969978    }