From c298e32942b60d786587ebe1bdd1d117d3745031 Mon Sep 17 00:00:00 2001 From: Yorhel <git@yorhel.nl> Date: Thu, 6 Sep 2012 09:33:58 +0200 Subject: [PATCH] Check that stdin is a tty when initializing ncurses --- src/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 24885f7..64a530c 100644 --- a/src/main.c +++ b/src/main.c @@ -216,8 +216,16 @@ static void init_nc() { if(term) set_term(term); ok = !!term; - } else + } else { + /* Make sure the user doesn't accidentally pipe in data to ncdu's standard + * input without using "-f -". An annoying input sequence could result in + * the deletion of your files, which we want to prevent at all costs. */ + if(!isatty(0)) { + fprintf(stderr, "Standard input is not a TTY. Did you mean to import a file using '-f -'?\n"); + exit(1); + } ok = !!initscr(); + } if(!ok) { fprintf(stderr, "Error while initializing ncurses.\n"); -- GitLab