Merge branch 'ap/path-max'
authorJunio C Hamano <gitster@pobox.com>
Fri, 10 Jan 2014 18:32:18 +0000 (10:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jan 2014 18:32:18 +0000 (10:32 -0800)
* ap/path-max:
Prevent buffer overflows when path is too long

1  2 
abspath.c
diff --combined abspath.c
index 8b3385a77749108b29d0a25042a13a174ddbc2e4,9c908e395b3456c6c0ecf15dabe37fcac0abca20..ca33558a91c5259a793fc56b571fa683e16b134f
+++ b/abspath.c
@@@ -143,7 -143,7 +143,7 @@@ static const char *real_path_internal(c
  error_out:
        free(last_elem);
        if (*cwd && chdir(cwd))
 -              die_errno ("Could not change back to '%s'", cwd);
 +              die_errno("Could not change back to '%s'", cwd);
  
        return retval;
  }
@@@ -215,23 -215,25 +215,25 @@@ const char *absolute_path(const char *p
   */
  const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
  {
-       static char path[PATH_MAX];
+       static struct strbuf path = STRBUF_INIT;
  #ifndef GIT_WINDOWS_NATIVE
        if (!pfx_len || is_absolute_path(arg))
                return arg;
-       memcpy(path, pfx, pfx_len);
-       strcpy(path + pfx_len, arg);
+       strbuf_reset(&path);
+       strbuf_add(&path, pfx, pfx_len);
+       strbuf_addstr(&path, arg);
  #else
        char *p;
        /* don't add prefix to absolute paths, but still replace '\' by '/' */
+       strbuf_reset(&path);
        if (is_absolute_path(arg))
                pfx_len = 0;
        else if (pfx_len)
-               memcpy(path, pfx, pfx_len);
-       strcpy(path + pfx_len, arg);
-       for (p = path + pfx_len; *p; p++)
+               strbuf_add(&path, pfx, pfx_len);
+       strbuf_addstr(&path, arg);
+       for (p = path.buf + pfx_len; *p; p++)
                if (*p == '\\')
                        *p = '/';
  #endif
-       return path;
+       return path.buf;
  }