Staging
v0.5.1
https://github.com/python/cpython
Revision bfa4fe4f39dd8b5ce1a0b649cedd36857859081a authored by Nir Soffer on 10 July 2017, 21:06:57 UTC, committed by Berker Peksag on 10 July 2017, 21:06:57 UTC
If history-length is set in .inputrc, and the history file is double the
history size (or more), history_get(N) returns NULL, and python
segfaults. Fix that by checking for NULL return value.

It seems that the root cause is incorrect handling of bigger history in
readline, but Python should not segfault even if readline returns
unexpected value.

This issue affects only GNU readline. When using libedit emulation
system history size option does not work.

This is a backport of the actual fix from master without the test, since
the test depends on new run_pty() helper which is not available in 2.7.
1 parent 5d1554a
Raw File
Tip revision: bfa4fe4f39dd8b5ce1a0b649cedd36857859081a authored by Nir Soffer on 10 July 2017, 21:06:57 UTC
[2.7] bpo-29854: Fix segfault in call_readline() (GH-728)
Tip revision: bfa4fe4
bitset.c

/* Bitset primitives used by the parser generator */

#include "pgenheaders.h"
#include "bitset.h"

bitset
newbitset(int nbits)
{
    int nbytes = NBYTES(nbits);
    bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) *  nbytes);

    if (ss == NULL)
        Py_FatalError("no mem for bitset");

    ss += nbytes;
    while (--nbytes >= 0)
        *--ss = 0;
    return ss;
}

void
delbitset(bitset ss)
{
    PyObject_FREE(ss);
}

int
addbit(bitset ss, int ibit)
{
    int ibyte = BIT2BYTE(ibit);
    BYTE mask = BIT2MASK(ibit);

    if (ss[ibyte] & mask)
        return 0; /* Bit already set */
    ss[ibyte] |= mask;
    return 1;
}

#if 0 /* Now a macro */
int
testbit(bitset ss, int ibit)
{
    return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
}
#endif

int
samebitset(bitset ss1, bitset ss2, int nbits)
{
    int i;

    for (i = NBYTES(nbits); --i >= 0; )
        if (*ss1++ != *ss2++)
            return 0;
    return 1;
}

void
mergebitset(bitset ss1, bitset ss2, int nbits)
{
    int i;

    for (i = NBYTES(nbits); --i >= 0; )
        *ss1++ |= *ss2++;
}
back to top