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
          Katayama Hirofumi MZ
        2. printargs.exe
          32 kB
          Katayama Hirofumi MZ
        3. printargsA.exe
          32 kB
          Katayama Hirofumi MZ
        4. printargsA-null-check.exe
          35 kB
          Katayama Hirofumi MZ
        5. printargsA-null-check-winxp-japanese-FAILED.png
          27 kB
          Katayama Hirofumi MZ
        6. printargsA-win10-successful.png
          8 kB
          Katayama Hirofumi MZ
        7. printargsA-win2k3-english-FAILED.png
          26 kB
          Katayama Hirofumi MZ
        8. printargsA-winxp-japanese-FAILED.png
          27 kB
          Katayama Hirofumi MZ
        9. printargs-null-check.c
          0.4 kB
          Katayama Hirofumi MZ
        10. printargsW.exe
          32 kB
          Katayama Hirofumi MZ
        11. printargsW-null-check.exe
          35 kB
          Katayama Hirofumi MZ
        12. printargsW-win10-successful.png
          8 kB
          Katayama Hirofumi MZ
        13. printargsW-win2k3-english-FAILED.png
          20 kB
          Katayama Hirofumi MZ
        14. printargsW-winxp-japanese-FAILED.png
          27 kB
          Katayama Hirofumi MZ

        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: