Skip to content

Commit ba9c23e

Browse files
zdohnalbrammool
authored andcommitted
patch 8.2.3327: no check for sysconf() failing
Problem: No check for sysconf() failing. Solution: If sysconf() fails use SIGSTKSZ for the signal stack size. (Zdenek Dohnal, closes #8743)
1 parent 6e48b84 commit ba9c23e

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/os_unix.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -783,16 +783,36 @@ mch_stackcheck(char *p)
783783
* completely full.
784784
*/
785785

786-
#if !defined SIGSTKSZ && !defined(HAVE_SYSCONF_SIGSTKSZ)
787-
# define SIGSTKSZ 8000 // just a guess of how much stack is needed...
788-
#endif
789-
790786
# ifdef HAVE_SIGALTSTACK
791787
static stack_t sigstk; // for sigaltstack()
792788
# else
793789
static struct sigstack sigstk; // for sigstack()
794790
# endif
795791

792+
/*
793+
* Get a size of signal stack.
794+
* Preference (if available): sysconf > SIGSTKSZ > guessed size
795+
*/
796+
static long int get_signal_stack_size()
797+
{
798+
# ifdef HAVE_SYSCONF_SIGSTKSZ
799+
long int size = -1;
800+
801+
// return size only if sysconf doesn't return an error
802+
if ((size = sysconf(_SC_SIGSTKSZ)) > -1)
803+
return size;
804+
# endif
805+
806+
# ifdef SIGSTKSZ
807+
// if sysconf() isn't available or gives error, return SIGSTKSZ
808+
// if defined
809+
return SIGSTKSZ;
810+
# endif
811+
812+
// otherwise guess the size
813+
return 8000;
814+
}
815+
796816
static char *signal_stack;
797817

798818
static void
@@ -806,21 +826,13 @@ init_signal_stack(void)
806826
# else
807827
sigstk.ss_sp = signal_stack;
808828
# endif
809-
# ifdef HAVE_SYSCONF_SIGSTKSZ
810-
sigstk.ss_size = sysconf(_SC_SIGSTKSZ);
811-
# else
812-
sigstk.ss_size = SIGSTKSZ;
813-
# endif
829+
sigstk.ss_size = get_signal_stack_size();
814830
sigstk.ss_flags = 0;
815831
(void)sigaltstack(&sigstk, NULL);
816832
# else
817833
sigstk.ss_sp = signal_stack;
818834
if (stack_grows_downwards)
819-
# ifdef HAVE_SYSCONF_SIGSTKSZ
820-
sigstk.ss_sp += sysconf(_SC_SIGSTKSZ) - 1;
821-
# else
822-
sigstk.ss_sp += SIGSTKSZ - 1;
823-
# endif
835+
sigstk.ss_sp += get_signal_stack_size() - 1;
824836
sigstk.ss_onstack = 0;
825837
(void)sigstack(&sigstk, NULL);
826838
# endif
@@ -3278,11 +3290,7 @@ mch_early_init(void)
32783290
* Ignore any errors.
32793291
*/
32803292
#if defined(HAVE_SIGALTSTACK) || defined(HAVE_SIGSTACK)
3281-
# ifdef HAVE_SYSCONF_SIGSTKSZ
3282-
signal_stack = alloc(sysconf(_SC_SIGSTKSZ));
3283-
# else
3284-
signal_stack = alloc(SIGSTKSZ);
3285-
# endif
3293+
signal_stack = alloc(get_signal_stack_size());
32863294
init_signal_stack();
32873295
#endif
32883296
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3327,
758760
/**/
759761
3326,
760762
/**/

0 commit comments

Comments
 (0)