From bug-octave-request at bevo dot che dot wisc dot edu Tue Mar 27 13:12:49 2001 Subject: missing 0-terminator in libcruft/misc/dostop.c From: "John W. Eaton" To: Paul Kienzle Cc: bug-octave at bevo dot che dot wisc dot edu Date: Tue, 27 Mar 2001 13:12:30 -0600 On 21-Mar-2001, Paul Kienzle wrote: | To: bug-octave at bevo dot che dot wisc dot edu | Cc: pkienzle | Subject: missing 0-terminator in libcruft/misc/dostop.c | | Bug report for Octave 2.1.31 configured for %OCTAVE_CANONICAL_HOST_TYPE% | | Description: | ----------- | | The code in libcruft/misc/dostop.c reads: | | ... | char *tmp = malloc (len + 1); | strncpy (tmp, s, len); | (*current_liboctave_error_handler) ("%s", tmp); | | Since malloc doesn't guarantee that memory will be zero, there may not | be a string terminator on tmp. OK. | which won't cause a problem until you encounter a fortran compiler which | uses uppercase for its symbols instead of lowercase. I also defined the function using F77_FCN. | I don't know any octave sequence to make this occur. It happens | from my own code (a simplistic fortran mex-like interface). The only way XSTOPX should be called is if there is an error in calling some Fortran code. The idea is to jump back up to the prompt, but doing some cleanup along the way, so I don't want STOP called at all. | The dostop function isn't really needed. Instead, you can do everything | by moving xstopx() into f77-fcn.c, and removing dostop.c and xstopx.f. | You already make the assumption elsewhere (e.g., dbleSCHUR) that calling a | fortran routine which expects a character*(*) requires adding the length | of the string to the end of the parameter list. xstopx requires the | converse: a C routine being called by a fortran routine with a value | which is character*(*) OK. | Note that you do not need to copy the string if you provide a format | string which sets the precision on the string to the length of the string. OK, that is a nice trick that I hadn't thought about (probably because the error function didn't originally handle format specifications, but I can't remember for sure now). jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------