*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> strcat (3)              
Title
Content
Arch
Section
 

STRCAT(3)

Contents


NAME    [Toc]    [Back]

     strcat -- concatenate strings

LIBRARY    [Toc]    [Back]

     Standard C Library (libc, -lc)

SYNOPSIS    [Toc]    [Back]

     #include <string.h>

     char *
     strcat(char * restrict s, const char * restrict append);

     char *
     strncat(char * restrict s, const char * restrict append, size_t count);

DESCRIPTION    [Toc]    [Back]

     The strcat() 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.

     The strncat() function appends not more than count characters from
     append, and then adds a terminating `\0'.

RETURN VALUES    [Toc]    [Back]

     The strcat() and strncat() functions return the pointer s.

SECURITY CONSIDERATIONS    [Toc]    [Back]

     The strcat() function is easily misused in a manner which enables malicious
 users to arbitrarily change a running program's functionality
     through a buffer overflow attack.	(See the FSA.)

     Avoid using strcat().  Instead, use strncat() or strlcat() and ensure
     that no more characters are copied to the destination buffer than it can
     hold.

     Note that strncat() can also be problematic.  It may be a security concern
 for a string to be truncated at all.	Since the truncated string
     will not be as long as the original, it may refer to a completely different
 resource and usage of the truncated resource could result in very
     incorrect behavior.  Example:

     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
     }

SEE ALSO    [Toc]    [Back]

      
      
     bcopy(3), memccpy(3), memcpy(3), memmove(3), strcpy(3), strlcat(3),
     strlcpy(3)

     The FreeBSD Security Architecture.  (See /usr/share/doc/{to be decided}.)

STANDARDS    [Toc]    [Back]

     The strcat() and strncat() functions conform to ISO/IEC 9899:1990
     (``ISO C89'').


FreeBSD 5.2.1			 June 4, 1993			 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
strcat Linux concatenate two strings
wcsncat Linux concatenate two wide-character strings
wcscat Linux concatenate two wide-character strings
cat FreeBSD concatenate and print files
cat IRIX concatenate and print files
cat OpenBSD concatenate and print files
xstr IRIX extract strings from C programs to implement shared strings
xstr OpenBSD extract strings from C programs to implement shared strings
xstr HP-UX extract strings from C programs to implement shared strings
xstr FreeBSD extract strings from C programs to implement shared strings
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service