]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Simplify by using strdup. Check for allocation failure.
authorJoerg Sonnenberger <joerg@bec.de>
Tue, 6 Dec 2016 14:38:09 +0000 (15:38 +0100)
committerJoerg Sonnenberger <joerg@bec.de>
Tue, 6 Dec 2016 14:38:09 +0000 (15:38 +0100)
libarchive/archive_options.c

index dbf3e80e90243fe710593a87f98629844520659d..6496025a5f6bafd6fa0cc62abd165edec2ba8911 100644 (file)
 #include "archive_platform.h"
 __FBSDID("$FreeBSD$");
 
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
 #include "archive_options_private.h"
 
 static const char *
@@ -105,8 +109,11 @@ _archive_set_options(struct archive *a, const char *options,
        if (options == NULL || options[0] == '\0')
                return ARCHIVE_OK;
 
-       data = (char *)malloc(strlen(options) + 1);
-       strcpy(data, options);
+       if ((data = strdup(options)) == NULL) {
+               archive_set_error(a,
+                   ENOMEM, "Out of memory adding file to list");
+               return (ARCHIVE_FATAL);
+       }
        s = (const char *)data;
 
        do {