Group :: Sistema/Base
RPM: glibc
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: glibc-2.3.5-obsd-alt-strlcpy-strlcat.patch
Download
Download
# Import strlcpy/strlcat from OpenBSD.
diff -uprk.orig glibc-2.3.5.orig/string/Makefile glibc-2.3.5/string/Makefile
--- glibc-2.3.5.orig/string/Makefile 2004-10-18 04:17:12 +0000
+++ glibc-2.3.5/string/Makefile 2005-05-08 22:25:39 +0000
@@ -40,7 +40,7 @@ routines := strcat strchr strcmp strcoll
addsep replace) \
envz basename \
strcoll_l strxfrm_l string-inlines memrchr \
- xpg-strerror
+ xpg-strerror strlcat strlcpy
# Gcc internally generates calls to unbounded memcpy and memset
# for -fbounded-pointer compiles. Glibc uses memchr for explicit checks.
diff -uprk.orig glibc-2.3.5.orig/string/Versions glibc-2.3.5/string/Versions
--- glibc-2.3.5.orig/string/Versions 2004-03-22 19:48:21 +0000
+++ glibc-2.3.5/string/Versions 2004-04-22 11:43:46 +0000
@@ -77,4 +77,8 @@ libc {
# x*
__xpg_strerror_r;
}
+ GLIBC_2.2.5 {
+ # imported from OpenBSD.
+ strlcat; strlcpy;
+ }
}
diff -uprk.orig glibc-2.3.5.orig/string/string.h glibc-2.3.5/string/string.h
--- glibc-2.3.5.orig/string/string.h 2004-10-18 04:17:12 +0000
+++ glibc-2.3.5/string/string.h 2005-05-08 22:29:02 +0000
@@ -348,6 +348,24 @@ extern int strncasecmp_l (__const char *
extern char *strsep (char **__restrict __stringp,
__const char *__restrict __delim)
__THROW __nonnull ((1, 2));
+
+/*
+ * Appends __src to string __dst of size __n (unlike strncat, __n is the
+ * full size of __dst, not space left). At most __n-1 characters
+ * will be copied. Always NUL terminates (unless __n <= strlen(__dst)).
+ * Returns strlen(__src) + MIN(__n, strlen(initial __dst)).
+ * If retval >= __n, truncation occurred.
+ */
+extern size_t strlcat (char *__dst, __const char *__src, size_t __n)
+ __THROW __nonnull ((1, 2));
+
+/*
+ * Copy __src to string __dst of size __n. At most __n-1 characters
+ * will be copied. Always NUL terminates (unless __n == 0).
+ * Returns strlen(__src); if retval >= __n, truncation occurred.
+ */
+extern size_t strlcpy (char *__dst, __const char *__src, size_t __n)
+ __THROW __nonnull ((1, 2));
#endif
#ifdef __USE_GNU
diff -uprk.orig glibc-2.3.5.orig/string/strlcat.c glibc-2.3.5/string/strlcat.c
--- glibc-2.3.5.orig/string/strlcat.c 1970-01-01 00:00:00 +0000
+++ glibc-2.3.5/string/strlcat.c 2003-11-01 07:13:34 +0000
@@ -0,0 +1,59 @@
+/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <string.h>
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+size_t
+strlcat(char *dst, const char *src, size_t siz)
+{
+ register char *d = dst;
+ register const char *s = src;
+ register size_t n = siz;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return(dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
+ }
+ *d = '\0';
+
+ return(dlen + (s - src)); /* count does not include NUL */
+}
diff -uprk.orig glibc-2.3.5.orig/string/strlcpy.c glibc-2.3.5/string/strlcpy.c
--- glibc-2.3.5.orig/string/strlcpy.c 1970-01-01 00:00:00 +0000
+++ glibc-2.3.5/string/strlcpy.c 2003-11-01 07:13:38 +0000
@@ -0,0 +1,55 @@
+/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <string.h>
+
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+size_t
+strlcpy(char *dst, const char *src, size_t siz)
+{
+ register char *d = dst;
+ register const char *s = src;
+ register size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0 && --n != 0) {
+ do {
+ if ((*d++ = *s++) == 0)
+ break;
+ } while (--n != 0);
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}