diff src/memline.c @ 10896:d513b653f5d0 v8.0.0337

patch 8.0.0337: invalid memory access in :recover command commit https://github.com/vim/vim/commit/c525e3a1c20f6b5d9809c8b84f80090a8e416c92 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 18 16:59:02 2017 +0100 patch 8.0.0337: invalid memory access in :recover command Problem: Invalid memory access in :recover command. Solution: Avoid access before directory name. (Dominique Pelle, closes #1488)
author Christian Brabandt <cb@256bit.org>
date Sat, 18 Feb 2017 17:00:05 +0100
parents 5780bd3a5a7e
children 835604f3c37a
line wrap: on
line diff
--- a/src/memline.c
+++ b/src/memline.c
@@ -1863,8 +1863,10 @@ recover_names(
 	    else
 	    {
 #if defined(UNIX) || defined(WIN3264)
-		p = dir_name + STRLEN(dir_name);
-		if (after_pathsep(dir_name, p) && p[-1] == p[-2])
+		int	len = STRLEN(dir_name);
+
+		p = dir_name + len;
+		if (after_pathsep(dir_name, p) && len > 1 && p[-1] == p[-2])
 		{
 		    /* Ends with '//', Use Full path for swap name */
 		    tail = make_percent_swname(dir_name, fname_res);
@@ -3922,8 +3924,10 @@ makeswapname(
 #endif
 
 #if defined(UNIX) || defined(WIN3264)  /* Need _very_ long file names */
-    s = dir_name + STRLEN(dir_name);
-    if (after_pathsep(dir_name, s) && s[-1] == s[-2])
+    int		len = STRLEN(dir_name);
+
+    s = dir_name + len;
+    if (after_pathsep(dir_name, s) && len > 1 && s[-1] == s[-2])
     {			       /* Ends with '//', Use Full path */
 	r = NULL;
 	if ((s = make_percent_swname(dir_name, fname)) != NULL)