Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines
Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.
REPEAT: Do NOT report bugs for outdated packages!
https://wiki.archlinux.org/title/Bug_reporting_guidelines
Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.
REPEAT: Do NOT report bugs for outdated packages!
FS#39534 - [freecol] Invalid redirect destination in fc.sh
Attached to Project:
Community Packages
Opened by mpan (mpan) - Wednesday, 19 March 2014, 04:21 GMT
Last edited by Sven-Hendrik Haase (Svenstaro) - Wednesday, 02 April 2014, 09:38 GMT
Opened by mpan (mpan) - Wednesday, 19 March 2014, 04:21 GMT
Last edited by Sven-Hendrik Haase (Svenstaro) - Wednesday, 02 April 2014, 09:38 GMT
|
DetailsDescription:
"fc.sh" script creates "/tmp/freecol" directory with 755 permissions and overwrites "messages.log" file located in it. This are three bugs. First: the name is hardcoded. Second: permissions are invalid. Third: the operation is not atomic. For purpose of creating temporary files and directories `mktemp` should be used. It provides proper name selection and guarantees both proper permissions and atomicity. Fixed version: ------------------------------------------------------------ #!/bin/bash FC_PATH=/usr/share/java/freecol cd $(mktemp -d) java -Xmx512M -jar $FC_PATH/FreeCol.jar "$@" --freecol-data $FC_PATH/data --no-intro &> ./messages.log ------------------------------------------------------------ |
This task depends upon
Closed by Sven-Hendrik Haase (Svenstaro)
Wednesday, 02 April 2014, 09:38 GMT
Reason for closing: Fixed
Additional comments about closing: I'm gonna call this fixed. If still unsatisfied, reopen.
Wednesday, 02 April 2014, 09:38 GMT
Reason for closing: Fixed
Additional comments about closing: I'm gonna call this fixed. If still unsatisfied, reopen.
Authors of `mktemp` know well what they do and don't try to break their choices.
Do not hardcode the temporary directory. It's not always "/tmp". `mktemp` does it properly by detecting the right one from the environment. If you want to provide a string that allows name to be distinctive and give a hint that it's freecol's directory, use --suffix option:
mktemp --suffix=.freecol
and this will create directories in a form:
/temporaryDir/tmp.hHia91mAcU.freecol
/temporaryDir/tmp.0Aim6DsM91.freecol
...
If the condition from line 6 would not always fail, it would be allowing `install -md755 $LOG_PATH` to be executed. There are two bugs in that command:
1. Lack of quotes around variable expansion. Since the value is passed to command that changes permissions and can silently accept multiple paths, it creates a security threat. A low severity one, but still...
2. The command is widening permissions. The permissions should be ones that `mktemp` has set.
For unknown reason the current code is also truncating names space by providing only 3 X-es compared to default 10. This means that for 1% probability of collision only 70 instances are required and for 50%: 570. Not a big issue practially², but there is really no reason to decrease this value. Just stick to `mktemp`'s defaults.
There is really a good reason I've removed whole `[ -d ... ] install ... $LOGPATH` part. It wasn't for decreasing file size ;).
¹ The only case it isn't is when `mktemp` fails. But if it does, then
the command following the condition will fail too.
² Happily `mktemp` prevents users from decreasing names space so low
that it would become a real problem.
It's not about not copying my solution, but about overriding what `mktemp` authors have choosen.
I've checked up the package. Seems to work right. There are some minor things that could be changed, but I believe they're not worth another package upgrade.
Thanks for fixing.
I've noticed 1 downside of using mktemp over the mkdir method :
with the mkdir method freecol used the same directory every time it was started (and the messages.log file was overwritten) .
Now it creates a new directory / file every time it's started.
I play freecol a lot, and tend to start it 10+ times between reboots , which leads to many directories for freecol in the tmp folder.
Suggestions how to avoid this ?
So maybe it's the right moment to ask the question: why is the directory needed?
Freecol has extensive internal logging, but that starts AFTER the freecol.jar is activated.
messages.log captures the output from the 'java -Xmx256M -jar $FC_PATH/FreeCol.jar "$@" --freecol-data $FC_PATH/data \
+ &> ./messages.log' command.
If something goes wrong with starting freecol before it's internal logging kicks in, messages.log is the only place with info to check what happened.
It is useful info, where should a log file with runtime info be placed ?
~/.freecol
the latest git version of freecol follows XDG rules,
and defaults to ~/.cache/freecol for it's log file on new installs.
If something goes wrong when starting java, the output goes to stderr and this is the place everyone checks.
Also there is no need to start from terminal. In X stderr and stdout are redirected to ~/.xsessionerrors file and this is the place everyone check first for errors from graphical applications.