|
NAMEstrcat , strncat —
concatenate strings
LIBRARYStandard C Library (libc, -lc)SYNOPSIS#include <string.h>
char *
char *
DESCRIPTIONThestrcat () and strncat ()
functions append a copy of the null-terminated string
append to the end of the null-terminated string
s, then add a terminating
‘\0 ’. The string s
must have sufficient space to hold the result. If s and
append overlap, the results are undefined.
The RETURN VALUESThestrcat () and strncat ()
functions return the pointer s.
SEE ALSObcopy(3), memccpy(3), memcpy(3), memmove(3), strcpy(3), strlcat(3), strlcpy(3), wcscat(3)STANDARDSThestrcat () and strncat ()
functions conform to ISO/IEC 9899:1990
(“ISO C90”).
SECURITY CONSIDERATIONSThestrcat () function is easily misused in a manner
which enables malicious users to arbitrarily change a running program's
functionality through a buffer overflow attack.
Avoid using Note that void foo(const char *arbitrary_string) { char onstack[8]; #if defined(BAD) /* * This first strcat is bad behavior. Do not use strcat! */ (void)strcat(onstack, arbitrary_string); /* BAD! */ #elif defined(BETTER) /* * The following two lines demonstrate better use of * strncat(). */ (void)strncat(onstack, arbitrary_string, sizeof(onstack) - strlen(onstack) - 1); #elif defined(BEST) /* * These lines are even more robust due to testing for * truncation. */ if (strlen(arbitrary_string) + 1 > sizeof(onstack) - strlen(onstack)) err(1, "onstack would be truncated"); (void)strncat(onstack, arbitrary_string, sizeof(onstack) - strlen(onstack) - 1); #endif }
Visit the GSP FreeBSD Man Page Interface. |