Hi,

I think there is a file descriotor leak in the syslogd(8) ttymsg()
error path.  When we return early with an error, we must close the
newly opened file descriptor first.

ok?

bluhm

Index: usr.sbin/syslogd/ttymsg.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/ttymsg.c,v
retrieving revision 1.11
diff -u -p -r1.11 ttymsg.c
--- usr.sbin/syslogd/ttymsg.c   16 Aug 2016 18:41:57 -0000      1.11
+++ usr.sbin/syslogd/ttymsg.c   15 Mar 2017 02:01:34 -0000
@@ -137,7 +137,7 @@ ttymsg(struct iovec *iov, int iovcnt, ch
                        if (tty_delayed >= TTYMAXDELAY) {
                                (void) snprintf(ebuf, sizeof(ebuf),
                                    "%s: too many delayed writes", device);
-                               return (ebuf);
+                               goto error;
                        }
                        logdebug("ttymsg delayed write\n");
                        if (iov != localiov) {
@@ -148,7 +148,7 @@ ttymsg(struct iovec *iov, int iovcnt, ch
                        if ((td = malloc(sizeof(*td))) == NULL) {
                                (void) snprintf(ebuf, sizeof(ebuf),
                                    "%s: malloc: %s", device, strerror(errno));
-                               return (ebuf);
+                               goto error;
                        }
                        td->td_length = 0;
                        if (left > MAXLINE)
@@ -176,9 +176,10 @@ ttymsg(struct iovec *iov, int iovcnt, ch
                 */
                if (errno == ENODEV || errno == EIO)
                        break;
-               (void) close(fd);
                (void) snprintf(ebuf, sizeof(ebuf),
                    "%s: %s", device, strerror(errno));
+ error:
+               (void) close(fd);
                return (ebuf);
        }
 

Reply via email to