grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BUG] GRUBs option parsing needs fixing


From: Andreas Vogel
Subject: [BUG] GRUBs option parsing needs fixing
Date: Thu, 08 Mar 2012 14:12:30 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

Hi all,

I start a new thread with this mail in order to have a thread on its own
for this subject.

In another thread we've already had some discussion about GRUBs option
parsing. I wanna summarize and describe here about the issue.

Right now I see 2 problems with GRUBs argument parsing:

1) GRUBs argument parsing is not POSIX compliant.

Problem:
POSIX (and GNU too) recommends (see
http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html):

"An option and its argument may or may not appear as separate tokens.
(In other words, the whitespace separating them is optional.) Thus, ‘-o
foo’ and ‘-ofoo’ are equivalent."

This is doesn't hold for GRUB.
When I try
    load_env -fenv
an error message
    error: unknown argument '-e'.
is returned.

Solution:
The GRUB argument parser needs to be fixed so that short options are
parsed according to POSIX/GNU standards.

2) Optional option argument is not handled correctly (and not according
to POSIX/GNU standard)

Problem:
Right now the GRUB argument parser doesn't handle optional arguments
properly and it doesn't comply to POSIX/GNU standards.

For short options parsing fails for the reason described above and
because the parser allows that the option and its (optional) argument
might be separated with whitespace.

For long options parsing fails too because the parser allows that the
option and its (optional) argument might be separated with whitespace.
Example:
    OK: search  --file  --set  --nofloppy  /boot/grub/grub.cfg
    OK: search  --file  --set  --  /boot/grub/grub.cfg
    ERROR: search  --file  --set  /boot/grub/grub.cfg

Solution:
This solution follows just the POSIX/GNU standards for argument syntax
as stated in the above mentioned HTML document.
In order to be able to handle optional arguments for options the GRUB
argument parser needs to implement parsing according to the following
syntax:

a) Short option: e.g. option name 'x' taking an optional argument '<arg>'
     Possible options: "-x"   or   "-x<arg>"

b) Long option: e.g. option name 'xlong' taking an optional argument '<arg>'
     Possible options: "--xlong"   or   "--xlong=<arg>"  or  "--xlong="
     For the third form the upcoming implementation is somehow free to
decide how to interpret that option. Regarding to GNUs getopt() man
page, this form will be interpreted by getopt() as if the option isn't
specified at all (due to a bug). Because that interpretation is based on
a bug and because it might make more sense the third form could/should
be interpreted as if "--xlong" has been specified (meaning: options is
present but without value).

So for both, short and long options taking an optional value, no
whitespace between option and its value (if the value is present) is
allowed.

IMHO the option parsing code in GRUB2 should be fixed as soon as
possible. The later it will be done the more we'll have to fight with
compatibility issues.

Any comments?

Andreas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]