Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31616

Check return value of std::snprintf for errors

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc3
    • Affects Version/s: None
    • Component/s: Storage
    • Fully Compatible
    • ALL
    • Storage 2017-11-13
    • 0

      There are four cases of using std::snprintf in db/storage that check the return code for some errors (a partial write), but not for the -1 error value. E.g:

          auto size = std::snprintf(oldestTSConfigString,
                                    sizeof(oldestTSConfigString),
                                    "oldest_timestamp=%llx",
                                    static_cast<unsigned long long>(timestampToSet.asU64()));
          invariant(static_cast<std::size_t>(size) < sizeof(oldestTSConfigString));
      

      This work should include checking the return value for -1 and translating the errno.

      Grep:
      https://github.com/mongodb/mongo/blob/0b23e5ab80c96a8c5b001a1a33c5d6099c48ef2b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp#L1045-L1049
      https://github.com/mongodb/mongo/blob/0b23e5ab80c96a8c5b001a1a33c5d6099c48ef2b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp#L1669-L1674
      https://github.com/mongodb/mongo/blob/0b23e5ab80c96a8c5b001a1a33c5d6099c48ef2b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp#L85-L89
      https://github.com/mongodb/mongo/blob/0b23e5ab80c96a8c5b001a1a33c5d6099c48ef2b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp#L112-L116

            Assignee:
            xiangyu.yao@mongodb.com Xiangyu Yao (Inactive)
            Reporter:
            daniel.gottlieb@mongodb.com Daniel Gottlieb (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: