]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Release option memory if there is a problem allocating a large
authorRoy Marples <roy@marples.name>
Thu, 21 Jul 2016 08:45:00 +0000 (08:45 +0000)
committerRoy Marples <roy@marples.name>
Thu, 21 Jul 2016 08:45:00 +0000 (08:45 +0000)
enough buffer to read the file.
Thanks to Koichi Okamoto for the initial patch.

if-options.c

index 3334d413bddac0014f14b5200d2ea8746500f330..289b3badab2da06768683b4f9767e38139660cd6 100644 (file)
@@ -2340,19 +2340,25 @@ read_config(struct dhcpcd_ctx *ctx,
                buf = malloc(buflen);
                if (buf == NULL) {
                        logger(ctx, LOG_ERR, "%s: %m", __func__);
+                       free_options(ifo);
                        return NULL;
                }
                ldop = edop = NULL;
                for (e = dhcpcd_embedded_conf; *e; e++) {
                        ol = strlen(*e) + 1;
                        if (ol > buflen) {
+                               char *nbuf;
+
                                buflen = ol;
-                               buf = realloc(buf, buflen);
-                               if (buf == NULL) {
-                                       logger(ctx, LOG_ERR, "%s: %m", __func__);
+                               nbuf = realloc(buf, buflen);
+                               if (nbuf == NULL) {
+                                       logger(ctx, LOG_ERR,
+                                           "%s: %m", __func__);
                                        free(buf);
+                                       free_options(ifo);
                                        return NULL;
                                }
+                               buf = nbuf;
                        }
                        memcpy(buf, *e, ol);
                        line = buf;