diff options
author | 2005-01-03 21:08:12 +0000 | |
---|---|---|
committer | 2005-01-03 21:08:12 +0000 | |
commit | 5424eb346bada6689700143cb1c356f29a41abdf (patch) | |
tree | d01ea3a33cc242ea1732cb9cb8a58a64992a8b0c /usr.bin/cvs/logmsg.c | |
parent | ok, ami is a good choice for the floppy (diff) | |
download | wireguard-openbsd-5424eb346bada6689700143cb1c356f29a41abdf.tar.xz wireguard-openbsd-5424eb346bada6689700143cb1c356f29a41abdf.zip |
more error checking on buffer operations and plug a descriptor leak
from Joris Vink
Diffstat (limited to 'usr.bin/cvs/logmsg.c')
-rw-r--r-- | usr.bin/cvs/logmsg.c | 19 |
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); |