Skip to contentSkip to conversation

pygrub: Fix command line argument error handling

PATCH In review Matthew Daley 2 participants 2 messages Nov 12, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pygrub: Fix command line argument error handling

pygrub's individual config file parsers do not correctly check the amount of command line arguments given to them. In addition, the LILO config parser would report an incorrect message.

Use len() to correctly check the amount of arguments, and fix the LILO error message.

tools/pygrub/src/ExtLinuxConf.py +1 -1
index 19776a3..510099b 100644
@@ -207,7 +207,7 @@ class ExtLinuxConfigFile(object):
                  }
         
 if __name__ == "__main__":
-    if sys.argv < 2:
+    if len(sys.argv) < 2:
         raise RuntimeError, "Need a configuration file to read"
     g = ExtLinuxConfigFile(sys.argv[1])
     for i in g.images:
tools/pygrub/src/GrubConf.py +1 -1
index c4f543d..629951f 100644
@@ -454,7 +454,7 @@ class Grub2ConfigFile(_GrubConfigFile):
                 }
         
 if __name__ == "__main__":
-    if sys.argv < 3:
+    if len(sys.argv) < 3:
         raise RuntimeError, "Need a grub version (\"grub\" or \"grub2\") and a grub.conf or grub.cfg to read"
     if sys.argv[1] == "grub":
         g = GrubConfigFile(sys.argv[2])
tools/pygrub/src/LiloConf.py +2 -2
index 9858ae2..2cb649f 100644
@@ -169,8 +169,8 @@ class LiloConfigFile(object):
                  }
 
 if __name__ == "__main__":
-    if sys.argv < 2:
-        raise RuntimeError, "Need a grub.conf to read"
+    if len(sys.argv) < 2:
+        raise RuntimeError, "Need a lilo.conf to read"
     g = LiloConfigFile(sys.argv[1])
     for i in g.images:
         print i #, i.title, i.root, i.kernel, i.args, i.initrd
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Matthew Daley

pygrub's individual config file parsers do not correctly check the amount of command line arguments given to them. In addition, the LILO config parser would report an incorrect message.

Use len() to correctly check the amount of arguments, and fix the LILO error message.

and applied, thanks.