bug-bash
[Top][All Lists]
Advanced

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

segmentation fault after interrupting function that uses "time"


From: Michael Maurer
Subject: segmentation fault after interrupting function that uses "time"
Date: Thu, 23 May 2024 13:43:16 +0200
User-agent: Evolution 3.46.4-2

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat 
-Werror=format-security -Wall
uname output: Linux nb 6.1.0-20-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.85-1 
(2024-04-11) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 15
Release Status: release

Description:
        Calling a function that itself uses the keyword "time" to call another 
function that performs a long task, and then interrupting with Ctrl+C before it 
is complete, causes a segfault. Behavior varies depending on whether or not the 
output of time is piped into another command, and whether the functions were 
sourced from a file or typed in directly.
        Seems similar to the bug previously reported here: 
https://lists.gnu.org/archive/html/bug-bash/2019-07/msg00004.html

Repeat-By:
        The simplest case can be reproduced with the following steps:
            foo ()  { sleep 10; echo 'output from long task'; }
            bar_1 () { time foo; }
            bar_1 # interrupt after a few seconds
            bar_1 # Segmentation fault

        Additionally, consider these variations:
            bar_2 () { time foo | cat; }
            bar_3 () { time (foo | cat); }
        
        If defined directly in the shell, calling and interrupting these 
functions causes no issues. If you source them from a script, however, bar_2 
behaves like bar_1 did above:
            . functions.sh # contains definition of foo and bar_[1-3]
            bar_2 # interrupt
            bar_2 # Segmentation fault
        Unless bar_3 is called AND interrupted beforehand:
            . functions.sh
            bar_3 # interrupt
            bar_2 # interrupt
            bar_2 # still works!
        If bar_3 finishes without interruption, bar_2 will still segfault 
afterwards. But bar_3 itself does not seem to have any issues.



reply via email to

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