From: Gisle Aas Date: Fri, 17 Jul 1998 22:49:32 +0000 (+0200) Subject: sv_gets() did not NUL-terminate SV when reading records X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e670df4e079ef573ed96c8dda3854ce6b6e45588;p=p5sagit%2Fp5-mst-13.2.git sv_gets() did not NUL-terminate SV when reading records Message-ID: p4raw-id: //depot/perl@1564 --- diff --git a/sv.c b/sv.c index 29c45fd..a54c6ba 100644 --- a/sv.c +++ b/sv.c @@ -3239,12 +3239,7 @@ sv_gets(register SV *sv, register PerlIO *fp, I32 append) /* Grab the size of the record we're getting */ recsize = SvIV(SvRV(rs)); (void)SvPOK_only(sv); /* Validate pointer */ - /* Make sure we've got the room to yank in the whole thing */ - if (SvLEN(sv) <= recsize + 3) { - /* No, so make it bigger */ - SvGROW(sv, recsize + 3); - } - buffer = SvPVX(sv); /* Get the location of the final buffer */ + buffer = SvGROW(sv, recsize + 1); /* Go yank in */ #ifdef VMS /* VMS wants read instead of fread, because fread doesn't respect */ @@ -3255,6 +3250,7 @@ sv_gets(register SV *sv, register PerlIO *fp, I32 append) bytesread = PerlIO_read(fp, buffer, recsize); #endif SvCUR_set(sv, bytesread); + buffer[bytesread] = '\0'; return(SvCUR(sv) ? SvPVX(sv) : Nullch); } else if (RsPARA(rs)) {