Skip to content

mod_autoindex: Don't clamp a pre-1970 last-modified date when sorting. - #1028

Open
arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/bz66182-autoindex-negative-mtime-clamp-v2
Open

arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/bz66182-autoindex-negative-mtime-clamp-v2

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

make_autoindex_entry() clamped any negative apr_time_t mtime to 0 when the listing's sort key was K_LAST_MOD, so a file or directory actually modified before 1970 was displayed as 1970-01-01 in a listing sorted by date (?C=M) -- while the same entry in the default, unsorted order (which doesn't hit that code path) already showed its real date.

The clamp dates back to the 1999 import of the Apache 1.3 codebase, from an era before apr_time_t's signed 64-bit microseconds-since-epoch could reliably represent dates before 1970. The module's own sentinel for "no mtime available" is the literal value -1 (checked with lm != -1 at both call sites that format it for display), not "any negative value", so clamping every negative value here only corrupts genuine pre-1970 timestamps; it was never needed to guard the sentinel.

Reproduced on a real build: a file with mtime touch -d 1958-01-01 showed "1958-01-01" in the default listing and "1970-01-01" once sorted with ?C=M. After removing the clamp, both orderings show the real 1958 date. Confirmed RED (clamp present) and GREEN (clamp removed) with the new regression test, run against a real server.

PR 66182


[x] This PR does not report or address a security vulnerability (see SECURITY.md and https://www.apache.org/security/#reporting-a-vulnerability).
[x] Code follows the httpd style guide.
[x] New log messages (level debug or higher) use an empty APLOGNO() tag (not applicable -- no new log messages).
[x] If the change is user-visible, a changes-entries/*.txt file is included.
[x] Test cases based on pyhttpd are included where appropriate (test/modules/generators/test_002_autoindex.py, extended with a new RED/GREEN-verified regression test).

make_autoindex_entry() clamped any negative apr_time_t mtime to 0 when
the listing's sort key was K_LAST_MOD, so a file or directory actually
modified before 1970 was displayed as 1970-01-01 in a listing sorted
by date (?C=M) -- while the same entry in the default, unsorted order
(which doesn't hit that code path) already showed its real date.

The clamp dates back to the 1999 import of the Apache 1.3 codebase, from
an era before apr_time_t's signed 64-bit microseconds-since-epoch could
reliably represent dates before 1970. The module's own sentinel for "no
mtime available" is the literal value -1 (checked with `lm != -1` at
both call sites that format it for display), not "any negative value",
so clamping every negative value here only corrupts genuine pre-1970
timestamps; it was never needed to guard the sentinel.

Reproduced on a real build: a file with mtime touch -d 1958-01-01 showed
"1958-01-01" in the default listing and "1970-01-01" once sorted with
?C=M. After removing the clamp, both orderings show the real 1958 date.

PR 66182
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant