Compare commits

...

2 Commits

Author SHA1 Message Date
d9b0dce41a
Remove minitar_panic() wrapper around minitar_handle_panic() 2023-01-12 19:01:55 +01:00
e568e88617
Remove assertion that was not used
minitar_static_dup() is always called with sizes MUCH smaller than 1024.
2023-01-12 19:00:12 +01:00

View File

@ -1,6 +1,5 @@
#include "minitar.h" #include "minitar.h"
#include "tar.h" #include "tar.h"
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -28,11 +27,6 @@ WEAK noreturn void minitar_handle_panic(const char* message)
abort(); abort();
} }
noreturn void minitar_panic(const char* message)
{
minitar_handle_panic(message);
}
// Safer BSD-style replacement for strcpy/strncpy. Copies at most size-1 bytes from src into dest, always // Safer BSD-style replacement for strcpy/strncpy. Copies at most size-1 bytes from src into dest, always
// null-terminating the result. Returns the full length of src, to make it easy to check for overflows. Non-standard, so // null-terminating the result. Returns the full length of src, to make it easy to check for overflows. Non-standard, so
// we provide our own implementation. // we provide our own implementation.
@ -124,7 +118,6 @@ static size_t minitar_align_down_to_block_size(size_t size)
static char* minitar_static_dup(const char* str, size_t size) static char* minitar_static_dup(const char* str, size_t size)
{ {
static char result[1024]; static char result[1024];
assert(size < 1024);
memcpy(result, str, size); memcpy(result, str, size);
result[size] = 0; result[size] = 0;
return result; return result;
@ -183,13 +176,13 @@ void minitar_parse_metadata_from_tar_header(const struct tar_header* hdr, struct
{ {
case '\0': case '\0':
case '0': metadata->type = MTAR_REGULAR; break; case '0': metadata->type = MTAR_REGULAR; break;
case '1': minitar_panic("Links to other files within a tar archive are unsupported"); case '1': minitar_handle_panic("Links to other files within a tar archive are unsupported");
case '2': minitar_panic("Symbolic links are unsupported"); case '2': minitar_handle_panic("Symbolic links are unsupported");
case '3': minitar_panic("Character devices are unsupported"); case '3': minitar_handle_panic("Character devices are unsupported");
case '4': minitar_panic("Block devices are unsupported"); case '4': minitar_handle_panic("Block devices are unsupported");
case '5': metadata->type = MTAR_DIRECTORY; break; case '5': metadata->type = MTAR_DIRECTORY; break;
case '6': minitar_panic("FIFOs are unsupported"); case '6': minitar_handle_panic("FIFOs are unsupported");
default: minitar_panic("Unknown entry type in tar header"); default: minitar_handle_panic("Unknown entry type in tar header");
} }
minitar_strlcpy(metadata->uname, hdr->uname, 32); minitar_strlcpy(metadata->uname, hdr->uname, 32);
@ -240,7 +233,7 @@ int minitar_read_header(struct minitar* mp, struct tar_header* hdr)
{ {
size_t rc = fread(hdr, 1, sizeof *hdr, mp->stream); size_t rc = fread(hdr, 1, sizeof *hdr, mp->stream);
if (rc == 0 && feof(mp->stream)) return 0; if (rc == 0 && feof(mp->stream)) return 0;
if (rc == 0 && ferror(mp->stream)) minitar_panic("Error while reading file header from tar archive"); if (rc == 0 && ferror(mp->stream)) minitar_handle_panic("Error while reading file header from tar archive");
if (rc < sizeof *hdr) minitar_panic("Valid tar files should be split in 512-byte blocks"); if (rc < sizeof *hdr) minitar_handle_panic("Valid tar files should be split in 512-byte blocks");
return 1; return 1;
} }