]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common,tools: make sure the destination buffer can handle the size of the string 29316/head
authorsongweibin <song.weibin@zte.com.cn>
Thu, 25 Jul 2019 11:44:08 +0000 (19:44 +0800)
committersongweibin <song.weibin@zte.com.cn>
Fri, 26 Jul 2019 06:27:02 +0000 (14:27 +0800)
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>
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;