shar: Check strdup return value (#2173)

The strdup function could fail, so check for NULL return value.
This commit is contained in:
Tobias Stoeckmann authored and GitHub committed 2024-05-10 01:49:50 +02:00
1 parent 8bc1a3e66e
commit 576a242050
1 file changed
+8
@@ -209,6 +209,10 @@ archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
if (archive_entry_filetype(entry) != AE_IFDIR) {
/* Try to create the dir. */
p = strdup(name);
if (p == NULL) {
archive_set_error(&a->archive, ENOMEM, "Out of memory");
return (ARCHIVE_FATAL);
}
pp = strrchr(p, '/');
/* If there is a / character, try to create the dir. */
if (pp != NULL) {
@@ -291,6 +295,10 @@ archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
free(shar->last_dir);
shar->last_dir = strdup(name);
if (shar->last_dir == NULL) {
archive_set_error(&a->archive, ENOMEM, "Out of memory");
return (ARCHIVE_FATAL);
}
/* Trim a trailing '/'. */
pp = strrchr(shar->last_dir, '/');
if (pp != NULL && pp[1] == '\0')