[hackers] [sbase] Check return value of snprintf in mktemp(1) || sin

From: <git_AT_suckless.org>
Date: Fri, 24 Jan 2014 17:19:53 +0100

commit 30620afb6c6c75e14ebd9de876114f88a83f0355
Author: sin <sin_AT_2f30.org>
Date: Fri Jan 24 16:17:39 2014 +0000

    Check return value of snprintf in mktemp(1)

diff --git a/mktemp.c b/mktemp.c
index 8416a01..4988e58 100644
--- a/mktemp.c
+++ b/mktemp.c
_AT_@ -42,7 +42,8 @@ main(int argc, char *argv[])
         if ((p = getenv("TMPDIR")))
                 tmpdir = p;
 
- snprintf(tmppath, sizeof(tmppath), "%s/%s", tmpdir, template);
+ if (snprintf(tmppath, sizeof(tmppath), "%s/%s", tmpdir, template) >= sizeof(tmppath))
+ eprintf(EXIT_FAILURE, "path too long
");
         if (dflag) {
                 if (!mkdtemp(tmppath)) {
                         if (!qflag)
Received on Fri Jan 24 2014 - 17:19:53 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 24 2014 - 17:24:10 CET