home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unreleased / patches / old / 5.4p.12 < prev    next >
Encoding:
Internet Message Format  |  1999-07-21  |  2.7 KB

  1. To: Mike Steed <mrsteed@usa.net>
  2. Cc: vim-dev@vim.org
  3. In-Reply-To: <19990722161430.20086.qmail@www0n.netaddress.usa.net>
  4. Subject: patch 5.4p.12 (was: 5.4p Win32 crash)
  5. Fcc: outbox
  6. From: Bram Moolenaar <Bram@moolenaar.net>
  7. ------------
  8.  
  9. Mike -
  10.  
  11. > Type :e zzzz... (about 256 z's), then hit 'wildchar', and Vim will crash.  A
  12. > silly thing to do, I know, but still, Vim shouldn't crash.
  13.  
  14. I have to use a longer zzzzz..., but it indeed crashes.
  15.  
  16. > I think the problem is that in win32_expandpath(), memory is being written
  17. > beyond the end of buf[].
  18.  
  19. Yes, looks like it.  The code assumes that the path is valid, and thus isn't
  20. longer than _MAX_PATH.  That isn't always true.
  21.  
  22. > I took a quick look at the code but wasn't sure of the best way to fix it.
  23.  
  24. dos_expandpath() allocates buf[].  That's a solution.  Also makes it more
  25. similar to the other xxx_expandpath() functions.
  26.  
  27. > And this may be something that gets put on the todo list until after 5.4 is
  28. > out.
  29.  
  30. I could still do that.  After all, it does solve a crash.  But I better make
  31. sure that it really fixes the problem, and not cause a new one...  OK, it does
  32. fix the problem for me.  And it's a simple change, since similar code is
  33. already used for MS-DOS.
  34.  
  35.  
  36. Patch 5.4p.12
  37. Problem:    Win32: Trying to expand a string that is longer than 256
  38.         characters could cause a crash. (Steed)
  39. Solution:   For the buffer in win32_expandpath() don't use a fixed size array,
  40.         allocate it.
  41. Files:        src/os_win32.c
  42.  
  43.  
  44. *** ../vim-5.4p/src/os_win32.c    Mon Jul 19 11:09:14 1999
  45. --- src/os_win32.c    Thu Jul 22 22:22:24 1999
  46. ***************
  47. *** 2603,2609 ****
  48.       char_u        *wildc,
  49.       int            flags)
  50.   {
  51. !     char        buf[_MAX_PATH+1];
  52.       char        *p, *s, *e;
  53.       int            start_len, c = 1;
  54.       WIN32_FIND_DATA    fb;
  55. --- 2603,2609 ----
  56.       char_u        *wildc,
  57.       int            flags)
  58.   {
  59. !     char        *buf;
  60.       char        *p, *s, *e;
  61.       int            start_len, c = 1;
  62.       WIN32_FIND_DATA    fb;
  63. ***************
  64. *** 2613,2618 ****
  65. --- 2613,2622 ----
  66.       int            len;
  67.   
  68.       start_len = gap->ga_len;
  69. +     /* make room for file name */
  70. +     buf = (char *)alloc(STRLEN(path) + BASENAMELEN + 5);
  71. +     if (buf == NULL)
  72. +     return 0;
  73.   
  74.       /*
  75.        * Find the first part in the path name that contains a wildcard.
  76. ***************
  77. *** 2700,2705 ****
  78. --- 2704,2710 ----
  79.           c = FindNextFile(hFind, &fb);
  80.       }
  81.       FindClose(hFind);
  82. +     vim_free(buf);
  83.   
  84.       matches = gap->ga_len - start_len;
  85.       if (matches)
  86.  
  87. --
  88. hundred-and-one symptoms of being an internet addict:
  89. 224. You set up your own Web page. You set up a Web page for each
  90.      of your kids... and your pets.
  91.  
  92. --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\--
  93.   \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /
  94.