~ubuntu-branches/ubuntu/saucy/python2.7/saucy-proposed

« back to all changes in this revision

Viewing changes to Modules/_sre.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-05-15 19:15:16 UTC
  • mto: (36.1.23 sid)
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: package-import@ubuntu.com-20130515191516-zmv6to904wemey7s
Tags: upstream-2.7.5
ImportĀ upstreamĀ versionĀ 2.7.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
686
686
    alloc_pos = state->data_stack_base; \
687
687
    TRACE(("allocating %s in %d (%d)\n", \
688
688
           SFY(type), alloc_pos, sizeof(type))); \
689
 
    if (state->data_stack_size < alloc_pos+sizeof(type)) { \
 
689
    if (sizeof(type) > state->data_stack_size - alloc_pos) { \
690
690
        int j = data_stack_grow(state, sizeof(type)); \
691
691
        if (j < 0) return j; \
692
692
        if (ctx_pos != -1) \
706
706
do { \
707
707
    TRACE(("copy data in %p to %d (%d)\n", \
708
708
           data, state->data_stack_base, size)); \
709
 
    if (state->data_stack_size < state->data_stack_base+size) { \
 
709
    if (size > state->data_stack_size - state->data_stack_base) { \
710
710
        int j = data_stack_grow(state, size); \
711
711
        if (j < 0) return j; \
712
712
        if (ctx_pos != -1) \
1028
1028
            TRACE(("|%p|%p|REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr,
1029
1029
                   ctx->pattern[1], ctx->pattern[2]));
1030
1030
 
1031
 
            if (ctx->ptr + ctx->pattern[1] > end)
 
1031
            if (ctx->pattern[1] > end - ctx->ptr)
1032
1032
                RETURN_FAILURE; /* cannot match */
1033
1033
 
1034
1034
            state->ptr = ctx->ptr;
1111
1111
            TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr,
1112
1112
                   ctx->pattern[1], ctx->pattern[2]));
1113
1113
 
1114
 
            if (ctx->ptr + ctx->pattern[1] > end)
 
1114
            if (ctx->pattern[1] > end - ctx->ptr)
1115
1115
                RETURN_FAILURE; /* cannot match */
1116
1116
 
1117
1117
            state->ptr = ctx->ptr;
2784
2784
        skip = *code;                                   \
2785
2785
        VTRACE(("%lu (skip to %p)\n",                   \
2786
2786
               (unsigned long)skip, code+skip));        \
2787
 
        if (code+skip-adj < code || code+skip-adj > end)\
 
2787
        if (skip-adj > end-code)                        \
2788
2788
            FAIL;                                       \
2789
2789
        code++;                                         \
2790
2790
    } while (0)
2817
2817
 
2818
2818
        case SRE_OP_CHARSET:
2819
2819
            offset = 32/sizeof(SRE_CODE); /* 32-byte bitmap */
2820
 
            if (code+offset < code || code+offset > end)
 
2820
            if (offset > end-code)
2821
2821
                FAIL;
2822
2822
            code += offset;
2823
2823
            break;
2825
2825
        case SRE_OP_BIGCHARSET:
2826
2826
            GET_ARG; /* Number of blocks */
2827
2827
            offset = 256/sizeof(SRE_CODE); /* 256-byte table */
2828
 
            if (code+offset < code || code+offset > end)
 
2828
            if (offset > end-code)
2829
2829
                FAIL;
2830
2830
            /* Make sure that each byte points to a valid block */
2831
2831
            for (i = 0; i < 256; i++) {
2834
2834
            }
2835
2835
            code += offset;
2836
2836
            offset = arg * 32/sizeof(SRE_CODE); /* 32-byte bitmap times arg */
2837
 
            if (code+offset < code || code+offset > end)
 
2837
            if (offset > end-code)
2838
2838
                FAIL;
2839
2839
            code += offset;
2840
2840
            break;
2985
2985
                    GET_ARG; prefix_len = arg;
2986
2986
                    GET_ARG; /* prefix skip */
2987
2987
                    /* Here comes the prefix string */
2988
 
                    if (code+prefix_len < code || code+prefix_len > newcode)
 
2988
                    if (prefix_len > newcode-code)
2989
2989
                        FAIL;
2990
2990
                    code += prefix_len;
2991
2991
                    /* And here comes the overlap table */
2992
 
                    if (code+prefix_len < code || code+prefix_len > newcode)
 
2992
                    if (prefix_len > newcode-code)
2993
2993
                        FAIL;
2994
2994
                    /* Each overlap value should be < prefix_len */
2995
2995
                    for (i = 0; i < prefix_len; i++) {
3118
3118
               to allow arbitrary jumps anywhere in the code; so we just look
3119
3119
               for a JUMP opcode preceding our skip target.
3120
3120
            */
3121
 
            if (skip >= 3 && code+skip-3 >= code &&
 
3121
            if (skip >= 3 && skip-3 < end-code &&
3122
3122
                code[skip-3] == SRE_OP_JUMP)
3123
3123
            {
3124
3124
                VTRACE(("both then and else parts present\n"));