bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

unwind_protect_string() macro broken for 64-bit machines


From: Brian . Boylston
Subject: unwind_protect_string() macro broken for 64-bit machines
Date: Tue, 13 Mar 2001 12:21:30 -0500 (EST)

Configuration Information [Automatically generated, do not change]:
Machine: alphaev56
OS: osf4.0f
Compiler: cc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='alphaev56' 
-DCONF_OSTYPE='osf4.0f' -DCONF_MACHTYPE='alphaev56-dec-osf4.0f' 
-DCONF_VENDOR='dec' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib 
-I/usr/local/include -O4 -arch host -std1
uname output: OSF1 brian.zk3.dec.com T5.0 1071 alpha
Machine Type: alphaev56-dec-osf4.0f

Bash Version: 2.04
Patch Level: 0
Release Status: release

Description:
    There is an inherent flaw in the design of the unwind_protect_var()
    family of functions and macros: the assumption that
    sizeof(int) == sizeof(char*), particularly in the case of the
    unwind_protect_string() macro.

Repeat-By:
    The following will cause bash to core dump on an alpha:

    bash-2.04$ funcA () {
    > echo funcA\!
    > }
    bash-2.04$ funcB () {
    > echo enter funcB
    > funcA
    > funcA
    > funcA
    > funcA
    > funcA
    > echo leave funcB
    }
    bash-2.04$ funcB
    enter funcB
    funcA!
    funcA!
    Segmentation fault (core dumped)

Fix:
    The fix I came up with is a bit lengthy, consisting of nearly a
    complete rewrite of the unwind_protect_var() family. Send mail
    if you're interested...

    For a glimpse of what is wrong, the following change to the definition
    of unwind_protect_string() makes it compatible with machines for
    which sizeof(int) != sizeof(char*), but breaks it for machines for
    which sizeof(int) == sizeof(char*):

    For sizeof(int) == sizeof(char*) (the current implementation):

      /* How to protect a pointer to a string. */
      #define unwind_protect_string(X) \
        unwind_protect_var ((int *)&(X), (X), sizeof (char *))

    For sizeof(int) != sizeof(char*) (a poor fix):

      /* How to protect a pointer to a string. */
      #define unwind_protect_string(X) \
        unwind_protect_var ((int *)&(X), &(X), sizeof (char *))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]