* [PATCH 0/2] various safety fixes from the Perl side
@ 2022-09-03 11:20 Eric Wong
2022-09-03 11:20 ` [PATCH 1/2] Ractor compatibility Eric Wong
2022-09-03 11:20 ` [PATCH 2/2] paranoid safety fix to clamp pathnames to PATH_MAX Eric Wong
0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-03 11:20 UTC (permalink / raw)
To: mwrap-public
It's unlikely any of these affect applications today, but
Ractor use may increase in the future; and maybe some
maniac will use giant __FILE__ replacements via eval.
Eric Wong (2):
Ractor compatibility
paranoid safety fix to clamp pathnames to PATH_MAX
ext/mwrap/mwrap.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] Ractor compatibility
2022-09-03 11:20 [PATCH 0/2] various safety fixes from the Perl side Eric Wong
@ 2022-09-03 11:20 ` Eric Wong
2022-09-03 11:20 ` [PATCH 2/2] paranoid safety fix to clamp pathnames to PATH_MAX Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-03 11:20 UTC (permalink / raw)
To: mwrap-public
We can no longer depend on having GVL/GIL when we have a Ruby
execution context, so so make `kbuf' thread-specific to avoid
data corruption.
This was ported from the Perl5 version, since Perl5 has had
MVM/Ractor-like abilities with native threads for decades,
despite the Perl5 ecosystem largely avoids and discourages
threads.
---
ext/mwrap/mwrap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index 1d6baec..90f560e 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -308,7 +308,9 @@ struct alloc_hdr {
size_t size;
};
-static char kbuf[PATH_MAX + INT2STR_MAX + sizeof(struct alloc_hdr) + 2];
+static MWRAP_TSD char kbuf[
+ PATH_MAX + INT2STR_MAX + sizeof(struct alloc_hdr) + 2
+];
static struct alloc_hdr *ptr2hdr(void *p)
{
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] paranoid safety fix to clamp pathnames to PATH_MAX
2022-09-03 11:20 [PATCH 0/2] various safety fixes from the Perl side Eric Wong
2022-09-03 11:20 ` [PATCH 1/2] Ractor compatibility Eric Wong
@ 2022-09-03 11:20 ` Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-03 11:20 UTC (permalink / raw)
To: mwrap-public
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.
---
ext/mwrap/mwrap.c | 2 ++
1 file changed, 2 insertions(+)
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);
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-03 11:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-03 11:20 [PATCH 0/2] various safety fixes from the Perl side Eric Wong
2022-09-03 11:20 ` [PATCH 1/2] Ractor compatibility Eric Wong
2022-09-03 11:20 ` [PATCH 2/2] paranoid safety fix to clamp pathnames to PATH_MAX Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).