Re: NNTPC: should strnStackAdd null terminate data?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hi:
> 	Firstly you guys should note that it's midnight down
> here so anything I say may be insane:)
> 
> 	It seems that CMDarticle assumes that art_stack->data
> is null terminated while strnStackAdd doesn't seem to do that.
> The appended patch fixes this though I'm suspicious of it as
> it never affected me till tonight :(
> 
> 	Julian, could you clarify the semantics of strnStackAdd?
> Thanks.
> --- nntpcache-current.orig/libproff/str.c	Sun Sep 15 20:38:41 1996
> +++ nntpcache-current/libproff/str.c	Sat Oct  5 00:03:21 1996
> @@ -319,7 +319,7 @@
>  		l->len += STRSTACK_BLOCK_SIZE;
>  		l->data = Srealloc (l->data, l->len);
>  	}
> -	memcpy (l->data + l->used - 1, s, len);
> +	memcpy (l->data + l->used - 1, s, len + 1);
>  	l->used += len;
>  	return l;
>  }
> 

You're doing great ;)

strstack->data should be null terminated, however, strnStackAdd should
not presume that what it is being fed is null terminated.

@@ -262,10 +288,9 @@
        if (!l)
        {
                l = Smalloc (sizeof *l);
-               l->used = 1;
+               l->used = 1; /* the nil */
                l->len = STRSTACK_BLOCK_SIZE;
-               l->data = Smalloc (STRSTACK_BLOCK_SIZE);
-               *l->data = '\0';
+               l->data = Smalloc (l->len);
        }
        len = strlen (s);
        if (l->used + len > l->len)
@@ -273,7 +298,7 @@
                l->len += STRSTACK_BLOCK_SIZE;
                l->data = Srealloc (l->data, l->len);
        }
-       memcpy (l->data + l->used - 1, s, len);
+       memcpy (l->data + l->used - 1, s, len+1);
        l->used += len;
        return l;
 }
@@ -283,10 +308,9 @@
        if (!l)
        {
                l = Smalloc (sizeof *l);
-               l->used = 1;
+               l->used = 1; /* the nil */
                l->len = STRSTACK_BLOCK_SIZE;
-               l->data = Smalloc (STRSTACK_BLOCK_SIZE);
-               *l->data = '\0';
+               l->data = Smalloc (l->len);
        }
        if (l->used + len > l->len)
        {
@@ -295,6 +319,7 @@
        }
        memcpy (l->data + l->used - 1, s, len);
        l->used += len;
+       l->data[l->used-1] = '\0';
        return l;
 }

-- 
"Of all tyrannies a tyranny sincerely  exercised for the good of its victims  
 may be the most  oppressive.  It may be better to live under  robber barons  
 than  under  omnipotent  moral busybodies,  The robber baron's  cruelty may  
 sometimes sleep,  his cupidity may at some point be satiated; but those who  
 torment us for own good  will torment us  without end,  for they do so with 
 the approval of their own conscience."    -   C.S. Lewis, _God in the Dock_ 
+---------------------+--------------------+----------------------------------+
|Julian Assange RSO   | PO Box 2031 BARKER | Secret Analytic Guy Union        |
|proff@suburbia.net   | VIC 3122 AUSTRALIA | finger for PGP key hash ID =     |
|proff@gnu.ai.mit.edu | FAX +61-3-98199066 | 0619737CCC143F6DEA73E27378933690 |
+---------------------+--------------------+----------------------------------+


[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux