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