On Tue Mar 06 16:07:09 2012, zefram@fysh.org wrote:
> Father Chrysostomos via RT wrote:
> >- const MEM_SIZE len_wanted = sizeof(STRLEN) + size;
> >+ const MEM_SIZE len_wanted = sizeof(STRLEN) + WARNsize;
>
> No, still drastically wrong. size can legitimately be greater than the
> fixed WARNsize, due to dynamic category registration. You mustn't write
> those extra octets past the end of the allocated space (as this version
> of your patch does), nor is it acceptable to just drop them.
>
> The kind of munging you can sensibly do is to zero-pad an input that
> was shorter than WARNsize. Any input of WARNsize or longer is already
> handled correctly.
Thank you for your patience and your explanations. How about this patch?
diff --git a/util.c b/util.c
index 1ff5913..e6b5fa5 100644
--- a/util.c
+++ b/util.c
@@ -2002,7 +2002,8 @@ S_ckwarn_common(pTHX_ U32 w)
STRLEN *
Perl_new_warnings_bitfield(pTHX_ STRLEN *buffer, const char *const bits,
STRLEN size) {
- const MEM_SIZE len_wanted = sizeof(STRLEN) + size;
+ const MEM_SIZE len_wanted =
+ sizeof(STRLEN) + (size > WARNsize ? size : WARNsize);
PERL_UNUSED_CONTEXT;
PERL_ARGS_ASSERT_NEW_WARNINGS_BITFIELD;
@@ -2012,6 +2013,8 @@ Perl_new_warnings_bitfield(pTHX_ STRLEN *buffer,
const char *const bits,
PerlMemShared_realloc(buffer, len_wanted));
buffer[0] = size;
Copy(bits, (buffer + 1), size, char);
+ if (size < WARNsize)
+ Zero((char *)(buffer + 1) + size, WARNsize - size, char);
return buffer;
}
Without it, the problem that Marc mentioned will occur if a
common::sense is installed for 5.12 but then inadvertently used for 5.16.
--
Father Chrysostomos
---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=111500
Thread Previous
|
Thread Next