]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common,tools: make sure the destination buffer can handle the size of the string
authorsongweibin <song.weibin@zte.com.cn>
Thu, 25 Jul 2019 11:44:08 +0000 (19:44 +0800)
committerNathan Cutler <ncutler@suse.com>
Mon, 27 Jan 2020 14:37:25 +0000 (15:37 +0100)
fix klocwork issues:
Width is not specified for 's' conversion specifier.
This can result in an overflow of the buffer
provided in argument 3 of a call to 'sscanf'

Signed-off-by: songweibin <song.weibin@zte.com.cn>
(cherry picked from commit 5e8c412e63d6a86aa4846efe4cceff52ca8f16d5)

src/common/util.cc
src/tools/cephfs/Dumper.cc

index 3448eb2bfa37bd028ff8ef190d33c63788640018..9678f6076411c3f0b0e86c76f573479280ccd2c8 100644 (file)
@@ -249,7 +249,7 @@ void collect_sys_info(map<string, string> *m, CephContext *cct)
        break;
       char key[40];
       long long value;
-      int r = sscanf(line, "%s %lld", key, &value);
+      int r = sscanf(line, "%39s %lld", key, &value);
       if (r == 2) {
        if (strcmp(key, "MemTotal:") == 0)
          (*m)["mem_total_kb"] = boost::lexical_cast<string>(value);
index 11d32523f416e46b705198681a8af21d2aaab6fb..6b7584978918eeee6445b9a7e6141fbe6bbe65b0 100644 (file)
@@ -243,7 +243,7 @@ int Dumper::undump(const char *dump_file, bool force)
     if (strstr(buf, "fsid")) {
       uuid_d fsid;
       char fsid_str[40];
-      sscanf(strstr(buf, "fsid"), "fsid %s", fsid_str);
+      sscanf(strstr(buf, "fsid"), "fsid %39s", fsid_str);
       r = fsid.parse(fsid_str);
       if (!r) {
        derr  << "Invalid fsid" << dendl;