[PATCH xlsatoms] Count % signs, require at least 2 for a format string (#39614)
Peter Hutterer
peter.hutterer at who-t.net
Sun Jul 14 21:07:35 PDT 2013
xlsatoms -format "%s" sounds like a good idea, the resulting crash isn't.
I'm too lazy to check for all possible combinations that we allow here (it
is a printf-compatible string), so let's just check that we have two
specifiers %.
X.Org Bug 39614 <http://bugs.freedesktop.org/show_bug.cgi?id=39614>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
This isn't meant as a security fix, just as a mere sanity fix for a
simple-to-detect case.
xlsatoms.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/xlsatoms.c b/xlsatoms.c
index eb4e21d..f21fadd 100644
--- a/xlsatoms.c
+++ b/xlsatoms.c
@@ -196,6 +196,20 @@ say_batch(xcb_connection_t *c, const char *format, xcb_get_atom_name_cookie_t *c
char atom_name[1024];
long i;
int done = 0;
+ int format_specifiers = 0;
+
+ i = 0;
+
+ while(i < strlen(format) - 1) {
+ if (format[i] == '%' && format[++i] != '%')
+ format_specifiers++;
+ i++;
+ }
+
+ if (format_specifiers != 2) {
+ fprintf(stderr, "Invalid format specifier: '%s'. Need %%d and %%s.\n", format);
+ return 1;
+ }
for (i = 0; i < count; i++)
cookie[i] = xcb_get_atom_name(c, i + low);
--
1.8.2.1
More information about the xorg-devel
mailing list