bug-grub
[Top][All Lists]

## Re: Cannot pass a single backslash in multiboot cmdline

 From: Andrei Borzenkov Subject: Re: Cannot pass a single backslash in multiboot cmdline Date: Mon, 26 Dec 2016 21:24:12 +0300 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

26.12.2016 21:12, Jakub Jermář пишет:
> Hi Andrei,
>
> On 12/26/2016 06:59 PM, Andrei Borzenkov wrote:
>> 26.12.2016 17:44, Jakub Jermář пишет:
>>> Hi,
>>>
>>> I am observing a strange behavior when passing boot arguments with a
>>> backslash to the kernel (the multiboot cmd_line via the multiboot
>>> command in grub.cfg). I would like to pass foo\bar to the kernel, but to
>>> no avail. I tried:
>>>
>>
>> Which kernel? What do you load?
>
> The kernel is a modified version of HelenOS, but IMHO this issue is
> kernel agnostic.

Not really. It depends on target program being loaded which is why I

> The cmd_line is already wrong when picked up from the
> multiboot info and printed out (so there is no processing on it from the
> HelenOS side).

Sure, but /if/ your kernel interpreted \' as quoting character, the
result would be correct.

> The argument I am trying to pass is actually a HelenOS
> path to the serial console service, something like:
>
> devices/\hw\pci0\00:01.0\com1\a
>
> The backslashes are part of the service's name.
>
>>> foo\bar gets passed as foobar
>>> foo\\bar gets passed as foo\\bar
>>> 'foo\bar' gets passed as foo\\bar
>>> "foo\bar" gets passed as foo\\bar
>>>
>>> Note that the backslash gets doubled when I try to escape it.
>>>
>>> I am using grub 2.02~beta2, revision
>>> bc220962e366b1b46769ed6f9fa5be603ba58ab5.
>>>
>>> How does one pass foo\bar so that the back slash does not get eaten or
>>> doubled?
>>>
>>
>> You can't currently. I do not know what was intended when grub cmdline
>> was written, but the way it quotes string is definitely not compatible
>> with linux kernel (which only recognizes "' as valid quote character).
>
> I think I understand why it is eating the single backslash (expected
> behavior),

You have two levels here. First level is grub command line processing.
It is loosely compatible with (Bourne) shell so yes, backslash is
treated as escape character. You can still pass backslash using usual
shell quoting, e.g. foo\\bar or 'foo\bar'. Second level is
grub_create_loader_cmdline() function. This one escapes \' with second
\'. So in the above case this function receives foo\bar' as adds
second \'.

Now if you pass it to linux kernel as example, it does not treat \'
specially so result is wrong. Same as in your case. It is just that
linux does not normally need it.

> so the issue mainly is with why is it duplicating the escaped
> (unexpected behavior) backslashes.
>
>> Could you please open formal bug report on savannah, so we could discuss
>> its priority.
>
> Ok, will do.
>
>> And yes, this is not the first report. Actually there could be similar
>
> Sorry, I was searching for it, but the bug tracking system on savannah
> is not very user friendly and I simply got no results.
>

Well, I won't argue here. I believe to have seen something similar, but
it may be on grub-devel.

`