resurrecting-open-source-projects / scrot

SCReenshOT - command line screen capture utility
Other
495 stars 49 forks source link

Maximum filename length is wrong #247

Closed guijan closed 1 year ago

guijan commented 1 year ago

Scrot uses this macro to check if input/output filenames are within a certain size: https://github.com/resurrecting-open-source-projects/scrot/blob/70a7540cfdc1000db8d400883c2eece386b5bf91/src/options.c#L61-L66 https://github.com/resurrecting-open-source-projects/scrot/blob/70a7540cfdc1000db8d400883c2eece386b5bf91/src/options.c#L76

The issue is that a maximum length of 256 is hardcoded, but the maximum filename length is a very complex issue. 256 could be too much or too little depending on the operating system, the file system, and even what directory the file is created in. The solution is that the code handling input/output filenames should pass around an alloc storage duration buffer and dynamically grow it as needed throughout the program's execution. Then, when the file is finally created, the system will return error if it fails to create the file.

Also, that code didn't have to be a macro.

229 partly fixes this bug along with a host of other bugs.

There is much more code around handling filenames which needs to be read carefully to check if it's free from this bug or not. The code that handles the output file and its filename is extremely buggy as many issues attest: #241 #244 #246 #228 #226 #223