]> git.apps.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:38:37 +0000 (15:38 +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 4631bf092f6a67f1b3e2a3fa7e3987c8408c70b8..9cea0d78fd180da59b4da50139ca23ab43d3a187 100644 (file)
@@ -194,7 +194,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 98ab43537eaa40b103a8317faea571e445893e68..0f4e78fbf90a991b92b10208a1fda207dea93c68 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;