develooper Front page | perl.perl5.porters | Postings from January 2006

[PATCH] Change 26781/26830 (SvRTRIM should also write a new '\0'at the end) can cause segfaults

Thread Next
From:
Philippe M. Chiasson
Date:
January 26, 2006 13:40
Subject:
[PATCH] Change 26781/26830 (SvRTRIM should also write a new '\0'at the end) can cause segfaults
Message ID:
43D941AF.1060503@ActiveState.com
Change 26781, integrated into 5.8.x as 26830 can cause segfaults if Strerror(errno)
returns null.

This can be easily reproduced with:

$> ./perl  -e'$!=41; print $^E'
Protocol wrong type for socket
$> ./perl -e'$!=-1; print $^E'
Bus error

for any unknown $! value

This patch fixes the problem

--- mg.c.old    Thu Jan 26 13:28:31 2006
+++ mg.c.new    Thu Jan 26 13:30:25 2006
@@ -575,10 +575,12 @@
 #define SvRTRIM(sv) STMT_START { \
     STRLEN len = SvCUR(sv); \
     char * const p = SvPVX(sv); \
-    while (len > 0 && isSPACE(p[len-1])) \
-       --len; \
-    SvCUR_set(sv, len); \
-    p[len] = '\0'; \
+    if (p) { \
+        while (len > 0 && isSPACE(p[len-1])) \
+           --len; \
+        SvCUR_set(sv, len); \
+        p[len] = '\0'; \
+    } \
 } STMT_END

 int

--------------------------------------------------------------------------------
Philippe M. Chiasson                  gozer@ActiveState.com GPG KeyID : 88C3A5A5
http://xrl.us/activegozer       F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About