diff --git a/Makefile.common b/Makefile.common index 1d480af..1f429ce 100644 --- a/Makefile.common +++ b/Makefile.common @@ -11,7 +11,8 @@ LIBTELNET_SRCS = \ libtelnet/read_password.c \ libtelnet/rsaencpwd.c \ libtelnet/sra.c \ - libtelnet/getaddrinfo.c + libtelnet/getaddrinfo.c \ + libtelnet/strlcpy.c # libtelnet/pk.c TELNET_SRCS = \ diff --git a/libtelnet/strlcpy.c b/libtelnet/strlcpy.c new file mode 100644 index 0000000..6b4ed53 --- /dev/null +++ b/libtelnet/strlcpy.c @@ -0,0 +1,54 @@ +/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef __GNO__ + +#include +#include + +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t dsize) +{ + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ +} + +#endif diff --git a/libtelnet/strlcpy.h b/libtelnet/strlcpy.h new file mode 100644 index 0000000..009747d --- /dev/null +++ b/libtelnet/strlcpy.h @@ -0,0 +1,3 @@ +#include + +size_t strlcpy(char *dst, const char *src, size_t dsize); diff --git a/telnet/commands.c b/telnet/commands.c index c37e2e9..c8fe8c1 100644 --- a/telnet/commands.c +++ b/telnet/commands.c @@ -52,7 +52,7 @@ static const char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95"; #include #include #ifdef __GNO__ -#include "libtelnet/getaddrinfo.h" +# include "libtelnet/getaddrinfo.h" #endif #include #include diff --git a/telnet/externs.h b/telnet/externs.h index dd0ce67..a9219c5 100644 --- a/telnet/externs.h +++ b/telnet/externs.h @@ -67,6 +67,9 @@ typedef unsigned char cc_t; #endif #include +#ifdef __GNO__ +# include "libtelnet/strlcpy.h" +#endif #if defined(IPSEC) #include diff --git a/telnetd/defs.h b/telnetd/defs.h index 82145f7..55cbc22 100644 --- a/telnetd/defs.h +++ b/telnetd/defs.h @@ -96,6 +96,9 @@ #else #include #endif +#ifdef __GNO__ +# include "libtelnet/strlcpy.h" +#endif #ifndef USE_TERMIO #include