From 13081e57866100c504b399c2b0862b50726addfe Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 9 Sep 2006 14:34:05 +0200 Subject: [PATCH] Perform shell escaping in `-m' mode where necessary. --- ChangeLog | 3 +++ lspci.c | 30 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc35fd5..75a8a10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-09-09 Martin Mares + * lspci.c (show_machine): In the `-m' mode, do proper shell escaping + if the fields printed contain quotes or backslashes. + * lspci.c (show_machine): Added a `-vmm' mode, which removes the misuse of the `Device' tag for two different purposes. diff --git a/lspci.c b/lspci.c index 514e717..c1f9186 100644 --- a/lspci.c +++ b/lspci.c @@ -1801,6 +1801,19 @@ show_hex_dump(struct device *d) } } +static void +print_shell_escaped(char *c) +{ + printf(" \""); + while (*c) + { + if (*c == '"' || *c == '\\') + putchar('\\'); + putchar(*c++); + } + putchar('"'); +} + static void show_machine(struct device *d) { @@ -1850,21 +1863,18 @@ show_machine(struct device *d) else { show_slot_name(d); - printf(" \"%s\" \"%s\" \"%s\"", - pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, - p->device_class), - pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, - p->vendor_id, p->device_id), - pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, - p->vendor_id, p->device_id)); + print_shell_escaped(pci_lookup_name(pacc, classbuf, sizeof(classbuf), PCI_LOOKUP_CLASS, p->device_class)); + print_shell_escaped(pci_lookup_name(pacc, vendbuf, sizeof(vendbuf), PCI_LOOKUP_VENDOR, p->vendor_id, p->device_id)); + print_shell_escaped(pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id)); if (c = get_conf_byte(d, PCI_REVISION_ID)) printf(" -r%02x", c); if (c = get_conf_byte(d, PCI_CLASS_PROG)) printf(" -p%02x", c); if (sv_id && sv_id != 0xffff) - printf(" \"%s\" \"%s\"", - pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id), - pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id)); + { + print_shell_escaped(pci_lookup_name(pacc, svbuf, sizeof(svbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR, sv_id)); + print_shell_escaped(pci_lookup_name(pacc, sdbuf, sizeof(sdbuf), PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id, sv_id, sd_id)); + } else printf(" \"\" \"\""); putchar('\n'); -- 2.39.2