Ticket #1664 (closed defect: fixed)

Opened 4 months ago

Last modified 4 months ago

include directive in configuration file do not manage absolute file paths

Reported by: lunatic Owned by: moo
Priority: low Milestone: 1.5.0
Component: core Version: 1.5.x-svn
Severity: minor Keywords: include_shell, include
Cc: Blocked By:
Need User Feedback: no Blocking:

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 (fn[0] == '/' && fn[0] == '.')

Attachments

test_config_file.diff (0.6 kB) - added by lunatic 4 months ago.
include_filename.diff

Change History

Changed 4 months ago by lunatic

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

Changed 4 months ago by lunatic

  • summary changed from weird interactions between include_shell and include to include directive in configuration file do not manage absolute file paths

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] == '\\'))

Changed 4 months ago by moo

  • owner changed from jan to moo
  • 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.

Changed 4 months ago by lunatic

include_filename.diff

Changed 4 months ago by lunatic

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

Changed 4 months ago by moo

  • status changed from assigned to closed
  • resolution set to fixed

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

Changed 4 months ago by moo

fixed in [2171] for 1.4.x

Changed 4 months ago by lunatic

Works for me. Thanks.

Add/Change #1664 (include directive in configuration file do not manage absolute file paths)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.