[Patches] [ python-Patches-714348 ] Guard against segfaults in debug code

SourceForge.net noreply@sourceforge.net
Mon, 07 Apr 2003 14:44:45 -0700


Patches item #714348, was opened at 2003-04-02 22:14
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=714348&group_id=5470

Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Mark Hammond (mhammond)
>Assigned to: Mark Hammond (mhammond)
Summary: Guard against segfaults in debug code

Initial Comment:
When dumping invalid objects, we may as well avoid
segfaults if possible.  This allows us to extract as
much information as possible before dieing, which may
be handy in release builds etc.

Trivial patch just to get started (as I actually hit
this block!).  Assign back if you are OK with it, or I
will be OK with you not wanting to start this slippery
slope.

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2003-04-07 17:44

Message:
Logged In: YES 
user_id=31435

Do you think this helps?  I'm OK with it either way.  Normally, 
this routine doesn't exist in a release build, and in the debug 
build if we didn't segfault we'd end up calling Py_FatalError() 
after it returned.

BTW. since we're on Windows, would it be simpler to call the 
Win32 IsBadReadPtr()?

----------------------------------------------------------------------

Comment By: Mark Hammond (mhammond)
Date: 2003-04-02 22:16

Message:
Logged In: YES 
user_id=14198

Attaching patch.  It indents a couple of blocks, so FYI, a
--ignore-all-space diff is:

RCS file: /cvsroot/python/python/dist/src/Objects/obmalloc.c,v
retrieving revision 2.50
diff -w -r2.50 obmalloc.c
1126a1127
>       int tail_reachable = 0; /* can we dereference tail
without segfault */
1163a1165,1175
> #ifdef MS_WINDOWS
>       _try {
> #endif /* MS_WINDOWS */
>       tail_reachable = *tail ? 1 : 1; /* if we don't die,
it is reachable! */
> #ifdef MS_WINDOWS
>       } _except(1) {
>               /* tail_reachable remains 0 */
>       }
> #endif /* MS_WINDOWS */
>
>       if (tail_reachable) {
1185a1198,1200
>       } else {
>               fprintf(stderr, "INVALID\n");
>       }
1197c1212
<               if (q < tail) {
---
>               if (q < tail && tail_reachable) {

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=714348&group_id=5470