tig icon indicating copy to clipboard operation
tig copied to clipboard

~/.local/share/tig/history may not be used since version 2.5.6

Open yan12125 opened this issue 2 years ago • 1 comments

Since 2.5.6 (d308b74840e8b7ce8e5d00798bf578d3c92f4d92, particularly), if $XDG_DATA_HOME is valid, tig runs mkdir(dirname(path), 0777);. However, dirname() may modify the string pointed to by path [1]. If that happens, path no longer points to the desired history file.

For example, on Arch LInux, dirname() changes path from

"/home/yen/.local/share/tig/history\0"

to

"/home/yen/.local/share/tig\0history\0"

The following open() fails as path is now a directory, and the fallback ~/.tig_history is used.

By the way, is it a good idea to use permission 0777?

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirname.html

yan12125 avatar Jul 15 '22 15:07 yan12125

Figured out a fix: https://github.com/jonas/tig/pull/1217

yan12125 avatar Jul 16 '22 03:07 yan12125

@yan12125 , thanks for reporting and fixing the issue. To my dismay, macOS version of dirname() does not behave the same as Linux version, so I missed that. 0777 is further restricted by the user's umask, I don't think we have a reason to be more restrictive.

koutcher avatar Aug 18 '22 16:08 koutcher

0777 is further restricted by the user's umask, I don't think we have a reason to be more restrictive.

Got it!

yan12125 avatar Aug 19 '22 15:08 yan12125