[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix formatting a trailing backslash and a percent sign
From: |
Petr Písař |
Subject: |
[PATCH] Fix formatting a trailing backslash and a percent sign |
Date: |
Fri, 26 Jan 2024 11:52:22 +0100 |
There was a bug report that a trailing backslash leads to printing
a nul byte and an commandline:
$ /usr/bin/time -f 'abc\' sleep 1 2>&1 | hexdump -vC
00000000 61 62 63 3f 5c 00 73 6c 65 65 70 0a |abc?\.sleep.|
0000000c
This patch fixes it.
A similar fix was already in place for a trailing percent sign, but it
was missing printing an implicit newline as mandated by
the documentation. This patch fixes it either.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
src/time.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/time.c b/src/time.c
index 7b401bc..0d35f82 100644
--- a/src/time.c
+++ b/src/time.c
@@ -658,14 +658,15 @@ summarize (fp, fmt, command, resp)
case '\0':
putc ('?', fp);
- return;
+ break;
default:
putc ('?', fp);
putc (*fmt, fp);
}
- ++fmt;
+ if (*fmt != '\0')
+ ++fmt;
break; /* end of "case '%'" */
case '\\': /* Format escape. */
@@ -680,12 +681,17 @@ summarize (fp, fmt, command, resp)
case '\\':
putc ('\\', fp);
break;
+ case '\0':
+ putc ('?', fp);
+ putc ('\\', fp);
+ break;
default:
putc ('?', fp);
putc ('\\', fp);
putc (*fmt, fp);
}
- ++fmt;
+ if (*fmt != '\0')
+ ++fmt;
break;
default:
--
2.43.0