Uploaded image for project: 'Lustre'
  1. Lustre
  2. LU-21050

fix length check in cfs_abs_path()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • None
    • None
    • 3
    • 9223372036854775807

      When cfs_abs_path() appends the file name to the resolved parent
      directory, it stores the snprintf() result in "len", which already
      holds the length of the parent. The overflow check that follows,
      "len >= sizeof(buf) - len", then compares the appended length against
      the wrong remaining space. Truncation is only detected when the file
      name alone is longer than about half of the buffer, so a long parent
      path combined with a long file name can be silently truncated.

      Keep the snprintf() result in a separate variable and compare it
      against the space left after the parent, sizeof(buf) - len. Also treat
      a negative return as an error, and cast the result to size_t for the
      comparison so that it is never converted from a negative value.

      This is unlikely to be hit in practice because it needs a path close to
      PATH_MAX, but a truncated path should be reported as -ENAMETOOLONG
      instead of being returned to the caller.

            manhongdai Manhong Dai
            manhongdai Manhong Dai
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: