Project

General

Profile

Bug #1664

include directive in configuration file do not manage absolute file paths

Added by lunatic over 11 years ago. Updated over 11 years ago.

Status:
Fixed
Priority:
Low
Assignee:
-
Category:
core
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Missing in 1.5.x:

Description

When an "include_shell" generate "include file" lines there is sometimes some unexpected behavior due to the interaction between the "chdir basedir" in config_parse_cmd and the basedir prepending to the filename in config_parse_file.

For example if I do


   $ cd /my/home/rep
   $ /usr/sbin/lighttpd -f my_config_rep/lighttpd.conf

and an include_shell directive in lighttpd.conf generate "{{{include ./my_include_file}}}",
then lighttpd try to open the filename "{{{my_config_rep/./my_include_file}}}" (with the basedir prepended) from "{{{/my/top/rep/my_config_rep}}}" (to which it just changed).

When writing that you do not expect opening "{{{/my/top/rep/my_config_rep/my_config_rep/my_include_file}}}" which of course does not exist.

One solution is to not chdir when include_shell but it is not really good.
Another could be to have a special treatment of filename with "./" at the beginning and not prepending basedir for them.

This bug is perhaps related to #219 and #1221.

As a side note I just do not understand how this condition from configfile.c:875:


                      buffer_is_empty(context->basedir) &&
                        (fn[0] == '/' || fn[0] == '\\') &&
                        (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))

can ever be true ({{{fnr0 '/' && fnr0 '.'}}})

test_config_file.diff (595 Bytes) test_config_file.diff include_filename.diff lunatic, 2008-05-14 10:51

History

#1

Updated by lunatic over 11 years ago

Perhaps a quick fix should be just to document that only absolute filename behave well inside include_shell.

#2

Updated by lunatic over 11 years ago

Indeed the problem is worse than I thought, absolute filenames do not work at all with includes. The problem really is with the test before-mentioned.

I would rewrite it


    buffer_is_empty(context->basedir) ||
    (fn[0] == '/' || fn[0] == '\\') ||
    (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))
#3

Updated by moo over 11 years ago

  • Status changed from New to Assigned

let's see...


$ svn blame svn://svn.lighttpd.net/lighttpd/trunk/src/configfile.c@506 |grep -F 'fn['
   506        moo           (fn[0] == '/' || fn[0] == '\\') &&
   506        moo           (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) {

$ svn blame svn://svn.lighttpd.net/lighttpd/trunk/src/configfile.c@505 |grep -F 'fn['
   307        moo           (fn[0] == '/' || fn[0] == '\\') &&
   307        moo           (fn[0] == '.' && (fn[1] == '/' || fn[1] == '\\'))) {

assign to me, but can u pls try to change && to || and see if it works for you? or if it works in a reasonable way.

#4

Updated by lunatic over 11 years ago

Attached patch do it for me. Not a good patch and only barely tested but this my first try at the resolution.

#5

Updated by moo over 11 years ago

  • Status changed from Assigned to Fixed
  • Resolution set to fixed

can i assume that it fixed for you? commited to trunk as r2170, pending for 1.4.x

#6

Updated by moo over 11 years ago

fixed in r2171 for 1.4.x

#7

Updated by lunatic over 11 years ago

Works for me. Thanks.

Also available in: Atom