From adc2d0c9de764f1cb892860df8ecc93dc8909b39 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Mon, 21 Apr 2014 21:43:12 -0400 Subject: [PATCH] Fix for Coverity perl5 CID 29034: Out-of-bounds read (OVERRUN) overrun-local: Overrunning array PL_reg_intflags name of 14 8-byte elements at element index 31 (byte offset 248) using index bit (which evaluates to 31). Needed compile-time limits for the PL_reg_intflags_name so that the bit loop doesn't waltz off past the array. Could not use C_ARRAY_LENGTH because the size of name array is not visible during compile time (only const char*[] is), so modified regcomp.pl to generate the size, made it visible only under DEBUGGING. Did extflags analogously even though its size currently exactly 32 already. The sizeof(flags)*8 is extra paranoia for ILP64. --- regcomp.c | 8 ++++++-- regen/regcomp.pl | 17 ++++++++++++++++- regnodes.h | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/regcomp.c b/regcomp.c index 0238af9..920f7cb 100644 --- a/regcomp.c +++ b/regcomp.c @@ -15365,7 +15365,9 @@ S_regdump_intflags(pTHX_ const char *lead, const U32 flags) int bit; int set=0; - for (bit=0; bit<32; bit++) { + ASSUME(REG_INTFLAGS_NAME_SIZE <= sizeof(flags)*8); + + for (bit=0; bit) { @@ -332,6 +333,7 @@ for (0..31) { s/\bRXf_(PMf_)?// for $n, $extra; printf $out qq(\t%-20s/* 0x%08x%s */\n), qq("$n",),$power_of_2, $extra; + $REG_EXTFLAGS_NAME_SIZE++; } print $out <) { @@ -369,6 +378,7 @@ foreach my $file ("regcomp.h") { $comment= $comment ? " - $comment" : ""; printf $out qq(\t%-30s/* 0x%08x - %s%s */\n), qq("$abbr",), $val, $define, $comment; + $REG_INTFLAGS_NAME_SIZE++; } } } @@ -378,8 +388,13 @@ print $out <> 3] & (1 << ((node) & 7))) -- 2.7.4