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

Bug#673027: xkbcomp bad parsing of -w option



Control: tags -1 patch

On 2012-05-15 15:14:17 +0100, Zefram wrote:
> xkbcomp's warning-level option only works if the numeric argument comes
> in a separate command-line argument from the "-w".  E.g., "xkbcomp -w 3
> t0.xkb" and "xkbcomp -w 4 t0.xkb" work, and produce different degrees
> of verbosity.  But "xkbcomp -w3 t0.xkb" and "xkbcomp -w4 t0.xkb" both
> produce no warnings, as far as I can see.

The current code is:

        else if (strncmp(argv[i], "-w", 2) == 0)
        {
            if ((i >= (argc - 1)) || (!isdigit(argv[i + 1][0])))
            {
                warningLevel = 0;
                if (isdigit(argv[i][1]))
                    if (sscanf(&argv[i][1], "%i", &itmp) == 1)
                        warningLevel = itmp;
            }
            else
            {
                if (sscanf(argv[++i], "%i", &itmp) == 1)
                    warningLevel = itmp;
            }
        }

There are several bugs:
* It looks at the next argument before detecting whether -w already
  has a number attached to it, which yields an error when one uses
  -w<number> and the input file starts with a digit.
* In both occurrences of argv[i][1], 1 should be replaced by 2.
* Options like -wfoo are regarded in the same way as -w.

I've attached a patch that fixes these errors, but doesn't check
everything (garbage after the number is ignored). Anyway, that's
much better than the current code.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
--- xkbcomp/xkbcomp.c~	2013-12-25 13:01:29.000000000 +0100
+++ xkbcomp/xkbcomp.c	2014-07-29 15:31:07.233676040 +0200
@@ -579,17 +579,19 @@
         }
         else if (strncmp(argv[i], "-w", 2) == 0)
         {
-            if ((i >= (argc - 1)) || (!isdigit(argv[i + 1][0])))
+            if (argv[i][2] == 0)
             {
-                warningLevel = 0;
-                if (isdigit(argv[i][1]))
-                    if (sscanf(&argv[i][1], "%i", &itmp) == 1)
-                        warningLevel = itmp;
+                if (++i < argc && sscanf(argv[i], "%i", &itmp) == 1)
+                    warningLevel = itmp;
+                else
+                    warningLevel = 0;
             }
             else
             {
-                if (sscanf(argv[++i], "%i", &itmp) == 1)
+                if (sscanf(&argv[i][2], "%i", &itmp) == 1)
                     warningLevel = itmp;
+                else
+                    goto unknown_flag;
             }
         }
         else if ((strcmp(argv[i], "-xkb") == 0) && (!xkblist))
@@ -622,6 +624,7 @@
         }
         else
         {
+          unknown_flag:
             ERROR1("Unknown flag \"%s\" on command line\n", argv[i]);
             Usage(argc, argv);
             return False;

Reply to: