From: Karel Zak Date: Thu, 7 Nov 2013 13:07:17 +0000 (+0100) Subject: blkid: escape quotes in the output X-Git-Tag: v2.25-rc1~775 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c9885cde853a458b5abe5ce0804abc27caf4fd4;p=thirdparty%2Futil-linux.git 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 Signed-off-by: Karel Zak --- diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index b032c852a4..2aba0de98f 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); } }