summaryrefslogtreecommitdiff
path: root/6/main.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-14 23:15:44 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-14 23:15:44 -0400
commit6d98d1414c11322eb919530405aebce01ee51c6f (patch)
tree28e5de0375481a5f0cf71f473a251e2c5593b0ed /6/main.c
parentf6e3939a23bcb8bfc53baf6bb3231ea5afbd44d9 (diff)
downloadmc-6d98d1414c11322eb919530405aebce01ee51c6f.tar.gz
Add checking for buffer overruns.
Diffstat (limited to '6/main.c')
-rw-r--r--6/main.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/6/main.c b/6/main.c
index 408507a..c198a56 100644
--- a/6/main.c
+++ b/6/main.c
@@ -6,6 +6,7 @@
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <err.h>
@@ -56,6 +57,7 @@ static char *gentemp(char *buf, size_t bufsz, char *path, char *suffix)
{
char *tmpdir;
char *base;
+ struct timeval tv;
tmpdir = getenv("TMPDIR");
if (!tmpdir)
@@ -65,7 +67,9 @@ static char *gentemp(char *buf, size_t bufsz, char *path, char *suffix)
base++;
else
base = path;
- snprintf(buf, bufsz, "%s/tmp%lx-%s%s", tmpdir, random(), base, suffix);
+ gettimeofday(&tv, NULL);
+ srandom(tv.tv_usec);
+ snprintf(buf, bufsz, "%s/tmp%lx%lx-%s%s", tmpdir, random(), (long)tv.tv_usec, base, suffix);
return buf;
}
@@ -88,7 +92,6 @@ int main(int argc, char **argv)
int i;
Stab *globls;
char buf[1024];
-
while ((opt = getopt(argc, argv, "d:hSo:I:")) != -1) {
switch (opt) {
case 'o':