https://bz.apache.org/bugzilla/show_bug.cgi?id=70258

            Bug ID: 70258
           Summary: apxs -A mishandles LoadModule entries at configuration
                    file boundaries
           Product: Apache httpd-2
           Version: 2.5-HEAD
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: support
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Tested on trunk bae35cfbf7. The -a/-A code in support/apxs.in is identical on
2.4.x. Found while investigating bug 69648; this is a distinct problem and
reproduces upstream.

The -a/-A code locates an existing LoadModule line with
    m|\n#?\s*$lmd_re|
and rewrites it with
    s|^(.*\n)#?\s*$lmd_re[^\n]*\n|$1$c$lmd\n|s
These patterns require a newline both before and after the line, so they do not
handle the first line or the last line of the file correctly.

Case 1: the LoadModule line is the first line of httpd.conf.

  d=$(mktemp -d); mkdir $d/conf
  printf 'LoadModule foo_module modules/mod_foo.so\nLoadModule other_module
modules/mod_other.so\n# end\n' > $d/conf/httpd.conf
  apxs -S SYSCONFDIR=$d/conf -e -A -n foo mod_foo.so
  cat $d/conf/httpd.conf

Expected: the first line becomes "#LoadModule foo_module ..." and the module is
disabled.
Actual: the active first line is left enabled and a commented duplicate is
appended after the last LoadModule line:

  LoadModule foo_module modules/mod_foo.so
  LoadModule other_module modules/mod_other.so
  #LoadModule foo_module         modules/mod_foo.so
  # end

The existence test does not see the first line (no preceding newline), so apxs
takes the "module not present" path and adds a new line instead of editing the
existing one. Running the command again changes nothing more, but the module
stays enabled.

Case 2: the LoadModule line is the last line and the file has no trailing
newline.

  printf 'LoadModule other_module modules/mod_other.so\nLoadModule foo_module
modules/mod_foo.so' > $d/conf/httpd.conf
  apxs -S SYSCONFDIR=$d/conf -e -A -n foo mod_foo.so

Expected: the line is disabled.
Actual: exit status 0 and "preparing module `foo'" is printed, but the file is
not changed and the module stays enabled. The existence test matches, but the
replacement needs a newline after the line, so the substitution silently
matches nothing.

With a trailing newline, or with the line anywhere in the middle of the file,
-A works as expected. Both cases come from the same assumption in the two
regular expressions: that the line is surrounded by newlines.

-a has the same problem. With an active LoadModule as the first line, apxs -e
-a appends a second active copy, so the module would be loaded twice. With a
commented LoadModule as the last line without a trailing newline, apxs -e -a
does not enable it.

Expected behavior: apxs -A and -a should find and edit the line wherever it is
in the file, including the first line and a last line without a trailing
newline, and repeated runs should be idempotent.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to