Revert previous commit, but using strtoul(l) everywhere
I'm pretty sure every field in a tar header is unsigned octal...
This commit is contained in:
parent
30c7c0ad57
commit
6c696c67b1
@ -11,17 +11,6 @@ add_library(minitar STATIC ${SOURCES})
|
||||
|
||||
set_target_properties(minitar PROPERTIES OUTPUT_NAME mtar)
|
||||
|
||||
include(CheckSourceCompiles)
|
||||
|
||||
# Check for signedness of standard types
|
||||
check_source_compiles(C "#include <sys/types.h>\nint main(int argc, char** argv){ char is_unsigned_size_type[(size_t)0 < (size_t)-1 ? 1 : -1]; }" UNSIGNED_SIZE_TYPE)
|
||||
check_source_compiles(C "#include <sys/types.h>\nint main(int argc, char** argv){ char is_unsigned_time_type[(time_t)0 < (time_t)-1 ? 1 : -1]; }" UNSIGNED_TIME_TYPE)
|
||||
check_source_compiles(C "#include <sys/types.h>\nint main(int argc, char** argv){ char is_unsigned_mode_type[(mode_t)0 < (mode_t)-1 ? 1 : -1]; }" UNSIGNED_MODE_TYPE)
|
||||
check_source_compiles(C "#include <sys/types.h>\nint main(int argc, char** argv){ char is_unsigned_gid_type[(gid_t)0 < (gid_t)-1 ? 1 : -1]; }" UNSIGNED_GID_TYPE)
|
||||
check_source_compiles(C "#include <sys/types.h>\nint main(int argc, char** argv){ char is_unsigned_uid_type[(uid_t)0 < (uid_t)-1 ? 1 : -1]; }" UNSIGNED_UID_TYPE)
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY)
|
||||
|
||||
target_include_directories(minitar PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
if (MSVC)
|
||||
|
@ -1,5 +0,0 @@
|
||||
#cmakedefine UNSIGNED_SIZE_TYPE
|
||||
#cmakedefine UNSIGNED_TIME_TYPE
|
||||
#cmakedefine UNSIGNED_MODE_TYPE
|
||||
#cmakedefine UNSIGNED_GID_TYPE
|
||||
#cmakedefine UNSIGNED_UID_TYPE
|
27
src/util.c
27
src/util.c
@ -1,6 +1,5 @@
|
||||
#define _POSIX_C_SOURCE 200809L // for strndup
|
||||
#define _IN_MINITAR
|
||||
#include "config.h"
|
||||
#include "minitar.h"
|
||||
#include "tar.h"
|
||||
#include <stdio.h>
|
||||
@ -8,6 +7,8 @@
|
||||
#include <stdnoreturn.h>
|
||||
#include <string.h>
|
||||
|
||||
// Default implementation for minitar_handle_panic(). Since it's declared weak, any other definition will silently
|
||||
// override this one :)
|
||||
__attribute__((weak)) noreturn void minitar_handle_panic(const char* message)
|
||||
{
|
||||
fprintf(stderr, "minitar: %s\n", message);
|
||||
@ -28,48 +29,26 @@ void minitar_parse_tar_header(const struct tar_header* hdr, struct minitar_entry
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(metadata->name, hdr->prefix);
|
||||
strncpy(metadata->name, hdr->prefix, 155);
|
||||
strcat(metadata->name, "/");
|
||||
strncat(metadata->name, hdr->name, 100);
|
||||
metadata->name[256] = '\0';
|
||||
}
|
||||
|
||||
#ifdef UNSIGNED_MODE_TYPE
|
||||
metadata->mode = (mode_t)strtoul(hdr->mode, NULL, 8);
|
||||
#else
|
||||
metadata->mode = (mode_t)strtol(hdr->mode, NULL, 8);
|
||||
#endif
|
||||
|
||||
#ifdef UNSIGNED_UID_TYPE
|
||||
metadata->uid = (uid_t)strtoul(hdr->uid, NULL, 8);
|
||||
#else
|
||||
metadata->uid = (uid_t)strtol(hdr->uid, NULL, 8);
|
||||
#endif
|
||||
|
||||
#ifdef UNSIGNED_GID_TYPE
|
||||
metadata->gid = (gid_t)strtoul(hdr->gid, NULL, 8);
|
||||
#else
|
||||
metadata->gid = (gid_t)strtol(hdr->uid, NULL, 8);
|
||||
#endif
|
||||
|
||||
char* sizeptr = strndup(
|
||||
hdr->size, 12); // The hdr->size field is not null-terminated, yet strndup returns a null-terminated string.
|
||||
if (!sizeptr) minitar_panic("Failed to allocate memory to duplicate a tar header's size field");
|
||||
#ifdef UNSIGNED_SIZE_TYPE
|
||||
metadata->size = (size_t)strtoull(sizeptr, NULL, 8);
|
||||
#else
|
||||
metadata->size = (size_t)strtoll(sizeptr, NULL, 8);
|
||||
#endif
|
||||
free(sizeptr);
|
||||
|
||||
char* timeptr = strndup(
|
||||
hdr->mtime, 12); // The hdr->mtime field is not null-terminated, yet strndup returns a null-terminated string.
|
||||
if (!timeptr) minitar_panic("Failed to allocate memory to duplicate a tar header's mtime field");
|
||||
#ifdef UNSIGNED_TIME_TYPE
|
||||
metadata->mtime = (time_t)strtoull(timeptr, NULL, 8);
|
||||
#else
|
||||
metadata->mtime = (time_t)strtoll(timeptr, NULL, 8);
|
||||
#endif
|
||||
free(timeptr);
|
||||
|
||||
switch (hdr->typeflag)
|
||||
|
Loading…
Reference in New Issue
Block a user