1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

device_id: ignore quotes in device id

A t10 wwid string was found containing a " character
which breaks vg metadata parsing.  Ignore any quotation
marks in device id strings.
This commit is contained in:
David Teigland 2023-02-06 12:18:55 -06:00
parent 57ad78d436
commit dc99f0def1
3 changed files with 34 additions and 2 deletions

View File

@ -438,8 +438,8 @@ int dev_read_sys_wwid(struct cmd_context *cmd, struct device *dev,
if (!ret || !buf[0])
return 0;
/* in t10 id, replace series of spaces with one _ */
if (!strncmp(buf, "t10.", 4) && strchr(buf, ' ')) {
/* in t10 id, replace characters like space and quote */
if (!strncmp(buf, "t10.", 4)) {
if (bufsize < DEV_WWID_SIZE)
return 0;
memcpy(tmpbuf, buf, DEV_WWID_SIZE);
@ -587,6 +587,8 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
/* wwids are already munged if needed */
if (idtype != DEV_ID_TYPE_SYS_WWID) {
for (i = 0; i < strlen(sysbuf); i++) {
if (sysbuf[i] == '"')
continue;
if (isblank(sysbuf[i]) || isspace(sysbuf[i]) || iscntrl(sysbuf[i]))
sysbuf[i] = '_';
}

View File

@ -53,6 +53,12 @@ int format_t10_id(const unsigned char *in, int in_bytes, unsigned char *out, int
/* skip leading spaces */
if (!retlen && (in[i] == ' '))
continue;
/* skip non-ascii non-printable characters */
if (!isascii(in[i]) || !isprint(in[i]))
continue;
/* skip quote */
if (in[i] == '"')
continue;
/* replace one or more spaces with _ */
if (in[i] == ' ') {
in_space = 1;

View File

@ -219,6 +219,30 @@ vgremove $vg
rm $SYS_DIR/dev/block/$MAJOR1:$MINOR1/wwid
cleanup_sysfs
# Test t10 wwid containing quote
rm $DF
aux wipefs_a "$DEV1"
mkdir -p $SYS_DIR/dev/block/$MAJOR1:$MINOR1/
echo "t10.ATA_2.5\"_SATA_SSD_1112-A___111111111111" > $SYS_DIR/dev/block/$MAJOR1:$MINOR1/wwid
lvmdevices --adddev "$DEV1"
cat $DF
vgcreate $vg "$DEV1"
lvcreate -l1 -an $vg
cat $DF
# check wwid string in metadata output
pvs -o+deviceidtype,deviceid "$DEV1" |tee out
grep sys_wwid out
# the quote is removed after the 5
grep 2.5_SATA_SSD out
# check wwid string in system.devices
grep sys_wwid $DF
# the quote is removed after the 5
grep 2.5_SATA_SSD $DF
lvremove -y $vg
vgremove $vg
rm $SYS_DIR/dev/block/$MAJOR1:$MINOR1/wwid
cleanup_sysfs
# TODO: lvmdevices --adddev <dev> --deviceidtype <type> --deviceid <val>
# This would let the user specify the second naa wwid.