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

Re: [leafnode-list] Leafnode 2.0b8: XPAT causes segfault



krasel@xxxxxxxxxxxxxxxxxxxxxxxxxxxx (Cornelius Krasel) writes:

> --- leafnode-2.0b8/artutil.c	Wed Jan 10 10:16:06 2001
> +++ leafnode-current/artutil.c	Wed Jun 27 20:29:14 2001
[...]
> @@ -155,17 +166,17 @@
>  	q = strchr( p, ',' );
>  	if ( q )
>  	    *q++ = '\0';
> -	if ( *p && ( isinteresting( p ) || create_all_links ) ) {
> +	if ( *p && (isinteresting(p) || islocalgroup(p) || create_all_links) ) {
>  	    cg = findgroup( p );
>  	    if ( cg && chdirgroup( p, TRUE ) ) {
>  		if (xref)
> -		    cxref = strdup( xref );
> +		    cxref = critstrdup(xref, "storearticle(): Xref");
>  		if (( xrefno = lookup_xref( cxref, cg->name )) != NULL ) {
>  		    strcpy( tmp, xrefno );
>  		    link( outname, tmp );
>  		} else {
>  		    do {
> -			sprintf( tmp, "%ld", ++cg->last );
> +			snprintf( tmp, 10, "%ld", ++cg->last );

cg->last is unsigned long. "%lu" would be appropriate.
The tmp[10] buffer is too small to hold all possible "unsigned long"
values:

,----[ limits.h ]
| /* Maximum value an `unsigned long int' can hold.  (Minimum is 0.)  */
| #  ifdef __alpha__
| #   define ULONG_MAX    18446744073709551615UL
                          ^^^^^^^^^^^^^^^^^^^^
                          12345678901234567890
| #  else
| #   ifdef __STDC__
| #    define ULONG_MAX   4294967295UL
                          ^^^^^^^^^^
                          1234567890
| #   else
| #    define ULONG_MAX   4294967295L
| #   endif
| #  endif
`----

Could configure find out the minimum buffer size needed for printing
ULONG_MAX?

Or estimate like:
#define ULONG_MAXLEN (sizeof(ULONG_MAX)*3+1) /* (3.0==ceil(log10(256.0))) */

[...]
> @@ -323,7 +335,7 @@
>  	    }
>  	    if ( cg ) {
>  		do {
> -		    sprintf(tmp, "%lu", ++cg->last);
> +		    snprintf(tmp, 10, "%lu", ++cg->last);

Same as above, concerning tmp[10].

Stefan


-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list