|
|
68f74b |
From 1fce38a3b2dc10c5bdd2c9f97c08c66dce7f0a95 Mon Sep 17 00:00:00 2001
|
|
|
68f74b |
From: "G. Branden Robinson" <g.branden.robinson@gmail.com>
|
|
|
68f74b |
Date: Tue, 1 Dec 2020 16:37:16 +1100
|
|
|
68f74b |
Subject: [PATCH 6/7] [xtotroff]: Avoid overrunning buffer write.
|
|
|
68f74b |
|
|
|
68f74b |
* src/utils/xtotroff/xtotroff.c (MapFont): Avoid writing past
|
|
|
68f74b |
the end of a static buffer. Problem found and patch supplied by
|
|
|
68f74b |
Bjarni Ingi Gislason. I tweaked it to comment it differently (in case
|
|
|
68f74b |
the buffer ever needs to grow, but the prospects of future X11
|
|
|
68f74b |
server-side font rendering development seem dim) and use snprintf()
|
|
|
68f74b |
instead of retaining the existing sprintf().
|
|
|
68f74b |
|
|
|
68f74b |
Quiets warning: '%s' directive writing up to 255 bytes into a region
|
|
|
68f74b |
of size between 0 and 255 [-Wformat-overflow=].
|
|
|
68f74b |
---
|
|
|
68f74b |
src/utils/xtotroff/xtotroff.c | 7 +++++--
|
|
|
68f74b |
1 file changed, 5 insertions(+), 2 deletions(-)
|
|
|
68f74b |
|
|
|
68f74b |
diff --git a/src/utils/xtotroff/xtotroff.c b/src/utils/xtotroff/xtotroff.c
|
|
|
68f74b |
index 8545a5e..aee2a1a 100644
|
|
|
68f74b |
--- a/src/utils/xtotroff/xtotroff.c
|
|
|
68f74b |
+++ b/src/utils/xtotroff/xtotroff.c
|
|
|
68f74b |
@@ -127,7 +127,9 @@ static int MapFont(char *font_name, const char *troff_name)
|
|
|
68f74b |
XFontName parsed;
|
|
|
68f74b |
int j, k;
|
|
|
68f74b |
DviCharNameMap *char_map;
|
|
|
68f74b |
- char encoding[256];
|
|
|
68f74b |
+ /* 'encoding' needs to hold a CharSetRegistry (256), a CharSetEncoding
|
|
|
68f74b |
+ (256) [both from XFontName.h], a dash, and a null terminator. */
|
|
|
68f74b |
+ char encoding[256 * 2 + 1 + 1];
|
|
|
68f74b |
char *s;
|
|
|
68f74b |
int wid;
|
|
|
68f74b |
char name_string[2048];
|
|
|
68f74b |
@@ -156,7 +158,8 @@ static int MapFont(char *font_name, const char *troff_name)
|
|
|
68f74b |
return 0;
|
|
|
68f74b |
|
|
|
68f74b |
XParseFontName(names[0], &parsed, &attributes);
|
|
|
68f74b |
- sprintf(encoding, "%s-%s", parsed.CharSetRegistry,
|
|
|
68f74b |
+ size_t sz = sizeof encoding;
|
|
|
68f74b |
+ snprintf(encoding, sz, "%s-%s", parsed.CharSetRegistry,
|
|
|
68f74b |
parsed.CharSetEncoding);
|
|
|
68f74b |
for (s = encoding; *s; s++)
|
|
|
68f74b |
if (isupper(*s))
|
|
|
68f74b |
--
|
|
|
68f74b |
2.32.0
|
|
|
68f74b |
|