Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-11317

Coverity analysis defect 138263: Argument cannot be negative

    • 1
    • 2023-07-25 Absolute unit

      The error flagged by Coverity (below) appears to be a false positive as the condition will be handled by testutil_check(ret); but the related code needs to be re-evaluated.

      The issue is around the use of WT_SYSCALL_RETRY with pread, which fails to distinguish between EOF and a failure to read any bytes (no matter how unlikely). The only other similar usage of WT_SYSCALL_RETRY in src/posix/os_posix/os_fs.c tracks the number of bytes remaining in the file and uses that as context information, though the comment "pread returns > 0 when successful" is incorrect.

          for (offset = 0, n = 0;; offset += n) {
              WT_SYSCALL_RETRY((n = pread(rfd, buf, COPY_BUF_SIZE, offset)) < 0 ? -1 : 0, ret);
              testutil_check(ret);
              if (n == 0)
                  break;
              testutil_assert_errno(write(wfd, buf, (size_t)n) == n);
          }
      
      Argument cannot be negative
      
       The negative argument will be interpreted as a very large unsigned value. Negative value used as argument to a function expecting a positive value (for example, size of buffer or allocation)
      /test/utility/file.c:300: NEGATIVE_RETURNS 138263 Function "pread(rfd, buf, 262144UL, offset)" returns a negative number.
      /test/utility/file.c:300: NEGATIVE_RETURNS 138263 Assigning: "n" = "pread(rfd, buf, 262144UL, offset)".
      /test/utility/file.c:304: NEGATIVE_RETURNS 138263 "(size_t)n" is passed to a parameter that cannot be negative.
      

            Assignee:
            mick.graham@mongodb.com Mick Graham
            Reporter:
            xgen-internal-coverity Coverity Collector User
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: