2318 Commits

Author SHA1 Message Date
Martin v. Löwis
9b8de84a89 Backported r55839 and r61350
Issue #4469: Prevent expandtabs() on string and unicode
objects from causing a segfault when a large width is passed
on 32-bit platforms.
2008-12-13 13:20:46 +00:00
Benjamin Peterson
38ce9c294b backport the security fix part of r67246 2008-11-17 23:27:02 +00:00
Matthias Klose
b7cfda1324 - Issue #2587: In the C API, PyString_FromStringAndSize() takes a signed size
parameter but was not verifying that it was greater than zero.  Values
  less than zero will now raise a SystemError and return NULL to indicate a
  bug in the calling C code. CVE-2008-1887.

  backport r62261, r62271
2008-11-12 07:21:52 +00:00
Neal Norwitz
b93d7d52b5 Security patches from Apple: prevent int overflow when allocating memory 2008-07-31 17:04:32 +00:00
Neal Norwitz
46b3a79459 Backport r65182. This change modified from using the unsigned max value
to the signed max value similar to 2.5 and trunk.

Issue #2620: Overflow checking when allocating or reallocating memory
was not always being done properly in some python types and extension
modules.  PyMem_MALLOC, PyMem_REALLOC, PyMem_NEW and PyMem_RESIZE have
all been updated to perform better checks and places in the code that
would previously leak memory on the error path when such an allocation
failed have been fixed.
2008-07-28 05:22:45 +00:00
Martin v. Löwis
c8ed4ff565 Backport of r60793:
Added checks for integer overflows, contributed by Google. Some are
only available if asserts are left in the code, in cases where they
can't be triggered from Python code.
2008-03-02 19:20:32 +00:00
Thomas Wouters
1e42ab6e43 Backport trunk revision 53527:
SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize

When running the interpreter in an environment that would cause it to set
stdout/stderr/stdin's encoding, having a sitecustomize that would replace
them with something other than PyFile objects would crash the interpreter.
Fix it by simply ignoring the encoding-setting for non-files.

This could do with a test, but I can think of no maintainable and portable
way to test this bug, short of adding a sitecustomize.py to the buildsystem
and have it always run with it (hmmm....)
2007-01-23 15:09:19 +00:00
Tim Peters
0af9b87953 Backport rev 51262 from trunk -- squashes a compiler warning on Windows
about truly wrong code.

Checkin comment from 51262:

Can't return NULL from a void function.  If there is a memory error,
about the best we can do is call PyErr_WriteUnraisable and go on.
We won't be able to do the call below either, so verify delstr is valid.
2006-10-09 23:37:58 +00:00
Tim Peters
2b37ea4087 Backport of the pieces of trunk rev 46589 relevant to
fixing an unlikely crash bug in dict resizing, SF
bug 1456209.

The rest of rev 46589 changes whether Python suppresses
exceptions during some dict-related comparisons.  While I
think that's a good idea, it does change visible behavior at
times, and there was already some complaining about that on
the trunk.  Not a good idea for backporting.  The part of
46589 checked in here can at worst stop segfaults, and I doubt
anyone will gripe about that ;-)
2006-10-09 20:24:45 +00:00
Andrew M. Kuchling
2fafa251db [Partial backport of r45947 | neal.norwitz]
Fix problems found by Coverity.

longobject.c: also fix an ssize_t problem
  <a> could have been NULL, so hoist the size calc to not use <a>.

[The ssize_t change isn't needed for 2.4.  The other changes in this revision
 are to modules not present in 2.4. --amk]
2006-10-09 18:42:49 +00:00
Andrew M. Kuchling
e0235ae1a9 [Backport r42951 | guido.van.rossum]
Fix three nits found by Coverity, adding null checks and comments.

[This commit only makes two changes.  One change in the original patch
 is just adding a comment, and another adds a 'base != NULL' check to
 silence Coverity, but a comment adds that that base is never going to
 be NULL.  I didn't backport that change. --amk]
2006-10-09 18:19:01 +00:00
Andrew M. Kuchling
78754c13ce [Backport r43695 | neal.norwitz]
Remove dead code (reported by HP compiler).

Can probably be backported if anyone cares.
2006-10-06 19:26:14 +00:00
Andrew M. Kuchling
3e3566937e [Backport r50679 | neal.norwitz. This is the last Klocwork bug to be
backported.]

Use sizeof(buffer) instead of duplicating the constants to ensure they won't
be wrong.

The real change is to pass (bufsz - 1) to PyOS_ascii_formatd and 1
to strncat.  strncat copies n+1 bytes from src (not dest).

Reported by Klocwork #58.
2006-10-05 19:42:49 +00:00
Andrew M. Kuchling
32f378b0d9 [Backport r50681 | neal.norwitz]
PyFunction_SetDefaults() is documented as taking None or a tuple.
A NULL would crash the PyTuple_Check().  Now make NULL return a SystemError.

Reported by Klocwork #73.
2006-10-05 19:38:17 +00:00
Andrew M. Kuchling
6d0bc3e9f4 [Backport r51246 | neal.norwitz]
Handle a whole lot of failures from PyString_FromInternedString().

Should fix most of Klocwork 234-272.

[Backport r51400 | neal.norwitz]

Move initialization of interned strings to before allocating the
object so we don't leak op.  (Fixes an earlier patch to this code)

Klockwork #350
2006-10-05 19:25:26 +00:00
Andrew M. Kuchling
978809518d [Partial backport of r51218 | neal.norwitz -- the changes to ast.c, symtable.c,
and _elementtree.c weren't applicable]

Klocwork made another run and found a bunch more problems.
This is the first batch of fixes that should be easy to verify based on context.
This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
2006-10-05 18:37:08 +00:00
Andrew M. Kuchling
8a28c16430 [Backport r50743 | neal.norwitz]
Handle allocation failures gracefully.  Found with failmalloc.
Many (all?) of these could be backported.
2006-10-05 18:08:58 +00:00
Andrew M. Kuchling
1af9f68b4a [Backport r51248 | neal.norwitz]
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.

Klocwork 308
2006-10-05 17:18:13 +00:00
Armin Rigo
b2d0f34240 A review of overflow-detecting code in the 2.4 branch.
* unified the way intobject, longobject and mystrtoul handle
  values around -sys.maxint-1.

* in general, trying to entierely avoid overflows in any computation
  involving signed ints or longs is extremely involved.  Fixed a few
  simple cases where a compiler might be too clever (but that's all
  guesswork).

* more overflow checks against bad data in marshal.c.
2006-10-04 10:13:32 +00:00
Martin v. Löwis
98041d7bf0 Fix integer negation and absolute value to not rely
on undefined behaviour of the C compiler anymore.
2006-10-04 05:48:05 +00:00
Andrew M. Kuchling
59e0e1e395 [Backport r51230 | neal.norwitz]
Check return of PyMem_MALLOC (garbage) is non-NULL.
Check seq in both portions of if/else.

Klocwork #289-290.
2006-10-03 19:07:06 +00:00
Andrew M. Kuchling
b1d7043290 [Backport r50779 | neal.norwitz]
Move the initialization of size_a down below the check for a being NULL.

Reported by Klocwork #106.

[Slight change required: in 2.5 Py_ssize_t is used, but 2.4 uses int.]
2006-10-03 18:52:07 +00:00
Andrew M. Kuchling
5cf2fb9904 [Backport r50683 | neal.norwitz]
Stop INCREFing name, then checking if it's NULL.  name (f_name) should never
be NULL so assert it.  Fix one place where we could have passed NULL.

Reported by Klocwork #66.
2006-10-03 18:43:28 +00:00
Andrew M. Kuchling
91697928ca [Backport r50680 | neal.norwitz]
Handle a NULL name properly.
2006-10-03 18:40:23 +00:00
Andrew M. Kuchling
c6994f2502 [Backport rev. 42545 by georg.brandl]
Make staticmethod and classmethod complain about keyword args.
2006-10-03 18:25:19 +00:00