[quagga-dev 4405] Re: Segfault in lib/smux.c

Andrew J. Schorr aschorr at telemetry-investments.com
Tue Sep 26 14:43:32 BST 2006


On Tue, Sep 26, 2006 at 03:28:10PM +0200, Pierre-Yves Ritschard wrote:
> I wondered about that too, I thought it would be best, but since sizeof
> (int) was used before I thought it was a style decision, Here's a reworked
> patch.

Thanks, I think it's better this way.

> --- lib/smux.c.orig	Tue Sep 26 15:36:33 2006
> +++ lib/smux.c	Tue Sep 26 15:37:16 2006
> @@ -1032,19 +1032,19 @@
>    val = SNMP_TRAP_ENTERPRISESPECIFIC;
>    ptr = asn_build_int (ptr, &len, 
>  		       (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
> -		       &val, sizeof (int));
> +		       &val, sizeof (val));
>  
>    /* Specific trap integer. */
>    val = sptrap;
>    ptr = asn_build_int (ptr, &len, 
>  		       (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER),
> -		       &val, sizeof (int));
> +		       &val, sizeof (val));
>  
>    /* Timeticks timestamp. */
>    val = 0;
>    ptr = asn_build_unsigned_int (ptr, &len, 
>  				(u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_TIMETICKS),
> -				&val, sizeof (int));
> +				&val, sizeof (val));
>    
>    /* Variables. */
>    h1 = ptr;

For extra points, you could fix all the other instances in the file.  I
think there are a few more that have sizeof(<type>) instead of
sizeof(<variable passed as argument>).  Hard-wiring the type in 2 places
is a dangerous practice, in my opinion...

Regards,
Andy



More information about the Quagga-dev mailing list