Bug 230621 - rc.subr wrong override for $command
Summary: rc.subr wrong override for $command
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.1-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-rc mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-14 18:04 UTC by Eugene Grosbein
Modified: 2018-12-03 23:24 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Grosbein freebsd_committer 2018-08-14 18:04:04 UTC
/etc/rc.subr has run_rc_command() function used with base system and ports. The function contains this code:

eval _override_command=\$${name}_program
command=${_override_command:-$command}

This code supposes that ${name} contents must have correct syntax for shell variable. This is wrong for our Ports Collection having plenty of ports with dash (-) in the ${name}. For such a port, ${name}_program expands to something like: part1-part2_program with non-existing (empty) $part1 variable.

So, _override_command ends up with always-non-empty wrong value "-part2_program". Therefore, the value of ${command} set by port's startup script is always ignored due to code cited above and replaced with bad "-part2_program" string that break it all.
Comment 1 Jilles Tjoelker freebsd_committer 2018-08-26 21:38:58 UTC
There is nothing that sets $name; each rc.d script must set it itself. To match documentation (rc.conf(5)) that states that shell variables can be set such as ⟨name⟩_nice, the name itself needs to be a valid shell variable name.

So if an rc.d script sets name to a literal, it must be a valid shell variable name. If a script can be linked to multiple names for multiple instances of a service, this translates to a requirement on the administrator about which names they can use. Sanitization here may as well make things more confusing.
Comment 2 Miroslav Lachman 2018-08-27 08:17:04 UTC
Dash is a problem also in base rc script for background fsck: /etc/rc.d/bgfsck
name="background-fsck"

I already posted about it 8 years ago without any reaction
https://lists.freebsd.org/pipermail/freebsd-rc/2010-January/001814.html
Comment 3 Jilles Tjoelker freebsd_committer 2018-08-27 21:42:54 UTC
The name= in etc/rc.d/bgfsck was finally fixed in 2014 in SVN r273013. This is present in 11.0 and newer but not in any 10.x or older versions.
Comment 4 Miroslav Lachman 2018-08-27 22:14:08 UTC
(In reply to Jilles Tjoelker from comment #3)
Thanks for the clarification. We are still using 10.4 so I didn't knew it was already fixed.
Comment 5 Jilles Tjoelker freebsd_committer 2018-12-03 23:24:19 UTC
The base parts are fixed in 11.0 and newer, and older versions are unsupported.