summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-01-03 21:08:13 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2005-01-03 21:08:13 +0000
commitcf7f36730fdc206aa69fcc553465d5f30906e367 (patch)
treea3b87aac52e4cc89b97c49f7dc3513d3719e1420
parente283e47d654363ca2df6b6f9e7c4c447b948a30f (diff)
more error checking on buffer operations and plug a descriptor leak
from Joris Vink
-rw-r--r--usr.bin/cvs/logmsg.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/usr.bin/cvs/logmsg.c b/usr.bin/cvs/logmsg.c
index 3dd1febdb62..f9ba6942ccc 100644
--- a/usr.bin/cvs/logmsg.c
+++ b/usr.bin/cvs/logmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: logmsg.c,v 1.10 2004/12/08 21:49:02 jfb Exp $ */
+/* $OpenBSD: logmsg.c,v 1.11 2005/01/03 21:08:12 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -112,8 +112,10 @@ cvs_logmsg_open(const char *path)
}
bp = cvs_buf_alloc(128, BUF_AUTOEXT);
- if (bp == NULL)
+ if (bp == NULL) {
+ (void)fclose(fp);
return (NULL);
+ }
/* lcont is used to tell if a buffer returned by fgets is a start
* of line or just line continuation because the buffer isn't
@@ -130,11 +132,20 @@ cvs_logmsg_open(const char *path)
/* skip lines starting with the prefix */
continue;
- cvs_buf_append(bp, lbuf, strlen(lbuf));
+ if (cvs_buf_append(bp, lbuf, strlen(lbuf)) < 0) {
+ cvs_buf_free(bp);
+ (void)fclose(fp);
+ return (NULL);
+ }
lcont = (lbuf[len - 1] == '\n') ? 0 : 1;
}
- cvs_buf_putc(bp, '\0');
+ (void)fclose(fp);
+
+ if (cvs_buf_putc(bp, '\0') < 0) {
+ cvs_buf_free(bp);
+ return (NULL);
+ }
msg = (char *)cvs_buf_release(bp);