(canonicalize_file_name) [!HAVE_RESOLVEPATH]:
authorJim Meyering <jim@meyering.net>
Fri, 2 May 2003 21:42:51 +0000 (21:42 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 2 May 2003 21:42:51 +0000 (21:42 +0000)
A memory-allocation error could result in heap corruption.  Fix it
by also updating `dest' when rpath may be changed by xrealloc.

lib/canonicalize.c

index 453279d..6e58b28 100644 (file)
@@ -173,9 +173,11 @@ canonicalize_file_name (const char *name)
       if (!rpath)
        return NULL;
       dest = strchr (rpath, '\0');
-      if (dest < rpath + PATH_MAX)
+      if (dest - rpath < PATH_MAX)
        {
-         rpath = xrealloc (rpath, PATH_MAX);
+         char *p = xrealloc (rpath, PATH_MAX);
+         dest = p + (dest - rpath);
+         rpath = p;
          rpath_limit = rpath + PATH_MAX;
        }
       else