This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
off-by-one in malloc.c (from Ilya Zakharevich)
authorGurusamy Sarathy <gsar@cpan.org>
Fri, 4 Feb 2000 05:05:57 +0000 (05:05 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Fri, 4 Feb 2000 05:05:57 +0000 (05:05 +0000)
p4raw-id: //depot/perl@4974

malloc.c

index 734ea06..5e85661 100644 (file)
--- a/malloc.c
+++ b/malloc.c
@@ -1748,9 +1748,9 @@ char *
 Perl_strdup(const char *s)
 {
     MEM_SIZE l = strlen(s);
-    char *s1 = (char *)Perl_malloc(l);
+    char *s1 = (char *)Perl_malloc(l+1);
 
-    Copy(s, s1, (MEM_SIZE)l, char);
+    Copy(s, s1, (MEM_SIZE)(l+1), char);
     return s1;
 }
 
@@ -1776,8 +1776,8 @@ Perl_putenv(char *a)
   else
       var = Perl_malloc(l + 1);
   Copy(a, var, l, char);
-  val++;
-  my_setenv(var,val);
+  var[l + 1] = 0;
+  my_setenv(var, val+1);
   if (var != buf)
       Perl_mfree(var);
   return 0;