Bug 4676

Summary: Can't use '#' in mdev.conf CMD
Product: Busybox Reporter: Nikolay.Yaroshevich
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: major CC: busybox-cvs
Priority: P5    
Version: 1.18.x   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:
Attachments: Proposed patch

Description Nikolay.Yaroshevich 2012-01-06 09:56:29 UTC
Sample string from my mdev.conf:

dvb[0123]\..*                   0:0     660     @N=${MDEV%.*}; N=${N#dvb}; D=${MDEV#dvb?.}; mkdir -p dvb/adapter${N}; chmod 755 dvb dvb/adapter${N}; mv MDEV dvb/adapter${N}/${D}

Executing that cmd on corresponding event causes error:
sh: syntax error: missing '}'

After some tracing it looks like '#' is treated as start of comment. 

in util-linux/mdev.c:
            if (ENABLE_FEATURE_MDEV_EXEC && command) {
                /* setenv will leak memory, use putenv/unsetenv/free */
                char *s = xasprintf("%s=%s", "MDEV", node_name);
                char *s1 = xasprintf("%s=%s", "SUBSYSTEM", G.subsystem);
                putenv(s);
                putenv(s1);
        ------> bb_error_msg("\n*** trying to exec '%s' ***\n", command);
                if (system(command) == -1)
                    bb_perror_msg("can't run '%s'", command);
                bb_unsetenv_and_free(s1);
                bb_unsetenv_and_free(s);
                free(command);
            }

Resulting output:

mdev: 
*** trying to exec 'N=${MDEV%.*}; N=${N' ***

sh: syntax error: missing '}'
mdev: 
*** trying to exec 'N=${MDEV%.*}; N=${N' ***

sh: syntax error: missing '}'
Comment 1 Denys Vlasenko 2012-01-10 17:39:33 UTC
Created attachment 3956 [details]
Proposed patch