Date: Thu, 15 Jul 1999 18:24:25 -0600 From: Warner Losh <imp@village.org> To: Mike Smith <mike@smith.net.au> Cc: Tim Vanderhoek <vanderh@ecf.utoronto.ca>, Sheldon Hearn <sheldonh@uunet.co.za>, Garance A Drosihn <drosih@rpi.edu>, Paul Hart <hart@iserver.com>, freebsd-hackers@FreeBSD.ORG Subject: Re: OpenBSD's strlcpy(3) and strlcat(3) Message-ID: <199907160024.SAA01153@harmony.village.org> In-Reply-To: Your message of "Thu, 15 Jul 1999 15:44:51 PDT." <199907152244.PAA01458@dingo.cdrom.com> References: <199907152244.PAA01458@dingo.cdrom.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <199907152244.PAA01458@dingo.cdrom.com> Mike Smith writes: : What's really stupid is that most of the time you're trying to use : these functions to fix code that looks like: : strcpy(buf, str1); : strcat(buf, str2); : strcat(buf, str3); : without overflowing buf. This is dumb! Use asprintf instead: : : asprinf(&buf, "%s%s%s", str1, str2, str3); : : If you can't keep all of the string elements together at once, try: : : asprinf(&buf, "%s%s", str1, str2); : ... : asprintf(&buf2, "%s%s", buf, str3); : free(buf); : : No, it's not fast, but it _is_ robust. That is true for this case, but not always true. I think these APIs have an excellent role to play. Sure, there are other ways to do it, but there are a growing number of systems that have strl* on them (OpenBSD, Linux and Solaris), which is reason enough to improve our portability by using them. The asprintf isn't completely robust becuase you must free() the routine, or face a memory leak. It won't overflow, but it might introduce another bug. The whole point of these APIs was to transition old code to new in a safe manner that isn't prone to potentiall programming errors. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907160024.SAA01153>