From: songweibin Date: Thu, 25 Jul 2019 11:44:08 +0000 (+0800) Subject: common,tools: make sure the destination buffer can handle the size of the string X-Git-Tag: v15.1.0~2056^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F29316%2Fhead;p=ceph.git common,tools: make sure the destination buffer can handle the size of the string 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 --- diff --git a/src/common/util.cc b/src/common/util.cc index 3448eb2bfa37..9678f6076411 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -249,7 +249,7 @@ void collect_sys_info(map *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(value); diff --git a/src/tools/cephfs/Dumper.cc b/src/tools/cephfs/Dumper.cc index 11d32523f416..6b7584978918 100644 --- a/src/tools/cephfs/Dumper.cc +++ b/src/tools/cephfs/Dumper.cc @@ -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;