diff options
author | DLL125 <134442578+DLL125@users.noreply.github.com> | 2023-07-17 14:11:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-17 14:11:12 +0200 |
commit | 65765798d85258c0358b28b90aac68ed1851f49b (patch) | |
tree | 22f573edc4e16790d9be208fce95db1134fe2ba4 /src/Common/libzip/zip_source_file_stdio_named.c | |
parent | 6267b91931af87db2b95172389a6fbaac206e42e (diff) | |
download | VeraCrypt-65765798d85258c0358b28b90aac68ed1851f49b.tar.gz VeraCrypt-65765798d85258c0358b28b90aac68ed1851f49b.zip |
Libzip (#1152)
* Update LZMA to latest
* Update Libzip
Libzip updated to latest.
Diffstat (limited to 'src/Common/libzip/zip_source_file_stdio_named.c')
-rw-r--r-- | src/Common/libzip/zip_source_file_stdio_named.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/Common/libzip/zip_source_file_stdio_named.c b/src/Common/libzip/zip_source_file_stdio_named.c index 92ae344a..51e06a91 100644 --- a/src/Common/libzip/zip_source_file_stdio_named.c +++ b/src/Common/libzip/zip_source_file_stdio_named.c @@ -66,6 +66,7 @@ static zip_int64_t _zip_stdio_op_remove(zip_source_file_context_t *ctx); static void _zip_stdio_op_rollback_write(zip_source_file_context_t *ctx); static char *_zip_stdio_op_strdup(zip_source_file_context_t *ctx, const char *string); static zip_int64_t _zip_stdio_op_write(zip_source_file_context_t *ctx, const void *data, zip_uint64_t len); +static FILE *_zip_fopen_close_on_exec(const char *name, bool writeable); /* clang-format off */ static zip_source_file_operations_t ops_stdio_named = { @@ -300,11 +301,12 @@ static int create_temp_file(zip_source_file_context_t *ctx, bool create_file) { mode = -1; } - if ((temp = (char *)malloc(strlen(ctx->fname) + 13)) == NULL) { + size_t temp_size = strlen(ctx->fname) + 13; + if ((temp = (char *)malloc(temp_size)) == NULL) { zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0); return -1; } - sprintf(temp, "%s.XXXXXX.part", ctx->fname); + snprintf_s(temp, temp_size, "%s.XXXXXX.part", ctx->fname); end = temp + strlen(temp) - 5; start = end - 6; @@ -359,3 +361,32 @@ static int create_temp_file(zip_source_file_context_t *ctx, bool create_file) { return create_file ? fd : 0; } + + +/* + * fopen replacement that sets the close-on-exec flag + * some implementations support an fopen 'e' flag for that, + * but e.g. macOS doesn't. + */ +static FILE *_zip_fopen_close_on_exec(const char *name, bool writeable) { + int fd; + int flags; + FILE *fp; + + flags = O_CLOEXEC; + if (writeable) { + flags |= O_RDWR; + } + else { + flags |= O_RDONLY; + } + + /* mode argument needed on Windows */ + if ((fd = open(name, flags, 0666)) < 0) { + return NULL; + } + if ((fp = fdopen(fd, writeable ? "r+b" : "rb")) == NULL) { + return NULL; + } + return fp; +} |