Bug#962412: OpenRC and LSB header logic

Tito farmatito at tiscali.it
Sun Jun 7 21:06:51 BST 2020


On 6/7/20 7:27 PM, Ivan J. wrote:
> Package: insserv
> Version: 1.21.0-1
> 
> Hi. Attached is an insserv patch that adds better support for OpenRC
> initscripts. Naturally, it looks for #!/sbin/openrc-run as the shebang
> in the initscript and acts accordingly.
> 
> If merged, this can also close #960934
> 
Hi,
by looking at the patch it seems to me that:

 if (!strncmp(buf, "#!/sbin/openrc-run\n", 19))

is error prone unless for openrc initscripts there are
more restrictive rules than for sysv-initscripts.
On my system for example there are:

about 40 initscritps that start with:
#! /bin/sh
6 of them have whitespace at the end
'#! /bin/sh '
and 30 that start with
#!/bin/sh

if (!strncmp(buf, "#!/bin/sh\n", 10))

would miss more than 50% of them.
Your code catches of course the only openrc script

grep -r '^#!/sbin/openrc-run'
savecache:#!/sbin/openrc-run

but could you be sure for all other future openrc scripts?

Wouldn't it be safer to test for the consecutive tokens
#!  and /sbin/openrc-run
or maybe even better strip whitespace and newline
and test only for:
'#!/sbin/openrc-run' like:

int is_openrc_job(const char *path)
{
    char buf[64];
    FILE *script = NULL;
	char *p;
	
    script = fopen(path, "r");
    if (script == NULL) {
        warn("Can not open script %s: %s\n", path, strerror(errno));
        return 0;
    }

    if (fgets(buf, 64, script) == NULL) {
        warn("Could not read script %s: %s\n", path, strerror(errno));
        fclose(script);
        return 0;
    }

    fclose(script);
	
    p = buf;
    while (*p) {
       if (isspace(*p)) {
             memmove(p , p + 1, strlen(p + 1) + 1);
	  }
          p++;
   }

    if (!strncmp(buf, "#!/sbin/openrc-run", 18))
        return 1;

    return 0;
}

This code is just tested against a few corner case and might be
insecure or bugged as i didn't train my C skills a lot lately.

Just my 2 cents

Ciao,
Tito

root at devuan:/etc/init.d# grep -r ^#!
vivaldiframeworkd:#!/bin/bash
mountnfs.sh:#! /bin/sh
rsync:#! /bin/sh
hwclock.sh:#!/bin/sh
urandom:#! /bin/sh
rsyslog:#! /bin/sh
irqbalance:#!/bin/sh
single:#! /bin/sh
cron:#!/bin/sh
bootmisc.sh:#!/bin/sh
rcS:#!/bin/sh
checkroot.sh:#! /bin/sh
mdadm-waitidle:#!/bin/sh
rc.local:#! /bin/sh
mountall.sh:#! /bin/sh
eudev:#!/bin/sh -e
network-manager:#! /bin/sh
pppd-dns:#!/bin/sh -e
x11-common:#!/bin/sh
smartmontools:#!/bin/sh -e
sudo:#! /bin/sh
msm_profile:#!/bin/sh
cups-browsed:#! /bin/sh
brightness:#!/bin/sh
procps:#! /bin/sh
stop-bootlogd-single:#! /bin/sh
haveged:#! /bin/sh
reboot:#! /bin/sh
openvpn:#!/bin/sh -e
unattended-upgrades:#! /bin/sh
saned:#! /bin/sh
networking:#!/bin/sh -e
exim4:#! /bin/sh
vboxweb-service:#!/bin/sh
kmod:#!/bin/sh -e
binfmt-support:#! /bin/sh
mountdevsubfs.sh:#! /bin/sh
vboxdrv:#! /bin/sh
dbus:#!/bin/sh
stop-bootlogd:#! /bin/sh
slim:#!/bin/sh
checkfs.sh:#! /bin/sh
arno-iptables-firewall:#!/bin/sh
checkroot-bootclean.sh:#! /bin/sh
vboxballoonctrl-service:#!/bin/sh
umountfs:#! /bin/sh
sddm:#! /bin/sh
hddtemp:#!/bin/sh
hostname.sh:#! /bin/sh
pcscd:#! /bin/sh
console-setup.sh:#!/bin/sh
alsa-utils:#!/bin/sh
rc:#!/bin/sh
anacron:#! /bin/sh
mountall-bootclean.sh:#! /bin/sh
keyboard-setup.sh:#!/bin/sh
vboxautostart-service:#!/bin/sh
speech-dispatcher:#! /bin/sh
bootlogd:#! /bin/sh
lm-sensors:#!/bin/sh
avahi-daemon:#!/bin/sh
killprocs:#! /bin/sh
bootlogs:#!/bin/sh
halt:#! /bin/sh
savecache:#!/sbin/openrc-run
cups:#! /bin/sh
umountroot:#! /bin/sh
sendsigs:#! /bin/sh
bluetooth:#! /bin/sh
mdadm:#!/bin/sh
mountkernfs.sh:#! /bin/sh
mountnfs-bootclean.sh:#! /bin/sh
elogind:#! /bin/sh
umountnfs.sh:#! /bin/sh
rmnologin:#! /bin/sh
gdomap:#!/bin/sh




More information about the Debian-init-diversity mailing list