Skip to content

Commit

Permalink
Validate passed library path exists
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Dec 11, 2023
1 parent a2ad3ad commit 47819f5
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions dyld-shared-cache-extractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@
#include <sys/syslimits.h>
#include <unistd.h>

__attribute__((noreturn))
__attribute__((__format__(__printf__, 1, 0))) static void
fail(const char *error, ...) {
va_list args;
va_start(args, error);
vfprintf(stderr, error, args);
va_end(args);
exit(EXIT_FAILURE);
}

static int (*extract)(const char *cache_path, const char *output_path,
void (^progress)(int, int));

static int get_library_path(const char *candidate, char *output) {
if (candidate) {
if (access(candidate, R_OK) != 0) {
fail("error: dsc_extractor.bundle not found at provided path: %s\n",
candidate);
}

strncpy(output, candidate, PATH_MAX);
return 0;
}
Expand All @@ -33,16 +48,6 @@ static int get_library_path(const char *candidate, char *output) {
return 1;
}

__attribute__((noreturn))
__attribute__((__format__(__printf__, 1, 0))) static void
fail(const char *error, ...) {
va_list args;
va_start(args, error);
vfprintf(stderr, error, args);
va_end(args);
exit(EXIT_FAILURE);
}

static int extract_shared_cache(const char *library_path,
const char *cache_path,
const char *output_path) {
Expand Down Expand Up @@ -71,9 +76,9 @@ int main(int argc, char *argv[]) {
if (access(shared_cache, R_OK) != 0)
fail("error: shared cache path doesn't exist: %s\n", shared_cache);

const char *libraryCandidate = argc == 4 ? argv[3] : NULL;
const char *library_candidate = argc == 4 ? argv[3] : NULL;
char library_path[PATH_MAX];
if (get_library_path(libraryCandidate, library_path) != 0)
if (get_library_path(library_candidate, library_path) != 0)
fail("error: failed to fetch Xcode path\n");

if (access(library_path, R_OK) != 0)
Expand Down

0 comments on commit 47819f5

Please sign in to comment.