[PATCH 1/2] shuf: fix a segfault on 'shuf -e'

Bartosz Golaszewski bartekgola at gmail.com
Thu Mar 6 18:12:17 UTC 2014


Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
---
 coreutils/shuf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/coreutils/shuf.c b/coreutils/shuf.c
index f213d67..eff0d36 100644
--- a/coreutils/shuf.c
+++ b/coreutils/shuf.c
@@ -126,7 +126,9 @@ int shuf_main(int argc, char **argv)
 		fclose_if_not_stdin(fp);
 	}
 
-	shuffle_lines(lines, numlines);
+	/* Skip shuffle_lines() for one or zero lines. */
+	if (numlines > 1)
+		shuffle_lines(lines, numlines);
 
 	if (opts & OPT_o)
 		xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
-- 
1.8.4.5



More information about the busybox mailing list