changeset 24506:cf773d752eb9 v8.2.2793

patch 8.2.2793: MS-Windows: string literals are writable with MSVC Commit: https://github.com/vim/vim/commit/d23f8bde5cd16b7752cc4a73da106673839ed824 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Apr 21 11:30:48 2021 +0200 patch 8.2.2793: MS-Windows: string literals are writable with MSVC Problem: MS-Windows: string literals are writable with MSVC. Solution: Add the /GF compiler flag. Make mch_write() safer. (Ken Takata, closes #8133)
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Apr 2021 11:45:04 +0200
parents b68e47dd5919
children b5fc06b7a412
files src/Make_mvc.mak src/os_win32.c src/version.c
diffstat 3 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -489,7 +489,7 @@ CON_LIB = $(CON_LIB) /DELAYLOAD:comdlg32
 #VIMRCLOC = somewhere
 #VIMRUNTIMEDIR = somewhere
 
-CFLAGS = -c /W3 /nologo $(CVARS) -I. -Iproto -DHAVE_PATHDEF -DWIN32 \
+CFLAGS = -c /W3 /GF /nologo $(CVARS) -I. -Iproto -DHAVE_PATHDEF -DWIN32 \
 		$(CSCOPE_DEFS) $(TERM_DEFS) $(SOUND_DEFS) $(NETBEANS_DEFS) $(CHANNEL_DEFS) \
 		$(NBDEBUG_DEFS) $(XPM_DEFS) \
 		$(DEFINES) -DWINVER=$(WINVER) -D_WIN32_WINNT=$(WINVER)
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -6406,15 +6406,13 @@ mch_write(
     char_u  *s,
     int	    len)
 {
+    char_u  *end = s + len;
+
 # ifdef VIMDLL
     if (gui.in_use)
 	return;
 # endif
 
-    // Avoid writing to a string literal.
-    if (s[len] != NUL)
-	s[len] = NUL;
-
     if (!term_console)
     {
 	write(1, s, (unsigned)len);
@@ -6435,10 +6433,13 @@ mch_write(
 	    return;
 	}
 
-	while ((ch = s[++prefix]))
+	while (s + ++prefix < end)
+	{
+	    ch = s[prefix];
 	    if (ch <= 0x1e && !(ch != '\n' && ch != '\r' && ch != '\b'
 						&& ch != '\a' && ch != '\033'))
 		break;
+	}
 
 	if (p_wd)
 	{
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2793,
+/**/
     2792,
 /**/
     2791,