Uploaded image for project: 'Core ReactOS'
  1. Core ReactOS
  2. CORE-17787

CommandLineToArgvW quotes parse inaccurate implementation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Minor
    • 0.4.15
    • None

    Description

      https://github.com/reactos/reactos/blob/master/dll/win32/shell32/wine/shell32_main.c#L80

      Seems the function incorrectly parses sequence of quotes like `abc"""`

      I've found it when have run a set of tests:

      https://github.com/andry81/contools/blob/cb9c6a9962e9f7846b57b9c2067c79aff392df06/Utilities/tests/TODO.txt

      Specifically these tests has failed:

      printargs "0 1"" 2
      printargs "0 1""" 2
      

      The printargs utility just simply prints it's own command line:

      https://github.com/andry81/contools/blob/697dc55a313474fc1478c06c3cbc96eed8948908/Utilities/src/printargs/printargs.cpp

      Piece of code with the fix is here:

      https://github.com/andry81/contools/blob/9070c155775983394a414e26fa067a729ba2ec84/Utilities/src/_common/common.hpp#L3165

      The function _get_cmdline_arg_offsets just converts an array of argument indexes into an array of argument offsets in the initial command line.

      The actual piece of code which had a bug:

                  else if (*s == L'"')
                  {
                      quote_count = 0;
       
                      if (!(backslash_count & 1))
                          quote_count++; // unescaped
       
                      s++;
                      backslash_count = 0;
       
                      while (*s == L'"')
                      {
                          quote_count++;
                          s++;
                      }
       
                      if (quote_count & 1) {
                          quote_open = !quote_open;
                      }
                  }
      

      Attachments

        1. printargs.c
          0.3 kB
        2. printargs.exe
          32 kB
        3. printargsA.exe
          32 kB
        4. printargsA-null-check.exe
          35 kB
        5. printargsA-null-check-winxp-japanese-FAILED.png
          printargsA-null-check-winxp-japanese-FAILED.png
          27 kB
        6. printargsA-win10-successful.png
          printargsA-win10-successful.png
          8 kB
        7. printargsA-win2k3-english-FAILED.png
          printargsA-win2k3-english-FAILED.png
          26 kB
        8. printargsA-winxp-japanese-FAILED.png
          printargsA-winxp-japanese-FAILED.png
          27 kB
        9. printargs-null-check.c
          0.4 kB
        10. printargsW.exe
          32 kB
        11. printargsW-null-check.exe
          35 kB
        12. printargsW-win10-successful.png
          printargsW-win10-successful.png
          8 kB
        13. printargsW-win2k3-english-FAILED.png
          printargsW-win2k3-english-FAILED.png
          20 kB
        14. printargsW-winxp-japanese-FAILED.png
          printargsW-winxp-japanese-FAILED.png
          27 kB

        Issue Links

          Activity

            People

              katayama_hirofumi_mz Katayama Hirofumi MZ
              andry81 andry81
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: