]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkid: escape quotes in the output
authorKarel Zak <kzak@redhat.com>
Thu, 7 Nov 2013 13:07:17 +0000 (14:07 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 7 Nov 2013 13:10:26 +0000 (14:10 +0100)
 # e2label /dev/loop0 'La"bel'
 # blkid -p /dev/loop0
 /dev/loop0: LABEL="La"bel"  ....

new version:

 /dev/loop0: LABEL="La\"bel" ....

Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/blkid.c

index b032c852a4f1b432bcd567408b885f027dfe7147..2aba0de98ffc455e0f17b2a45efbbcdcb81a77fe 100644 (file)
@@ -104,8 +104,10 @@ static void usage(int error)
 /*
  * This function does "safe" printing.  It will convert non-printable
  * ASCII characters using '^' and M- notation.
+ *
+ * If 'esc' is defined then escape all chars from esc by \.
  */
-static void safe_print(const char *cp, int len)
+static void safe_print(const char *cp, int len, const char *esc)
 {
        unsigned char   ch;
 
@@ -122,7 +124,9 @@ static void safe_print(const char *cp, int len)
                        if ((ch < 32) || (ch == 0x7f)) {
                                fputc('^', stdout);
                                ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
-                       }
+
+                       } else if (esc && strchr(esc, ch))
+                               fputc('\\', stdout);
                }
                fputc(ch, stdout);
        }
@@ -302,7 +306,7 @@ static void print_value(int output, int num, const char *devname,
                        printf("DEVNAME=%s\n", devname);
                fputs(name, stdout);
                fputs("=", stdout);
-               safe_print(value, valsz);
+               safe_print(value, valsz, NULL);
                fputs("\n", stdout);
 
        } else {
@@ -310,7 +314,7 @@ static void print_value(int output, int num, const char *devname,
                        printf("%s: ", devname);
                fputs(name, stdout);
                fputs("=\"", stdout);
-               safe_print(value, valsz);
+               safe_print(value, valsz, "\"");
                fputs("\" ", stdout);
        }
 }