[vdr] vdr-1.4.1: bug report and fix: ReadLink with relative targets

Klaus Schmidinger Klaus.Schmidinger at cadsoft.de
Sat Jun 17 11:47:18 CEST 2006

Patrick Cernko wrote:
> Hi again,
> Patrick Cernko wrote:
>> Hi Klaus, hi list,
>> today I discovered that the ReadLink function (used in e.g. cSafeFile)
>> does not handle relative links correctly. I used a symlinked
>> channels.conf like that:
>> errror at ds9:/var/lib/vdr> ll channels.conf
>> lrwxrwxrwx  1 errror vdr 20 2006-06-12 00:03 channels.conf ->
>> channels.conf.normal
>> but vdr tried to write to channels.conf.$$$ in its current working
>> directory ("/") which failed. :-(
>> The bug is caused by the ReadLink function which always took the
>> unchanged value of the found link as target (without prepending the
>> links path for relative links).
>> As a fix, I added a check for relative links (== not starting with a
>> '/') and prepend the directory of the symlink. For that purpose I use
>> some small parts from the coreutils "dirname" program as I learned for a
>> long time that doing something so easy as computing the directory part
>> of a path can lead to several errors if not done right. :-)
>> Appended you find the patch, which makes vdr handle relative symlinks
>> correctly.
>> @Klaus: Feel free to review/reduce the code but pay attention to the
>> special cases! ;-)

Well, your patch looks like overkill to me ;-)

What about using 'canonicalize_file_name()' instead?

See the attached patch.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vdr-1.4.1-readlink.diff
Type: text/x-patch
Size: 988 bytes
Desc: not available
Url : http://www.linuxtv.org/pipermail/vdr/attachments/20060617/da40788c/vdr-1.4.1-readlink.bin

More information about the vdr mailing list