Skip to content

librc: prevent false daemon matches across files - #1051

Open
pva wants to merge 1 commit into
OpenRC:masterfrom
pva:prevent-false-matches
Open

librc: prevent false daemon matches across files#1051
pva wants to merge 1 commit into
OpenRC:masterfrom
pva:prevent-false-matches

Conversation

@pva

@pva pva commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

_match_daemon() removes successful matches from the list while looking for a match. rc_service_daemon_set() and rc_service_started_daemon() call it with the same list for each daemon record file they scan. This causes a criterion matched by one file to be no longer required from the next: partial matches from different files could add up to a successful match.

Fix this by matching each file against a private copy of the list.

To reproduce the problem:

export D=/var/tmp/
mkdir -p "$D/openrc/daemons/foo"
printf 'exec=/usr/bin/foo\nargv_0=bar\npidfile=\n' > "$D/openrc/daemons/foo/001"
printf 'exec=/usr/bin/bar\nargv_0=foo\npidfile=\n' > "$D/openrc/daemons/foo/002"
cat >test.c <<EOF
#include <stdio.h>
#include <rc.h>

int main(void)
{
	const char *argv0[] = { "foo", NULL };
	rc_set_user();
	bool r = rc_service_started_daemon("foo", "/usr/bin/foo", argv0, 0);
	printf("%s\n", r ? "true (bug)" : "false");
	return !r;
}
EOF
gcc -o repro test.c -lrc
XDG_RUNTIME_DIR="$D" ./repro

Should not match, but it matches before this patch.

_match_daemon() removes successful matches from the list while looking
for a match. rc_service_daemon_set() and rc_service_started_daemon()
call it with the same list for each daemon record file they scan. This
causes a criterion matched by one file to be no longer required from the
next: partial matches from different files could add up to a successful
match.

Fix this by matching each file against a private copy of the list.
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