Nmap Security Scanner
*Intro
*Ref Guide
*Install Guide
*Download
*Changelog
*Book
*Docs
Security Lists
*Nmap Hackers
*Nmap Dev
*Bugtraq
*Full Disclosure
*Pen Test
*Basics
*More
Security Tools
*Pass crackers
*Sniffers
*Vuln Scanners
*Web scanners
*Wireless
*Exploitation
*Packet crafters
*More
Site News
Site Search:
Exploit World
Advertising
About/Contact
Credits
Sponsors:
edgeos



Bugtraq: Re: strcpy versus strncpy

Re: strcpy versus strncpy

From: Chris L. Mason <cmason_at_WYREX.COM>
Date: Tue, 3 Mar 1998 11:14:16 -0500

On Tue, Mar 03, 1998 at 01:31:24AM +0100, Morten Welinder wrote:
> A recent article on BugTraq suggested that using strcpy should
> almost always be considered a bug. That's not right. It is,
> in fact, the wrong way around: strncpy is almost always a bug.
>

Hi,

What's wrong with using the following (I got the idea from some of
Stevens' code)?

char *sstrcpy(char *dst, size_t n, const char *src) {
    if (strlen(src) > (n - 1)) {
        errno = ENOSPC;
        return NULL;
    }

    strcpy(dst, src);
    dst[n - 1] = '\0';

    return dst;
}

(the first 's' stands for safe (I hope))
It's not MT safe, but other than that I can't see any problems.

Chris
Received on Mar 03 1998

[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]
edgeos