MaxTyutyunnikov / grub4dos-chenall

Automatically exported from code.google.com/p/grub4dos-chenall
0 stars 0 forks source link

grldr not escaping control characters (such as "&&" or "||") #113

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,
As of today grldr is not escaping the control characters when used
in the kernel parameters. In some cases this would be very useful
as some kernel as ipxe may need to use parameters containing the
control charaters "&&" and "||".

As an example using the following menu.lst:
kernel /ipxe.lkrn dhcp && chain http://www.test.com/boot.ipxe
does not work as ipxe only receives the command line "dhcp"
as grldr uses and interpret the "&&" characters and trunc the line
after "dhcp", cf ipxe debug screen: control_not_transmitted.png

As an other example using the following menu.lst:
kernel /ipxe.lkrn dhcp \&\& chain http://www.test.com/boot.ipxe
does not work either as ipxe receives this time the whole command
line including the "\&\&" characters which have not being escaped
and does not work for ipxe, cf ipxe debug screen: escape_not_working.png

Could you please consider adding a way to escape control characters
in grldr so ipxe could be better used with grldr ?
Thank you very much for your consideration and support.
Best Regards,
Gilles van Ruymbeke

Original issue reported on code.google.com by ruymbeke on 10 Feb 2013 at 7:56

Attachments:

GoogleCodeExporter commented 9 years ago
Hello,
As a quick and dirty test, commenting out the lines of stage2/cmdline.c
handling the && and || operators seems to work fine, cf patch below.
So another option could be to have a new command to enable or disable
these operators interpretation by grub so they can be used within the
kernel command line for other programs to be parsed such as ipxe.
This is not as clean as adding grub the capability to handle complex
escape sequences but it may easier to add to the grub code.
Best Regards,
Gilles

Index: stage2/cmdline.c
===================================================================
--- stage2/cmdline.c    (revision 326)
+++ stage2/cmdline.c    (working copy)
@@ -164,12 +164,12 @@
    {
        switch (*(unsigned short *)cmd)
        {
-           case 0x2626://  operator AND "&&"
-               *status = 1;
-               break;
-           case 0x7C7C://  operator OR "||"
-               *status = 2;
-               break;
+//         case 0x2626://  operator AND "&&"
+//             *status = 1;
+//             break;
+//         case 0x7C7C://  operator OR "||"
+//             *status = 2;
+//             break;
            case 0x2021://  ! 
                *status = 4;
                break; 

Original comment by ruymbeke on 14 Feb 2013 at 11:27

GoogleCodeExporter commented 9 years ago
It is useful to be able to put environment variables in a kernel line

e.g. kernel /sss %option1% vga=780

so having an operator to disable this translation would be a retrograde step.

Could we perhaps have more filtering to allow \& and \| to be translated to & 
and | ?

Original comment by Steve6375 on 16 Feb 2013 at 5:12

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I also found another solution for kernels which can handle a script file as 
command line arguments, like ipxe. In this method scripts can created 
dynamically or use a written script.

1- Create a file of the needed size and fill it with null character.
2- Create a floppy or disk image of small size and put the file in it.
3- Use gzip to compress the image.
4- Map the image file as a floppy or disk.
5- echo/cat the needed script into the file.
6- Send the script file as the argument to the kernel.
7- Boot.

Example:
Create a script file to bypass the IP assigned by the pxe server to ipxe 
network stack instead of using another dhcp command in it and plus some other 
arbitrary code.

Lets name the disk image: menu.gz and the null-filled file in it, menu.ipxe and 
also a bunch of scripts stored in ()/menu2.ipxe.

map --mem ()/menu.gz (fd1)
map --hook
set Sct = (fd1)/menu.ipxe
set /a IP1 = *0x8284 & 0xFF
set /a IP2 = *0x8285 & 0xFF
set /a IP3 = *0x8286 & 0xFF
set /a IP4 = *0x8287 & 0xFF
set IP = %IP1%.%IP2%.%IP3%.%IP4%
echo #!ipxe >> %Sct%
echo ifopen net0 >> %Sct%
echo set net0/ip %IP% >> %Sct%
cat ()/menu2.ipxe >> %Sct%
echo boot >> %Sct%
echo >> %Sct%
kernel ()/ipxe.lkrn
initrd %Sct%

Original comment by Valizadeh.Ashkan on 16 Feb 2013 at 6:48

GoogleCodeExporter commented 9 years ago
Another way for this issue,try like below use '|'.
echo & chain http://www.test.com/boot.ipxe | kernel / ipxe.lkrn dhcp &

with the new version will escape the KERNEL parameter.that can use like below.
kernel /ipxe.lkrn dhcp \&\& chain http://www.test.com/boot.ipxe

Original comment by chenall.cn on 10 Mar 2013 at 3:22

GoogleCodeExporter commented 9 years ago
Please try this
grub4dos-0.4.5c-2013-03-10.7z

Original comment by chenall.cn on 10 Mar 2013 at 5:16

GoogleCodeExporter commented 9 years ago
Hi Chenall,
Both solutions are working good, thank you very much !
I like the idea (as a temporary work around) of "piping" the second "&" into the
kernel command line parameter (which has the fisrt "&") using the "echo" 
command.
Very cool trick ! 
And the escape sequence "\&\&" is now working well in the (test only)
grub4dos-0.4.5c-2013-03-10.7z build. I am looking forward the "featured" 
release.
Again thank you very much for the follow up and for both your time and effort
in keeping updating and improving this great tool.
Best Regards,
Gilles

Original comment by ruymbeke on 11 Mar 2013 at 6:00

GoogleCodeExporter commented 9 years ago
Thank you for your report and test.

Original comment by chenall.cn on 12 Mar 2013 at 1:41