Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8205201

Problematic strncpy usage causes compiler warning on Fedora 28

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 11
    • hotspot

      /home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp: In static member function ‘static int os::create_file_for_heap(const char*)’:
      /home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp:172:16: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
         (void)strncpy(fullname, dir, strlen(dir)+1);
               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp:172:38: note: length computed here
         (void)strncpy(fullname, dir, strlen(dir)+1);
                                      ~~~~~~^~~~~
      /home/pr/sources/jdk/src/hotspot/os/posix/os_posix.cpp:173:16: error: ‘char* strncat(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
         (void)strncat(fullname, name_template, strlen(name_template));
               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      cc1plus: all warnings being treated as errors

      It seems the limit is expected/required to be based on the size of the destination buffer rather than the source buffer. Which superficially seems reasonable, but it depends on whether you have sized your destination buffer based on the source size already. So these warnings could be false positives and we may need to make this a build issue and disable the warnings.

            Unassigned Unassigned
            dholmes David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: