From e8824afa1ba9cec6b91428d991c6b0d9bc0c3877 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 22 Apr 2011 19:23:40 +1000 Subject: [PATCH] Do a sanity check on infile in lrzip to ensure it's working on a file it can compress. --- main.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 33662d8..c2a6a7b 100644 --- a/main.c +++ b/main.c @@ -35,6 +35,12 @@ #ifdef HAVE_SYS_RESOURCE_H # include #endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif #include #include #ifdef HAVE_ENDIAN_H @@ -718,8 +724,19 @@ int main(int argc, char *argv[]) control.infile = argv[i]; else if (!(i == 0 && STDIN)) break; - if (control.infile && (strcmp(control.infile, "-") == 0)) - control.flags |= FLAG_STDIN; + if (control.infile) { + if ((strcmp(control.infile, "-") == 0)) + control.flags |= FLAG_STDIN; + else { + struct stat infile_stat; + + stat(control.infile, &infile_stat); + if (unlikely(!S_ISREG(infile_stat.st_mode) && + !S_ISLNK(infile_stat.st_mode))) + failure("lrzip only works directly on FILES.\n" + "Use lrztar or pipe through tar for compressing directories.\n"); + } + } if (INFO && STDIN) failure("Will not get file info from STDIN\n");