resolvd: fix leaks of line and fp
authortb <tb@openbsd.org>
Fri, 9 Dec 2022 18:22:35 +0000 (18:22 +0000)
committertb <tb@openbsd.org>
Fri, 9 Dec 2022 18:22:35 +0000 (18:22 +0000)
In case asprintf() fails or the iov overflows, the file and the line read
would be leaked.

also noted by otto
ok deraadt millert

sbin/resolvd/resolvd.c

index ff93c31..2ffdfc6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: resolvd.c,v 1.31 2022/12/09 18:11:24 otto Exp $       */
+/*     $OpenBSD: resolvd.c,v 1.32 2022/12/09 18:22:35 tb Exp $ */
 /*
  * Copyright (c) 2021 Florian Obser <florian@openbsd.org>
  * Copyright (c) 2021 Theo de Raadt <deraadt@openbsd.org>
@@ -654,11 +654,15 @@ regen_resolvconf(const char *why)
                            line);
                        if (len < 0) {
                                lwarn("asprintf");
+                               free(line);
+                               fclose(fp);
                                goto err;
                        }
                        iov[iovcnt++].iov_len = len;
                        if (iovcnt >= UIO_MAXIOV) {
                                lwarnx("too many user-managed lines");
+                               free(line);
+                               fclose(fp);
                                goto err;
                        }
                }