diff options
author | 2001-07-27 17:24:20 +0000 | |
---|---|---|
committer | 2001-07-27 17:24:20 +0000 | |
commit | 5deb6f12f444f54d1de53a34cdd6dfeb18c000b1 (patch) | |
tree | 33d8318cf81c1905720bac2e8f32490af73e1e69 | |
parent | abort if stdout use ever produces EOF. before, top was one of those nasty (diff) | |
download | wireguard-openbsd-5deb6f12f444f54d1de53a34cdd6dfeb18c000b1.tar.xz wireguard-openbsd-5deb6f12f444f54d1de53a34cdd6dfeb18c000b1.zip |
Use snprintf to avoid potential overflows; zen-parse@gmx.net
-rw-r--r-- | gnu/usr.bin/groff/pic/pic.y | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/gnu/usr.bin/groff/pic/pic.y b/gnu/usr.bin/groff/pic/pic.y index 46f1a8d96d5..4d5a35440d3 100644 --- a/gnu/usr.bin/groff/pic/pic.y +++ b/gnu/usr.bin/groff/pic/pic.y @@ -1736,23 +1736,7 @@ char *format_number(const char *form, double n) { if (form == 0) form = "%g"; - else { - // this is a fairly feeble attempt at validation of the format - int nspecs = 0; - for (const char *p = form; *p != '\0'; p++) - if (*p == '%') { - if (p[1] == '%') - p++; - else - nspecs++; - } - if (nspecs > 1) { - lex_error("bad format `%1'", form); - return strsave(form); - } - } - sprintf(sprintf_buf, form, n); - return strsave(sprintf_buf); + return do_sprintf(form, &n, 1); } char *do_sprintf(const char *form, const double *v, int nv) @@ -1774,7 +1758,7 @@ char *do_sprintf(const char *form, const double *v, int nv) if (*form == '%') { one_format += *form++; one_format += '\0'; - sprintf(sprintf_buf, one_format.contents()); + snprintf(sprintf_buf, sizeof(sprintf_buf), one_format.contents()); } else { if (i >= nv) { @@ -1785,7 +1769,7 @@ char *do_sprintf(const char *form, const double *v, int nv) } one_format += *form++; one_format += '\0'; - sprintf(sprintf_buf, one_format.contents(), v[i++]); + snprintf(sprintf_buf, sizeof(sprintf_buf), one_format.contents(), v[i++]); } one_format.clear(); result += sprintf_buf; |