Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Nov 1998 22:20:43 -0800 (PST)
From:      Archie Cobbs <archie@whistle.com>
To:        dillon@apollo.backplane.com (Matthew Dillon)
Cc:        grog@lemis.com, rnordier@nordier.com, freebsd-current@FreeBSD.ORG
Subject:   Re: snprintf() in the kernel
Message-ID:  <199811210620.WAA25723@bubba.whistle.com>
In-Reply-To: <199811210537.VAA20822@apollo.backplane.com> from Matthew Dillon at "Nov 20, 98 09:37:21 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Matthew Dillon writes:
>     I've gone through your diffs.  I found what I believe to be one genuine
>     bug, but read the notes and stuff below... you may have a problem with
>     some of the strncpy()'s you converted to snprintf's.

Thanks very much! I didn't realize that the kernel strncpy() did
a zero fill.. that makes the analysis more complicated.

> dev/dpt/dpt_control.c
> 
>     This doesn't look right, you forgot to remove the strncpy and replace it
>     with the snprintf, but added the extra sizeof() argument as if you had.
> 
>                                 strncpy(compat_softc.ha_fw_version,
> -                                       dpt->board_data.firmware, 4);
> +                                   dpt->board_data.firmware,
> +                                   sizeof(compat_softc.ha_fw_version));
>                                 compat_softc.ha_ccb = NULL;
>                                 compat_softc.ha_cblist = NULL;

I actually left this one alone (sizeof(compat_softc.ha_fw_version) == 4)
because it was impossible to determine whether this string is supposed
to be nul-terminated or not .. the "ha_fw_version" field is not used
anywhere in the kernel! So I don't know if it needs a nul or not.

> netatm/spans/spans_util.c:
> 
>     I'm not sure about these ntohl() calls.  Some of the defines just 
>     macro the arguments through, others are routines, but historically
>     ntohl() has operated on a 32 bit quantity so we should probably
>     cast to ntohl() results to (long) in the s*printf() calls as well
>     as do the sprintf()->snprintf() conversion.

Agreed.. it could matter on alpha hardware.

> netinet/ip_divert.c:
> 
>     You might have to zero-fill unused space in sin_zero.  I'm not sure.

Hmm.. since Julian invented this hack I guess we can declare
that "it doesn't have to be zero filled" :-)

I'll work on adjusting for the concerns you pointed out.. 

Thanks,
-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811210620.WAA25723>