Re: safe strcpy()?
From: Ben Pfaff (blp@cs.stanford.edu)
Date: 01/30/03
- Previous message: Dave Aitel: "Re: safe strcpy()?"
- In reply to: Michael Howard: "RE: safe strcpy()?"
- Next in thread: Ed Carp: "Re: safe strcpy()?"
- Reply: Ed Carp: "Re: safe strcpy()?"
- Reply: Timo Sirainen: "Re: safe strcpy()?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
To: <secprog@securityfocus.com> From: Ben Pfaff <blp@cs.stanford.edu> Date: 29 Jan 2003 15:40:16 -0800
"Michael Howard" <mikehow@microsoft.com> writes:
> The point I'm making is people seem to think they can write crap code,
> then bindly replace the calls to strcpy with strncpy and all of a sudden
> their code is safe. [...]
The usual reason cited not to use strncpy() is that it doesn't
necessarily null-terminate its output buffer. But there's at
least one other reason: using strncpy() into a large buffer can
be very inefficient. strncpy() always writes to every byte in
the destination buffer, which can waste a lot of time if the
destination buffer is much longer than the source string.
As a result, strncpy() is hardly ever the right function to use.
strlcpy() from OpenBSD is usually a better choice.
-- "If a person keeps faithfully busy each hour of the working day, he can count on waking up some morning to find himself one of the competent ones of his generation." --William James
- Next message: Ed Carp: "Re: safe strcpy()?"
- Previous message: Dave Aitel: "Re: safe strcpy()?"
- In reply to: Michael Howard: "RE: safe strcpy()?"
- Next in thread: Ed Carp: "Re: safe strcpy()?"
- Reply: Ed Carp: "Re: safe strcpy()?"
- Reply: Timo Sirainen: "Re: safe strcpy()?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|