buf in effect is the serial number in ceph.conf and
the serial number consists of 16 hexadecimal characters.
1. In order to avoid ignoring the numbers, scan buf
with isxdigit.
2. In order to ignore all the potential garbage,
scan buf from the beginning.
Signed-off-by: Hongtong Liu <hongtong.liu@istuary.com>
derr << __func__ << " unable to read " << p << ": " << cpp_strerror(r) << dendl;
return r;
}
- while (r > 0 && !isalpha(buf[r-1])) {
- --r;
+ /* scan buf from the beginning with isxdigit. */
+ int i = 0;
+ while (i < r && isxdigit(buf[i])) {
+ i++;
}
- serial_number = string(buf, r);
+ serial_number = string(buf, i);
r = manager.try_get(serial_number, &driver);
if (r < 0) {
derr << __func__ << " failed to get nvme device with sn " << serial_number << dendl;