From 7aeb81f1de6a06c7ebc9a881e3a07591d760c9d6 Mon Sep 17 00:00:00 2001 From: Brandon Williams <bmwill@google.com> Date: Mon, 9 Jan 2017 10:50:23 -0800 Subject: [PATCH 1/2] real_path: prevent redefinition of MAXSYMLINKS The macro 'MAXSYMLINKS' is already defined on macOS and Linux in <sys/param.h>. If 'MAXSYMLINKS' has already been defined, use the value defined by the OS otherwise default to a value of 32 which is more inline with what is allowed by many systems. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> --- abspath.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/abspath.c b/abspath.c index 1d56f5ed9f9..0393213e5af 100644 --- a/abspath.c +++ b/abspath.c @@ -62,7 +62,9 @@ static void get_root_part(struct strbuf *resolved, struct strbuf *remaining) } /* We allow "recursive" symbolic links. Only within reason, though. */ -#define MAXSYMLINKS 5 +#ifndef MAXSYMLINKS +#define MAXSYMLINKS 32 +#endif /* * Return the real path (i.e., absolute path, with symlinks resolved From 0b9864aa28ba08d7fb901afee1a75a15e4ad431b Mon Sep 17 00:00:00 2001 From: Brandon Williams <bmwill@google.com> Date: Mon, 9 Jan 2017 10:50:24 -0800 Subject: [PATCH 2/2] real_path: set errno when max number of symlinks is exceeded Set errno to ELOOP when the maximum number of symlinks is exceeded, as would be done by other symlink-resolving functions. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> --- abspath.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/abspath.c b/abspath.c index 0393213e5af..fce40fddcc3 100644 --- a/abspath.c +++ b/abspath.c @@ -141,6 +141,8 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path, strbuf_reset(&symlink); if (num_symlinks++ > MAXSYMLINKS) { + errno = ELOOP; + if (die_on_error) die("More than %d nested symlinks " "on path '%s'", MAXSYMLINKS, path);