From ff2e8dd92d43e11705fcd2b493737bb58c4f2daa Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 16 Nov 2013 10:55:15 -0500 Subject: scanner: Use PATH_MAX, not hardcoded 1024 for realpath() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we can overflow the stack on longer pathnames. Tested-By: Mantas Mikulėnas --- giscanner/scannerlexer.l | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'giscanner') diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l index f80a8d61..89a34b88 100644 --- a/giscanner/scannerlexer.l +++ b/giscanner/scannerlexer.l @@ -31,6 +31,9 @@ %{ #include #include +#ifndef _WIN32 +#include +#endif #include #include "sourcescanner.h" @@ -317,11 +320,22 @@ check_identifier (GISourceScanner *scanner, return IDENTIFIER; } +/* taken from glib/gfileutils.c */ +#if defined(MAXPATHLEN) +#define G_PATH_LENGTH MAXPATHLEN +#elif defined(PATH_MAX) +#define G_PATH_LENGTH PATH_MAX +#elif defined(_PC_PATH_MAX) +#define G_PATH_LENGTH sysconf(_PC_PATH_MAX) +#else +#define G_PATH_LENGTH 2048 +#endif + static inline char * _realpath (const char *path) { #ifndef _WIN32 - char buffer[1025]; + char buffer[G_PATH_LENGTH]; return realpath (path, buffer) ? g_strdup (buffer) : NULL; #else -- cgit v1.2.1