]> granicus.if.org Git - vim/commitdiff
patch 8.2.2793: MS-Windows: string literals are writable with MSVC v8.2.2793
authorBram Moolenaar <Bram@vim.org>
Wed, 21 Apr 2021 09:30:48 +0000 (11:30 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 21 Apr 2021 09:30:48 +0000 (11:30 +0200)
Problem:    MS-Windows: string literals are writable with MSVC.
Solution:   Add the /GF compiler flag.  Make mch_write() safer. (Ken Takata,
            closes #8133)

src/Make_mvc.mak
src/os_win32.c
src/version.c

index 257f7e033f9ea04a4a92284183247740054def22..0f5611a4341038caa2a7ab76dc1f9e0e3d5658a1 100644 (file)
@@ -489,7 +489,7 @@ CON_LIB = $(CON_LIB) /DELAYLOAD:comdlg32.dll /DELAYLOAD:ole32.dll DelayImp.lib
 #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)
index 9b692ec0e9c55d2378e620b8d05a27866f3064e3..d40d0332c2408515a37feae4980a6b701e5adcda 100644 (file)
@@ -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)
        {
index 01ec9a1bf6dbdd4062a6f31b6dca2877ff9adf8b..07a1e044fdf917659981423bb6d71b6895c6e058 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2793,
 /**/
     2792,
 /**/