From c21f4a43755d33ae3962ac7eaaecf1df87f746cf Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Sun, 25 Oct 2009 13:03:25 +0100
Subject: [PATCH] Avoid segfault in combine_path_nt on windows when the first
 char of an appended path is wide.

Rev: src/combine_path.h:1.16
---
 src/combine_path.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/combine_path.h b/src/combine_path.h
index 74b5e89d13..44c25873b4 100644
--- a/src/combine_path.h
+++ b/src/combine_path.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: combine_path.h,v 1.15 2004/05/01 15:25:04 mast Exp $
+|| $Id: combine_path.h,v 1.16 2009/10/25 12:03:25 mast Exp $
 */
 
 /*
@@ -39,7 +39,14 @@ static int find_absolute(PCHARP s)
 {
   int c0=INDEX_PCHARP(s,0);
   int c1=c0?INDEX_PCHARP(s,1):0;
-  if(isalpha(c0) && c1==':' && IS_SEP(INDEX_PCHARP(s,2)))
+  /* The following used to use isalpha(c0), but it apparently can
+   * index out-of-bound memory in the msvc 9.0 crt when given 16-bit
+   * char values (known to occur with 0x20ac, at least). Besides, a
+   * drive letter is limited to a..z, so this is faster and more
+   * correct. */
+  if(((c0 >= 'A' && c0 <= 'Z') ||
+      (c0 >= 'a' && c0 <= 'z')) &&
+     c1==':' && IS_SEP(INDEX_PCHARP(s,2)))
     return 3;
 
   if(IS_SEP(c0) && IS_SEP(c1))
-- 
GitLab