[Rd] Segfault in foreign:read.xport (PR#1192)

gregory_r_warnes@groton.pfizer.com gregory_r_warnes@groton.pfizer.com
Mon, 3 Dec 2001 20:34:47 +0100 (MET)


I get a segfault when trying to read a SAS transport file with rather long
rows using read.xport from package foreign (version 0.4-7).  The culprit
seems to be these lines in xport_read in SASxport.c:

590                         } else {
591                             c = strchr(tmpchar, ' ');
592                             *c = '\0';
593                             SET_STRING_ELT(VECTOR_ELT(data, k), j,
594                                            (c == tmpchar) ?
R_BlankString :
595                                            mkChar(tmpchar));
596                         }

(gdb) print tmpchar
$1 = 0xb63674 "0502"
(gdb) print c
$2 = 0x0

According to the solaris man pages, strchr returns NULL if there is no
match.  Changing lines 591 and 592 to add an appropriate test for null seems
to fix the problem:

590                         } else {
591                             if( c = strchr(tmpchar, ' ') )
592                                 *c = '\0';
593                             SET_STRING_ELT(VECTOR_ELT(data, k), j,
594                                            (c == tmpchar) ?
R_BlankString :
595                                            mkChar(tmpchar));
596                         }

I haven't looked closely at the code, so this may not be the correct
solution.

Patch and version information below.

-Greg


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

> R.version
         _                   
platform sparc-sun-solaris2.8
arch     sparc               
os       solaris2.8          
system   sparc, solaris2.8   
status                       
major    1                   
minor    3.1                 
year     2001                
month    08                  
day      31                  
language R                   


-----------

-------------Patch Starts Here----------------
diff -r foreign.orig//src/SASxport.c foreign/src/SASxport.c
591,595c591,598
< 			c = strchr(tmpchar, ' ');
< 			*c = '\0';
< 			SET_STRING_ELT(VECTOR_ELT(data, k), j,
< 				       (c == tmpchar) ? R_BlankString :
< 				       mkChar(tmpchar));
---
> 		      if( c = strchr(tmpchar, ' ') )
>                           {
> 			    *c = '\0';
> 			  }
> 
> 		      SET_STRING_ELT(VECTOR_ELT(data, k), j,
> 				     (c == tmpchar) ? R_BlankString :
> 				     mkChar(tmpchar));
------------Patch Ends Here--------------------


LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._