projects
/
suckless
/
slstatus.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
1d25799
)
worked around the buffer overrun in smprintf()
author
Ali H. Fardan
<raiz@firemail.cc>
Sun, 28 Aug 2016 15:19:53 +0000
(18:19 +0300)
committer
Ali H. Fardan
<raiz@firemail.cc>
Sun, 28 Aug 2016 15:19:53 +0000
(18:19 +0300)
slstatus.c
patch
|
blob
|
history
diff --git
a/slstatus.c
b/slstatus.c
index 628c0f414569ccdbcd581211ff092a40c9eafed7..08866d2c823ea0f71218aa2839f108220da7072e 100644
(file)
--- a/
slstatus.c
+++ b/
slstatus.c
@@
-78,14
+78,15
@@
setstatus(const char *str)
static char *
smprintf(const char *fmt, ...)
{
- /* FIXME: This code should have
- bound checks, it is vulnerable to
- buffer overflows */
va_list ap;
+ char tmp[120];
char *ret = NULL;
va_start(ap, fmt);
- if (vasprintf(&ret, fmt, ap) < 0)
+ vsnprintf(tmp, sizeof(tmp)-1, fmt, ap);
+ tmp[strlen(tmp)+1] = '\0';
+
+ if (asprintf(&ret, "%s", tmp) < 0)
return NULL;
va_end(ap);