nixpkgs/pkgs/tools/compression/pxz/_SC_ARG_MAX.patch
2014-11-01 18:59:20 +01:00

37 lines
1 KiB
Diff

From b8f9827fc4de9296c7a6f5e6fdac46e070cd6cb4 Mon Sep 17 00:00:00 2001
From: Igor Pashev <pashev.igor@gmail.com>
Date: Sat, 1 Nov 2014 18:10:05 +0300
Subject: [PATCH] Fixed crash on Linux when stack size is unlimited
---
pxz.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/pxz.c b/pxz.c
index 9cb843e..52713e2 100644
--- a/pxz.c
+++ b/pxz.c
@@ -65,7 +65,7 @@ FILE **ftemp;
char str[0x100];
char buf[BUFFSIZE];
char *xzcmd;
-size_t xzcmd_max;
+const size_t xzcmd_max = 10240;
unsigned opt_complevel = 6, opt_stdout, opt_keep, opt_threads, opt_verbose;
unsigned opt_force, opt_stdout;
@@ -243,9 +243,12 @@ int main( int argc, char **argv ) {
lzma_filter filters[LZMA_FILTERS_MAX + 1];
lzma_options_lzma lzma_options;
- xzcmd_max = sysconf(_SC_ARG_MAX);
page_size = sysconf(_SC_PAGE_SIZE);
xzcmd = malloc(xzcmd_max);
+ if (!xzcmd) {
+ fprintf(stderr, "Failed to allocate %lu bytes for xz command.\n", xzcmd_max);
+ return -1;
+ }
snprintf(xzcmd, xzcmd_max, XZ_BINARY);
parse_args(argc, argv);