summaryrefslogtreecommitdiffstats
path: root/usr.bin/cvs/edit.c
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2008-06-11 02:19:13 +0000
committertobias <tobias@openbsd.org>2008-06-11 02:19:13 +0000
commit6534056ad73d313d3cef79113987d6336ec93f06 (patch)
tree86d51b9bff425a9e76e7922625f7153b7a7c04bd /usr.bin/cvs/edit.c
parentspacing (diff)
downloadwireguard-openbsd-6534056ad73d313d3cef79113987d6336ec93f06.tar.xz
wireguard-openbsd-6534056ad73d313d3cef79113987d6336ec93f06.zip
Avoid possible NULL pointer dereferences by using reentrant versions
of time functions. ok joris
Diffstat (limited to 'usr.bin/cvs/edit.c')
-rw-r--r--usr.bin/cvs/edit.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/usr.bin/cvs/edit.c b/usr.bin/cvs/edit.c
index c8faef21e6d..cc7944a299d 100644
--- a/usr.bin/cvs/edit.c
+++ b/usr.bin/cvs/edit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: edit.c,v 1.45 2008/03/01 21:29:36 deraadt Exp $ */
+/* $OpenBSD: edit.c,v 1.46 2008/06/11 02:19:13 tobias Exp $ */
/*
* Copyright (c) 2006, 2007 Xavier Santolaria <xsa@openbsd.org>
*
@@ -19,6 +19,7 @@
#include <errno.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "cvs.h"
@@ -257,7 +258,7 @@ static void
cvs_edit_local(struct cvs_file *cf)
{
FILE *fp;
- struct tm *t;
+ struct tm t;
time_t now;
char timebuf[CVS_TIME_BUFSZ], thishost[MAXHOSTNAMELEN];
char bfpath[MAXPATHLEN], wdir[MAXPATHLEN];
@@ -274,10 +275,8 @@ cvs_edit_local(struct cvs_file *cf)
CVS_PATH_NOTIFY, strerror(errno));
(void)time(&now);
- if ((t = gmtime(&now)) == NULL)
- fatal("gmtime failed");
-
- asctime_r(t, timebuf);
+ gmtime_r(&now, &t);
+ asctime_r(&t, timebuf);
timebuf[strcspn(timebuf, "\n")] = '\0';
if (gethostname(thishost, sizeof(thishost)) == -1)
@@ -326,7 +325,7 @@ cvs_unedit_local(struct cvs_file *cf)
{
FILE *fp;
struct stat st;
- struct tm *t;
+ struct tm t;
time_t now;
char bfpath[MAXPATHLEN], timebuf[64], thishost[MAXHOSTNAMELEN];
char wdir[MAXPATHLEN], sticky[CVS_ENT_MAXLINELEN];
@@ -360,10 +359,8 @@ cvs_unedit_local(struct cvs_file *cf)
CVS_PATH_NOTIFY, strerror(errno));
(void)time(&now);
- if ((t = gmtime(&now)) == NULL)
- fatal("gmtime failed");
-
- asctime_r(t, timebuf);
+ gmtime_r(&now, &t);
+ asctime_r(&t, timebuf);
timebuf[strcspn(timebuf, "\n")] = '\0';
if (gethostname(thishost, sizeof(thishost)) == -1)