]> mj.ucw.cz Git - pciutils.git/commitdiff
Perform shell escaping in `-m' mode where necessary.
authorMartin Mares <mj@ucw.cz>
Sat, 9 Sep 2006 12:34:05 +0000 (14:34 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 9 Sep 2006 12:34:05 +0000 (14:34 +0200)
ChangeLog
lspci.c

index bc35fd5c272578f36888db4d6510dd5e3126cc95..75a8a102e39194691929325fa26573bf41d06556 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-09-09  Martin Mares  <mj@ucw.cz>
 
+       * 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 514e717cf15c2f1d81a66d5fd1a85a1a9deaf6a7..c1f9186ddd64252153bf1d0aea2f6d818d1dd09f 100644 (file)
--- 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');