apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1685929 - in /apr/apr/trunk: CHANGES file_io/win32/filepath.c test/testnames.c
Date Wed, 17 Jun 2015 03:40:21 GMT
Author: brane
Date: Wed Jun 17 03:40:20 2015
New Revision: 1685929

URL: http://svn.apache.org/r1685929
Log:
apr_filepath_merge: Fix truename length calculation on Windows
in cases where the "short" name variant is actually longer than
the "long" or "true" name.

Patch submitted bu Bert Huijben <rhuijben a.o>.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/file_io/win32/filepath.c
    apr/apr/trunk/test/testnames.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1685929&r1=1685928&r2=1685929&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Wed Jun 17 03:40:20 2015
@@ -1,6 +1,11 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_filepath_merge: Fix truename length calculation on Windows
+     in cases where the "short" name variant is actually longer than
+     the "long" or "true" name. See: testnames.c:merge_shortname().
+     [Bert Huijben <rhuijben a.o>]
+
   *) apr_file_mktemp: Use mkostemp() where available to save on system
      calls.  [Joe Orton]
 

Modified: apr/apr/trunk/file_io/win32/filepath.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/win32/filepath.c?rev=1685929&r1=1685928&r2=1685929&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/filepath.c (original)
+++ apr/apr/trunk/file_io/win32/filepath.c Wed Jun 17 03:40:20 2015
@@ -890,9 +890,9 @@ APR_DECLARE(apr_status_t) apr_filepath_m
                             memmove(path + keptlen + namelen + 1,
                                    path + keptlen + seglen + 1,
                                    pathlen - keptlen - seglen);
-                            pathlen += namelen - seglen;
-                            seglen = namelen;
                         }
+                        pathlen += namelen - seglen;
+                        seglen = namelen;
                     }
                     else { /* namelen > seglen */
                         if (pathlen + namelen - seglen >= sizeof(path))

Modified: apr/apr/trunk/test/testnames.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testnames.c?rev=1685929&r1=1685928&r2=1685929&view=diff
==============================================================================
--- apr/apr/trunk/test/testnames.c (original)
+++ apr/apr/trunk/test/testnames.c Wed Jun 17 03:40:20 2015
@@ -214,6 +214,39 @@ static void merge_lowercasedrive(abts_ca
 
   ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 }
+
+static void merge_shortname(abts_case *tc, void *data)
+{
+  apr_status_t rv;
+  char *long_path;
+  char short_path[MAX_PATH+1];
+  DWORD short_len;
+  char *result_path;
+
+  /* 'A b.c' is not a valid short path, so will have multiple representations
+     when short path name generation is enabled... but its 'short' path will
+     most likely be longer than the long path */
+  rv = apr_dir_make_recursive("C:/data/short/A b.c",
+                              APR_UREAD | APR_UWRITE | APR_UEXECUTE, p);
+  ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+  rv = apr_filepath_merge(&long_path, NULL, "C:/data/short/A b.c",
+                          APR_FILEPATH_NOTRELATIVE, p);
+  ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+  short_len = GetShortPathName(long_path, short_path, sizeof(short_path));
+  if (short_len > MAX_PATH)
+    return; /* Unable to test. Impossible shortname */
+
+  if (! strcmp(long_path, short_path))
+    return; /* Unable to test. 8dot3name option is probably not enabled */
+
+  rv = apr_filepath_merge(&result_path, "", short_path, APR_FILEPATH_TRUENAME,
+                          p);
+  ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+  ABTS_STR_EQUAL(tc, long_path, result_path);
+}
 #endif
 
 static void root_absolute(abts_case *tc, void *data)
@@ -341,6 +374,7 @@ abts_suite *testnames(abts_suite *suite)
     abts_run_test(suite, merge_dotdot_dotdot_dotdot, NULL);
 #if defined(WIN32)
     abts_run_test(suite, merge_lowercasedrive, NULL);
+    abts_run_test(suite, merge_shortname, NULL);
 #endif
 
     abts_run_test(suite, root_absolute, NULL);



Mime
View raw message