summaryrefslogtreecommitdiff
path: root/libarchive/archive_options.c
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2016-12-06 15:38:09 +0100
committerJoerg Sonnenberger <joerg@bec.de>2016-12-06 15:38:09 +0100
commitd4d4f91251a084d036518afb8423350c48914bf1 (patch)
tree2d3ac83edb5aebad49093b5259ebd54a578e35db /libarchive/archive_options.c
parent72c12f3f63bde10b27543ee098042ced08addf98 (diff)
downloadlibarchive-d4d4f91251a084d036518afb8423350c48914bf1.tar.gz
Simplify by using strdup. Check for allocation failure.
Diffstat (limited to 'libarchive/archive_options.c')
-rw-r--r--libarchive/archive_options.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libarchive/archive_options.c b/libarchive/archive_options.c
index dbf3e80e..6496025a 100644
--- a/libarchive/archive_options.c
+++ b/libarchive/archive_options.c
@@ -26,6 +26,10 @@
#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 {