diff options
author | Karel Zak | 2013-11-07 14:07:17 +0100 |
---|---|---|
committer | Karel Zak | 2013-11-07 14:10:26 +0100 |
commit | 1c9885cde853a458b5abe5ce0804abc27caf4fd4 (patch) | |
tree | 7a7f60ad47dfb4aa881093f31d57a0ba3c7def9d /misc-utils/blkid.c | |
parent | tests: add sparc64 lscpu test (diff) | |
download | kernel-qcow2-util-linux-1c9885cde853a458b5abe5ce0804abc27caf4fd4.tar.gz kernel-qcow2-util-linux-1c9885cde853a458b5abe5ce0804abc27caf4fd4.tar.xz kernel-qcow2-util-linux-1c9885cde853a458b5abe5ce0804abc27caf4fd4.zip |
blkid: escape quotes in the output
# 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>
Diffstat (limited to 'misc-utils/blkid.c')
-rw-r--r-- | misc-utils/blkid.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index b032c852a..2aba0de98 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -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); } } |