From d688c759ac3a36956df33b1c0d595d8f06eacdf9 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 31 May 2024 09:06:17 +0600 Subject: [PATCH] reject filenames with trailing slash (#376) avoids funny situations later down the line such as creating `/tmp/_000` when invoked as `scrot /tmp/` Fixes: https://github.com/resurrecting-open-source-projects/scrot/issues/228 --- src/options.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/options.c b/src/options.c index c5ac148..6279191 100644 --- a/src/options.c +++ b/src/options.c @@ -493,8 +493,11 @@ void optionsParse(int argc, char *argv[]) opt.outputFile = getPathOfStdout(); } - if (opt.outputFile[0] == '\0') - errx(EXIT_FAILURE, "output filename cannot be empty"); + size_t outputFileLen = strlen(opt.outputFile); + if (outputFileLen == 0) + errx(EXIT_FAILURE, "output file cannot be empty"); + if (opt.outputFile[outputFileLen - 1] == '/') + errx(EXIT_FAILURE, "output file cannot be a directory"); if (opt.thumb != THUMB_DISABLED) opt.thumbFile = optionsNameThumbnail(opt.outputFile);