8 added 412 characters in body
source | link

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

This was caused by a use-after-free bug which was fixed since dash 0.5.9, but which is still present in the dash 0.5.8 from Debian 9.8 stable (stretch), Ubuntu 18.04 (bionic) and Ubuntu 18.10 (cosmic).

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

A work-around is to put the trap handler in a function -- so that no commands run after the trap has been unset try to use the action string after it has been freed:

sighandler(){
    trap - "$sig" EXIT || exit "$?"
    kill -s "$sig" "$$" || exit "$?"
}
for sig in HUP INT QUIT ALRM TERM; do
    trap "sig=$sig; sighandler" "$sig"
done

kill -s HUP "$$"

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

This was caused by a use-after-free bug which was fixed since dash 0.5.9, but which is still present in the dash 0.5.8 from Debian 9.8 stable (stretch), Ubuntu 18.04 (bionic) and Ubuntu 18.10 (cosmic).

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

This was caused by a use-after-free bug which was fixed since dash 0.5.9, but which is still present in the dash 0.5.8 from Debian 9.8 stable (stretch), Ubuntu 18.04 (bionic) and Ubuntu 18.10 (cosmic).

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

A work-around is to put the trap handler in a function -- so that no commands run after the trap has been unset try to use the action string after it has been freed:

sighandler(){
    trap - "$sig" EXIT || exit "$?"
    kill -s "$sig" "$$" || exit "$?"
}
for sig in HUP INT QUIT ALRM TERM; do
    trap "sig=$sig; sighandler" "$sig"
done

kill -s HUP "$$"
7 added 49 characters in body
source | link

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

This was caused by a use-after-free bug which was fixed since dash 0.5.9, but which is still present in the dash 0.5.8 from Debian 9.8 stable (Stretchstretch), Ubuntu 18.04 (bionic) and Ubuntu 18.10 (cosmic).

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

This was caused by a use-after-free bug which was fixed since dash 0.5.9, but which is still present in the dash 0.5.8 from Debian 9.8 stable (Stretch).

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

This was caused by a use-after-free bug which was fixed since dash 0.5.9, but which is still present in the dash 0.5.8 from Debian 9.8 stable (stretch), Ubuntu 18.04 (bionic) and Ubuntu 18.10 (cosmic).

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
6 added 412 characters in body
source | link

[not really an answer yet, sorry]

I can reproduce the bug with dash 0.5.8 from debian 9.8 stretch.

The current dash code from git.kernel.org doesn't show the bug.

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

It remains to be seen if this severe heap corruption disappearedThis was caused by accidenta use-after-free bug which was fixed since dash 0.5.9, but which is still present in recent versions ofthe dash 0.5.8 from Debian 9.8 stable (and it could be still triggeredStretch) or if it was properly fixed.

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

[not really an answer yet, sorry]

I can reproduce the bug with dash 0.5.8 from debian 9.8 stretch.

The current dash code from git.kernel.org doesn't show the bug.

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

It remains to be seen if this severe heap corruption disappeared by accident in recent versions of dash (and it could be still triggered) or if it was properly fixed.

Here is a simplified testcase:

trap '
        trap    - HUP EXIT || exit "$?"
        kill -s HUP    "$$" || exit "$?" ' HUP INT
kill -HUP $$
$ dash dash-bug
dash-bug: 3: /home2/ahq/dash-bug: Syntax error: EOF in backquote substitution

Modifying the length or content of the quoted code may either "fix" the bug or produce different and interesting corruptions, with random bytes appearing out of nowhere.

This was caused by a use-after-free bug which was fixed since dash 0.5.9, but which is still present in the dash 0.5.8 from Debian 9.8 stable (Stretch).

This is the commit which fixed it:

commit 6c3f73bc536082fec38bd36e6c8a121033c68835
Author: Herbert Xu <herbert@gondor.apana.org.au>
Date:   Thu Oct 2 08:26:06 2014 +0800

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
5 simplify testcase
source | link
4 deleted 57 characters in body
source | link
3 Removed irrelevant text. The question doesn't even have a close vote yet.
source | link
2 deleted 9 characters in body
source | link
1
source | link