Package: dash Version: 0.5.8-2.4+edit Severity: normal Tags: patch Dear Maintainer,
This bug applies when dash is compiled with libedit support, which enables the 'fc' command. 'fc -s' can either take no arguments, in which it executes the last command, or one numerical argument, in which it executes the command with the given number as shown in 'fc -l'. On my system, either usage results in an infinite loop. dash has a built-in recursive block, which can be seen in action when calling 'fc -s' with no commands in history, starting a recursive 'fc -s' call. But the block seems ineffective against anything other than that specific case. A few tests: (1) start shell, 'fc -s' Recursive call, blocked after a few iterations. (2) start shell, 'echo Vanilla', 'fc -s' (3) start shell, 'man dash', 'fc -s' Both infinite loop.. (4) start shell, 'fc -l', 'fc -s' Successfully repeats 'fc -l', without infinite loop. (5) start shell, 'echo Vanilla, 'echo Chocolate', 'fc -l', 'fc -s 2' (6) start shell, 'coffee() { echo Coffee; }', coffee, 'fc -s' Infinite loop. I can provide text logs or video recordings for these cases, if needed! Aside from repeating a command at very high speeds, these infinite loops aren't very dangerous. They can easily be stopped with CTRL-C (or a combination of q and CTRl-C, for 'man dash'). ----- I played around with the source code for a few hours - both that of the version in stable and the version in sid - and tried making a few changes. The change from '==' to '>=' in the patch I'm including seems to be the only effective one. (Since it works, I suspect the problem is because because the he.num somehow surpasses last before the check finishes) I know Debian doesn't compile dash with libedit support for the repositories. But.. if this patch is not disagreeable, please consider incorporating it..! I will also appreciate it if someone can reproduce this issue. ----- he.num may somehow overrun last, causing an infinite loop when using fc -s. This mild change to the check plugs it. Index: dash/src/histedit.c =================================================================== --- dash.orig/src/histedit.c +++ dash/src/histedit.c @@ -388,7 +388,7 @@ histcmd(int argc, char **argv) * At end? (if we were to lose last, we'd sure be * messed up). */ - if (he.num == last) + if (he.num >= last) break; } if (editor) { -- System Information: Debian Release: 9.8 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 4.9.0-8-amd64 (SMP w/2 CPU cores) Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE= (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages dash depends on: ii debianutils 4.8.1.1 ii dpkg 1.18.25 ii libc6 2.24-11+deb9u4 ii libedit2 3.1-20160903-3 dash recommends no packages. dash suggests no packages.