Skip to content

Commit 63ec64f

Browse files
committed
Merge branch 'Assert string ptrs in-bounds' into blead
There are a bunch of functions that are passed pointers to two positions in a string. These commits allow you to declare these in embed.fnc, and have an assert like (s < e) generated that is automatically placed in the PERL_ARGS_ASSERT for the function. Many entries in embed.fnc are changed to use this new capability. This is extended for functions where it should instead be assert(s <= e) and assert(s <= cur)
2 parents 3a7b25b + a02324b commit 63ec64f

File tree

9 files changed

+617
-355
lines changed

9 files changed

+617
-355
lines changed

autodoc.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ sub check_and_add_proto_defn {
620620
$flags .= "n" if $flags =~ /#/; # No threads, arguments for #ifdef
621621

622622
my @munged_args= $args_ref->@*;
623-
s/\b(?:NN|NULLOK)\b\s+//g for @munged_args;
623+
s/\b(?:NN|NULLOK|[SM]PTR|EPTRQ?)\b\s+//g for @munged_args;
624624

625625
my $flags_sans_d = $flags;
626626
my $docs_expected = $flags_sans_d =~ s/d//g;

embed.fnc

Lines changed: 286 additions & 215 deletions
Large diffs are not rendered by default.

inline.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,7 +2963,6 @@ Perl_utf8_hop_back_overshoot(const U8 *s, SSize_t off,
29632963
const U8 * const start, SSize_t *remaining)
29642964
{
29652965
PERL_ARGS_ASSERT_UTF8_HOP_BACK_OVERSHOOT;
2966-
assert(start <= s);
29672966
assert(off <= 0);
29682967

29692968
/* Note: if we know that the input is well-formed, we can do per-word
@@ -3031,8 +3030,6 @@ Perl_utf8_hop_overshoot(const U8 *s, SSize_t off,
30313030
{
30323031
PERL_ARGS_ASSERT_UTF8_HOP_OVERSHOOT;
30333032

3034-
assert(start <= s && s <= end);
3035-
30363033
if (off >= 0) {
30373034
return utf8_hop_forward_overshoot(s, off, end, remaining);
30383035
}

proto.h

Lines changed: 98 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

regen/embed.pl

Lines changed: 231 additions & 44 deletions
Large diffs are not rendered by default.

regexec.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ STATIC U8 *
627627
S_find_span_end(U8 * s, const U8 * send, const U8 span_byte)
628628
{
629629
PERL_ARGS_ASSERT_FIND_SPAN_END;
630-
assert(send >= s);
631630

632631
/* Returns the position of the first byte in the sequence between 's' and
633632
* 'send-1' inclusive that isn't 'span_byte'; returns 'send' if none found.
@@ -700,7 +699,6 @@ STATIC U8 *
700699
S_find_next_masked(U8 * s, const U8 * send, const U8 byte, const U8 mask)
701700
{
702701
PERL_ARGS_ASSERT_FIND_NEXT_MASKED;
703-
assert(send >= s);
704702
assert((byte & mask) == byte);
705703

706704
/* Returns the position of the first byte in the sequence between 's'
@@ -777,7 +775,6 @@ STATIC U8 *
777775
S_find_span_end_mask(U8 * s, const U8 * send, const U8 span_byte, const U8 mask)
778776
{
779777
PERL_ARGS_ASSERT_FIND_SPAN_END_MASK;
780-
assert(send >= s);
781778
assert((span_byte & mask) == span_byte);
782779

783780
/* Returns the position of the first byte in the sequence between 's' and

toke.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,6 @@ STATIC void
18871887
S_incline(pTHX_ const char *s, const char *end)
18881888
{
18891889
PERL_ARGS_ASSERT_INCLINE;
1890-
assert(end >= s);
18911890

18921891
const char *t;
18931892
const char *n;
@@ -2855,7 +2854,6 @@ Perl_get_and_check_backslash_N_name(pTHX_ const char* s,
28552854
const char ** error_msg)
28562855
{
28572856
PERL_ARGS_ASSERT_GET_AND_CHECK_BACKSLASH_N_NAME;
2858-
assert(e >= s);
28592857
assert(s > (char *) 3);
28602858

28612859
/* <s> points to first character of interior of \N{}, <e> to one beyond the

utf8.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ STRLEN
725725
Perl_is_utf8_char_helper_(const U8 * const s, const U8 * e, const U32 flags)
726726
{
727727
PERL_ARGS_ASSERT_IS_UTF8_CHAR_HELPER_;
728-
assert(e > s);
729728
assert(0 == (flags & ~UTF8_DISALLOW_ILLEGAL_INTERCHANGE));
730729

731730
SSize_t len, full_len;
@@ -755,6 +754,7 @@ Perl_is_utf8_char_helper_(const U8 * const s, const U8 * e, const U32 flags)
755754
* determined with just the first one or two bytes.
756755
*
757756
*/
757+
758758
full_len = UTF8SKIP(s);
759759

760760
len = e - s;
@@ -840,7 +840,6 @@ Perl_is_utf8_FF_helper_(const U8 * const s0, const U8 * const e,
840840
const bool require_partial)
841841
{
842842
PERL_ARGS_ASSERT_IS_UTF8_FF_HELPER_;
843-
assert(s0 < e);
844843
assert(*s0 == I8_TO_NATIVE_UTF8(0xFF));
845844

846845
/* This is called to determine if the UTF-8 sequence starting at s0 and
@@ -4245,7 +4244,6 @@ S_turkic_fc(pTHX_ const U8 * const p, const U8 * const e,
42454244
U8 * ustrp, STRLEN *lenp)
42464245
{
42474246
PERL_ARGS_ASSERT_TURKIC_FC;
4248-
assert(e > p);
42494247

42504248
/* Returns 0 if the foldcase of the input UTF-8 encoded sequence from
42514249
* p0..e-1 according to Turkic rules is the same as for non-Turkic.
@@ -4280,7 +4278,6 @@ S_turkic_lc(pTHX_ const U8 * const p0, const U8 * const e,
42804278
U8 * ustrp, STRLEN *lenp)
42814279
{
42824280
PERL_ARGS_ASSERT_TURKIC_LC;
4283-
assert(e > p0);
42844281

42854282
/* Returns 0 if the lowercase of the input UTF-8 encoded sequence from
42864283
* p0..e-1 according to Turkic rules is the same as for non-Turkic.
@@ -4326,7 +4323,6 @@ S_turkic_uc(pTHX_ const U8 * const p, const U8 * const e,
43264323
U8 * ustrp, STRLEN *lenp)
43274324
{
43284325
PERL_ARGS_ASSERT_TURKIC_UC;
4329-
assert(e > p);
43304326

43314327
/* Returns 0 if the upper or title-case of the input UTF-8 encoded sequence
43324328
* from p0..e-1 according to Turkic rules is the same as for non-Turkic.

util.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,6 @@ Perl_delimcpy_no_escape(char *to, const char *to_end,
619619
ptrdiff_t to_len = to_end - to;
620620
SSize_t copy_len;
621621

622-
assert(from_len >= 0);
623-
assert(to_len >= 0);
624-
625622
/* Look for the first delimiter in the source */
626623
delim_pos = (const char *) memchr(from, delim, from_len);
627624

@@ -718,8 +715,6 @@ Perl_delimcpy(char *to, const char *to_end,
718715
const int delim, I32 *retlen)
719716
{
720717
PERL_ARGS_ASSERT_DELIMCPY;
721-
assert(from_end >= from);
722-
assert(to_end >= to);
723718

724719
const char * const orig_to = to;
725720
ptrdiff_t copy_len = 0;
@@ -1100,7 +1095,6 @@ char *
11001095
Perl_fbm_instr(pTHX_ unsigned char *big, unsigned char *bigend, SV *littlestr, U32 flags)
11011096
{
11021097
PERL_ARGS_ASSERT_FBM_INSTR;
1103-
assert(bigend >= big);
11041098

11051099
unsigned char *s;
11061100
STRLEN l;

0 commit comments

Comments
 (0)