Skip to content

Commit e4963c5

Browse files
committed
patch 8.1.0976: dosinstall still has buffer overflow problems
Problem: Dosinstall still has buffer overflow problems. Solution: Adjust buffer sizes. (Yasuhiro Matsumoto, closes #4002)
1 parent c666388 commit e4963c5

4 files changed

Lines changed: 36 additions & 32 deletions

File tree

src/dosinst.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ get_vim_env(void)
388388

389389
/* First get $VIMRUNTIME. If it's set, remove the tail. */
390390
vim = getenv("VIMRUNTIME");
391-
if (vim != NULL && *vim != 0 && strlen(vim) < BUFSIZE)
391+
if (vim != NULL && *vim != 0 && strlen(vim) < sizeof(buf))
392392
{
393393
strcpy(buf, vim);
394394
remove_tail(buf);
@@ -411,7 +411,7 @@ get_vim_env(void)
411411

412412
/* NSIS also uses GetTempPath(), thus we should get the same directory
413413
* name as where NSIS will look for vimini.ini. */
414-
GetTempPath(BUFSIZE, fname);
414+
GetTempPath(sizeof(fname) - 12, fname);
415415
add_pathsep(fname);
416416
strcat(fname, "vimini.ini");
417417

@@ -456,7 +456,7 @@ window_cb(HWND hwnd, LPARAM lparam)
456456
static int
457457
run_silent_uninstall(char *uninst_exe)
458458
{
459-
char vimrt_dir[MAX_PATH];
459+
char vimrt_dir[BUFSIZE];
460460
char temp_uninst[BUFSIZE];
461461
char temp_dir[MAX_PATH];
462462
char buf[BUFSIZE * 2 + 10];
@@ -506,7 +506,7 @@ uninstall_check(int skip_question)
506506
char *uninstall_key = "software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
507507
char subkey_name_buff[BUFSIZE];
508508
char temp_string_buffer[BUFSIZE-2];
509-
DWORD local_bufsize = BUFSIZE;
509+
DWORD local_bufsize;
510510
FILETIME temp_pfiletime;
511511
DWORD key_index;
512512
char input;
@@ -521,12 +521,14 @@ uninstall_check(int skip_question)
521521
KEY_WOW64_64KEY | KEY_READ, &key_handle);
522522
CHECK_REG_ERROR(code);
523523

524-
for (key_index = 0;
525-
RegEnumKeyEx(key_handle, key_index, subkey_name_buff, &local_bufsize,
526-
NULL, NULL, NULL, &temp_pfiletime) != ERROR_NO_MORE_ITEMS;
527-
key_index++)
524+
key_index = 0;
525+
while (TRUE)
528526
{
529-
local_bufsize = BUFSIZE;
527+
local_bufsize = sizeof(subkey_name_buff);
528+
if (RegEnumKeyEx(key_handle, key_index, subkey_name_buff, &local_bufsize,
529+
NULL, NULL, NULL, &temp_pfiletime) == ERROR_NO_MORE_ITEMS)
530+
break;
531+
530532
if (strncmp("Vim", subkey_name_buff, 3) == 0)
531533
{
532534
/* Open the key named Vim* */
@@ -535,10 +537,10 @@ uninstall_check(int skip_question)
535537
CHECK_REG_ERROR(code);
536538

537539
/* get the DisplayName out of it to show the user */
540+
local_bufsize = sizeof(temp_string_buffer);
538541
code = RegQueryValueEx(uninstall_key_handle, "displayname", 0,
539542
&value_type, (LPBYTE)temp_string_buffer,
540543
&local_bufsize);
541-
local_bufsize = BUFSIZE;
542544
CHECK_REG_ERROR(code);
543545

544546
allow_silent = 0;
@@ -568,9 +570,9 @@ uninstall_check(int skip_question)
568570
fflush(stdout);
569571

570572
/* get the UninstallString */
573+
local_bufsize = sizeof(temp_string_buffer);
571574
code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0,
572575
&value_type, (LPBYTE)temp_string_buffer, &local_bufsize);
573-
local_bufsize = BUFSIZE;
574576
CHECK_REG_ERROR(code);
575577

576578
/* Remember the directory, it is used as the default for NSIS. */
@@ -683,6 +685,8 @@ uninstall_check(int skip_question)
683685

684686
RegCloseKey(uninstall_key_handle);
685687
}
688+
689+
key_index++;
686690
}
687691
RegCloseKey(key_handle);
688692

@@ -1826,7 +1830,7 @@ create_shortcut(
18261830
/* translate the (possibly) multibyte shortcut filename to windows
18271831
* Unicode so it can be used as a file name.
18281832
*/
1829-
MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, BUFSIZE);
1833+
MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, sizeof(wsz)/sizeof(wsz[0]));
18301834

18311835
/* set the attributes */
18321836
shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target);
@@ -2135,7 +2139,7 @@ install_OLE_register(void)
21352139
* result in "to[]".
21362140
*/
21372141
static void
2138-
dir_remove_last(const char *path, char to[BUFSIZE])
2142+
dir_remove_last(const char *path, char to[MAX_PATH])
21392143
{
21402144
char c;
21412145
long last_char_to_copy;
@@ -2206,7 +2210,7 @@ init_homedir(void)
22062210
if (homepath == NULL || *homepath == NUL)
22072211
homepath = "\\";
22082212
if (homedrive != NULL
2209-
&& strlen(homedrive) + strlen(homepath) < MAX_PATH)
2213+
&& strlen(homedrive) + strlen(homepath) < sizeof(buf))
22102214
{
22112215
sprintf(buf, "%s%s", homedrive, homepath);
22122216
if (buf[0] != NUL)
@@ -2234,10 +2238,9 @@ init_homedir(void)
22342238
buf[p - (var + 1)] = NUL;
22352239
exp = getenv(buf);
22362240
if (exp != NULL && *exp != NUL
2237-
&& strlen(exp) + strlen(p) < MAX_PATH)
2241+
&& strlen(exp) + strlen(p) < sizeof(buf))
22382242
{
2239-
_snprintf(buf, MAX_PATH, "%s%s", exp, p + 1);
2240-
buf[MAX_PATH - 1] = NUL;
2243+
sprintf(buf, "%s%s", exp, p + 1);
22412244
var = buf;
22422245
}
22432246
}
@@ -2351,10 +2354,11 @@ init_directories_choice(void)
23512354

23522355
// Check if the "compiler" directory already exists. That's a good
23532356
// indication that the plugin directories were already created.
2354-
if (getenv("HOME") != NULL)
2357+
p = getenv("HOME");
2358+
if (p != NULL)
23552359
{
23562360
vimfiles_dir_choice = (int)vimfiles_dir_home;
2357-
sprintf(tmp_dirname, "%s\\vimfiles\\compiler", getenv("HOME"));
2361+
sprintf(tmp_dirname, "%s\\vimfiles\\compiler", p);
23582362
if (stat(tmp_dirname, &st) == 0)
23592363
vimfiles_dir_choice = (int)vimfiles_dir_none;
23602364
}

src/dosinst.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ char *searchpath(char *name);
5959
/* ---------------------------------------- */
6060

6161

62-
#define BUFSIZE 512 /* long enough to hold a file name path */
62+
#define BUFSIZE (MAX_PATH*2) /* long enough to hold a file name path */
6363
#define NUL 0
6464

6565
#define FAIL 0
@@ -93,15 +93,15 @@ int interactive; /* non-zero when running interactively */
9393
static void *
9494
alloc(int len)
9595
{
96-
char *s;
96+
void *p;
9797

98-
s = malloc(len);
99-
if (s == NULL)
98+
p = malloc(len);
99+
if (p == NULL)
100100
{
101101
printf("ERROR: out of memory\n");
102102
exit(1);
103103
}
104-
return (void *)s;
104+
return p;
105105
}
106106

107107
/*
@@ -512,7 +512,7 @@ char *sysdrive; /* system drive or "c:\" */
512512
do_inits(char **argv)
513513
{
514514
/* Find out the full path of our executable. */
515-
if (my_fullpath(installdir, argv[0], BUFSIZE) == NULL)
515+
if (my_fullpath(installdir, argv[0], sizeof(installdir)) == NULL)
516516
{
517517
printf("ERROR: Cannot get name of executable\n");
518518
myexit(1);

src/uninstal.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ reg_delete_key(HKEY hRootKey, const char *key, DWORD flag)
6060
* Returns non-zero when it's found.
6161
*/
6262
static int
63-
popup_gvim_path(char *buf)
63+
popup_gvim_path(char *buf, DWORD bufsize)
6464
{
6565
HKEY key_handle;
6666
DWORD value_type;
67-
DWORD bufsize = BUFSIZE;
6867
int r;
6968

7069
/* Open the key where the path to gvim.exe is stored. */
@@ -87,11 +86,10 @@ popup_gvim_path(char *buf)
8786
* Returns non-zero when it's found.
8887
*/
8988
static int
90-
openwith_gvim_path(char *buf)
89+
openwith_gvim_path(char *buf, DWORD bufsize)
9190
{
9291
HKEY key_handle;
9392
DWORD value_type;
94-
DWORD bufsize = BUFSIZE;
9593
int r;
9694

9795
/* Open the key where the path to gvim.exe is stored. */
@@ -209,7 +207,7 @@ batfile_thisversion(char *path)
209207
fd = fopen(path, "r");
210208
if (fd != NULL)
211209
{
212-
while (fgets(line, BUFSIZE, fd) != NULL)
210+
while (fgets(line, sizeof(line), fd) != NULL)
213211
{
214212
for (p = line; *p != 0; ++p)
215213
/* don't accept "vim60an" when looking for "vim60". */
@@ -335,7 +333,7 @@ main(int argc, char *argv[])
335333

336334
printf("This program will remove the following items:\n");
337335

338-
if (popup_gvim_path(popup_path))
336+
if (popup_gvim_path(popup_path, sizeof(popup_path)))
339337
{
340338
printf(" - the \"Edit with Vim\" entry in the popup menu\n");
341339
printf(" which uses \"%s\"\n", popup_path);
@@ -349,7 +347,7 @@ main(int argc, char *argv[])
349347
remove_openwith();
350348
}
351349
}
352-
else if (openwith_gvim_path(popup_path))
350+
else if (openwith_gvim_path(popup_path, sizeof(popup_path)))
353351
{
354352
printf(" - the Vim \"Open With...\" entry in the popup menu\n");
355353
printf(" which uses \"%s\"\n", popup_path);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ static char *(features[]) =
779779

780780
static int included_patches[] =
781781
{ /* Add new patch number below this line */
782+
/**/
783+
976,
782784
/**/
783785
975,
784786
/**/

0 commit comments

Comments
 (0)