.\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek and the American National Standards Committee X3, .\" on Information Processing Systems. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93 .\" $NetBSD: strcpy.3,v 1.23.26.1 2024/09/20 11:22:29 martin Exp $ .\" .Dd August 11, 2023 .Dt STRCPY 3 .Os .Sh NAME .Nm stpcpy , .Nm strcpy .Nd copy strings .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In string.h .Ft char * .Fn stpcpy "char * restrict dst" "const char * restrict src" .Ft char * .Fn strcpy "char * restrict dst" "const char * restrict src" .Sh DESCRIPTION The .Fn stpcpy and .Fn strcpy functions copy the string .Fa src to .Fa dst , including the terminating .Tn NUL byte. .Pp The strings .Fa src and .Fa dst may not overlap. The string .Fa src must be terminated by a .Tn NUL byte. The memory for .Fa dst must have space for .Fn strlen src Li "+ 1" bytes. .Sh RETURN VALUES The .Fn strcpy function returns .Fa dst . .Pp The .Fn stpcpy function returns a pointer to the terminating .Tn NUL byte of .Fa dst . .Sh SEE ALSO .Xr bcopy 3 , .Xr memccpy 3 , .Xr memcpy 3 , .Xr memmove 3 , .Xr strlcpy 3 , .Xr strncpy 3 , .Xr wcscpy 3 .Sh STANDARDS The .Fn strcpy function conforms to .St -isoC-99 . .Pp The .Fn stpcpy function conforms to .St -p1003.1-2008 . .Sh HISTORY The .Fn stpcpy function first appeared in .Nx 6.0 . .Sh SECURITY CONSIDERATIONS The .Fn strcpy and .Fn stpcpy functions copy until a .Tn NUL terminator without any bounds checks on the size of the input or output buffers. If the input buffer is missing a .Tn NUL terminator, or the input string is longer than the output buffer, this can lead to crashes or security vulnerabilities from buffer overruns, including disclosure of secrets in memory and arbitrary code execution. .Pp The .Xr strlcpy 3 function is a safer replacement for .Fn strcpy which allows the caller to specify the space allocated for .Fa dst . .Xr strlcpy 3 , or .Xr snprintf 3 with a format string of .Li \*q%s\*q , should be used instead of .Fn strcpy and .Fn stpcpy wherever possible to avoid buffer overruns in .Fa dst . .Po However, they still require .Fa src to be .Tn NUL Ns -terminated . .Pc