Skip to content

Commit

Permalink
reject filenames with trailing slash (#376)
Browse files Browse the repository at this point in the history
avoids funny situations later down the line such as creating `/tmp/_000`
when invoked as `scrot /tmp/`

Fixes: #228
  • Loading branch information
N-R-K authored May 31, 2024
1 parent 95350f6 commit d688c75
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d688c75

Please sign in to comment.