summaryrefslogtreecommitdiff
path: root/abspath.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-01-10 10:32:18 -0800
committerJunio C Hamano <gitster@pobox.com>2014-01-10 10:32:18 -0800
commit273c54f82ca6bfd1f05be3bf8961c55ba60f16e5 (patch)
tree76cf71a350cce0307b800367985f4025813d8423 /abspath.c
parentb0504a95193504b9d37ef8f01b5b2403e345ee89 (diff)
parentfc2b6214542a46f97d7067b2f7df530ed37737a7 (diff)
downloadgit-273c54f82ca6bfd1f05be3bf8961c55ba60f16e5.tar.gz
Merge branch 'ap/path-max'
* ap/path-max: Prevent buffer overflows when path is too long
Diffstat (limited to 'abspath.c')
-rw-r--r--abspath.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/abspath.c b/abspath.c
index 8b3385a777..ca33558a91 100644
--- a/abspath.c
+++ b/abspath.c
@@ -215,23 +215,25 @@ const char *absolute_path(const char *path)
*/
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;
}