Re: Coverity warning: strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);

2010-05-02 Thread Matthias Andree
Alfred Perlstein schrieb:
> I notice this code sprinkled through the sources:
>   strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
> 
> This trips up coverity because it does not know for sure
> that the string returned by cam_sim_name() is going to 
> be DEV_IDLEN-1 characters long.

Right. strncpy/strncat are examples for features that the C standards
libc had better not ever had, similar to [f]gets...

> Should we switch these calls to strlcpy?  Is there a smarter
> thing to do to code more defensively?

if dev_name is a vector of char or equally sized types:
(cpi->dev_name)[DEV_IDLEN-1] = '\0';

However, rather than relying on implicit assumptions and inefficiencies,
I'd still prefer memset + strlcpy.

-- 
Matthias Andree
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Re: Coverity warning: strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);

2010-05-01 Thread Matthew Jacob

On 5/1/2010 3:35 PM, Alfred Perlstein wrote:

I notice this code sprinkled through the sources:
   strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);

This trips up coverity because it does not know for sure
that the string returned by cam_sim_name() is going to
be DEV_IDLEN-1 characters long.

Should we switch these calls to strlcpy?  Is there a smarter
thing to do to code more defensively?

   


strlcpy seems right.

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"


Coverity warning: strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);

2010-05-01 Thread Alfred Perlstein
I notice this code sprinkled through the sources:
  strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);

This trips up coverity because it does not know for sure
that the string returned by cam_sim_name() is going to 
be DEV_IDLEN-1 characters long.

Should we switch these calls to strlcpy?  Is there a smarter
thing to do to code more defensively?

thank you,
-- 
- Alfred Perlstein
.- AMA, VMOA #5191, 03 vmax, 92 gs500, 85 ch250, 07 zx10
.- FreeBSD committer
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"