From: Ilya Dryomov Date: Fri, 13 Dec 2013 15:40:52 +0000 (+0200) Subject: rbd: switch to strict_strtol for major parsing X-Git-Tag: v0.75~113^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a42130592d4f3aebc6b1080a12c942b650fc5349;p=ceph.git rbd: switch to strict_strtol for major parsing Use common/strict_strtol, which actually parses integers in a proper way, instead of atoi for parsing /sys/bus/rbd/devices//major. This is important, because the kernel apparently can write things like "(none)" into that file, and in general is more bulletproof. Signed-off-by: Ilya Dryomov --- diff --git a/src/rbd.cc b/src/rbd.cc index 9556fb842ea..a5806b9b4c6 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -1895,8 +1895,15 @@ static int get_rbd_seq(int major_num, string &seq) << cpp_strerror(-r) << std::endl; continue; } + string err; + int cur_major = strict_strtol(major, 10, &err); + if (!err.empty()) { + cerr << err << std::endl; + cerr << "rbd: could not parse major number read from " << fn << ": " + << cpp_strerror(-r) << std::endl; + continue; + } - int cur_major = atoi(major); if (cur_major == major_num) { seq = string(dent->d_name); closedir(device_dir);