about summary refs log tree commit homepage
path: root/ext/mwrap/mwrap.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-09-03 10:58:20 +0000
committerEric Wong <e@80x24.org>2022-09-03 11:06:24 +0000
commit13ecb7e5cf4ee769801e53d9df87141c6730e825 (patch)
treec208f8b5e4bbee358ad92b21df5069e3062aa751 /ext/mwrap/mwrap.c
parentfd15a49eb477b345e97ca3bbd6cde135cd0d6583 (diff)
downloadmwrap-13ecb7e5cf4ee769801e53d9df87141c6730e825.tar.gz
While I doubt Ruby (nor Perl) would store pathnames longer than
PATH_MAX by default, it's possible `eval' users to specify
whatever path (and line number) they wish to use.

Likely was the case with `# line $FILE' directives in Perl5
which prompted this clamping.
Diffstat (limited to 'ext/mwrap/mwrap.c')
-rw-r--r--ext/mwrap/mwrap.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index 90f560e..08761d6 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -470,6 +470,8 @@ static struct src_loc *update_stats_rcu_lock(size_t size, uintptr_t caller)
 
                 /* avoid vsnprintf or anything which could call malloc here: */
                 len = strlen(ptr);
+                if (len > PATH_MAX)
+                        len = PATH_MAX;
                 k = (void *)kbuf;
                 k->total = size;
                 dst = mempcpy(k->k, ptr, len);