diff options
-rw-r--r-- | bgpd/bgp_aspath.c | 1 | ||||
-rw-r--r-- | bgpd/bgp_debug.c | 1 | ||||
-rw-r--r-- | bgpd/bgp_route.c | 1 | ||||
-rw-r--r-- | bgpd/bgp_updgrp.c | 1 | ||||
-rw-r--r-- | bgpd/bgp_updgrp_packet.c | 1 | ||||
-rw-r--r-- | bgpd/bgpd.c | 1 | ||||
-rw-r--r-- | bgpd/rfapi/vnc_debug.c | 1 | ||||
-rw-r--r-- | lib/Makefile.am | 8 | ||||
-rw-r--r-- | lib/if.c | 1 | ||||
-rw-r--r-- | lib/nexthop.c | 1 | ||||
-rw-r--r-- | lib/sockunion.c | 1 | ||||
-rw-r--r-- | lib/str.c | 95 | ||||
-rw-r--r-- | lib/str.h | 17 | ||||
-rw-r--r-- | lib/strlcat.c | 71 | ||||
-rw-r--r-- | lib/strlcpy.c | 56 | ||||
-rw-r--r-- | lib/vty.c | 1 | ||||
-rw-r--r-- | lib/zebra.h | 7 | ||||
-rw-r--r-- | zebra/kernel_socket.c | 1 | ||||
-rw-r--r-- | zebra/rt_socket.c | 1 | ||||
-rw-r--r-- | zebra/zebra_mpls.c | 1 | ||||
-rw-r--r-- | zebra/zebra_rib.c | 1 | ||||
-rw-r--r-- | zebra/zebra_rnh.c | 1 |
22 files changed, 138 insertions, 132 deletions
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index bf1e92b26..89a529d73 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -25,7 +25,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "memory.h" #include "vector.h" #include "vty.h" -#include "str.h" #include "log.h" #include "stream.h" #include "jhash.h" diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 4d9ff60e9..46d3afbf7 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -25,7 +25,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "linklist.h" #include "stream.h" #include "command.h" -#include "str.h" #include "log.h" #include "sockunion.h" #include "memory.h" diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 57e38ce10..852046699 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -27,7 +27,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "command.h" #include "stream.h" #include "filter.h" -#include "str.h" #include "log.h" #include "routemap.h" #include "buffer.h" diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 77b979e56..9e5ec4b26 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -37,7 +37,6 @@ #include "memory.h" #include "filter.h" #include "routemap.h" -#include "str.h" #include "log.h" #include "plist.h" #include "linklist.h" diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 3cb3ddcde..e18ba235c 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -37,7 +37,6 @@ #include "memory.h" #include "filter.h" #include "routemap.h" -#include "str.h" #include "log.h" #include "plist.h" #include "linklist.h" diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index f80402298..7554b512e 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -32,7 +32,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "memory.h" #include "filter.h" #include "routemap.h" -#include "str.h" #include "log.h" #include "plist.h" #include "linklist.h" diff --git a/bgpd/rfapi/vnc_debug.c b/bgpd/rfapi/vnc_debug.c index eaa8c56ee..b1cf4f43e 100644 --- a/bgpd/rfapi/vnc_debug.c +++ b/bgpd/rfapi/vnc_debug.c @@ -25,7 +25,6 @@ #include "lib/linklist.h" #include "lib/stream.h" #include "lib/command.h" -#include "lib/str.h" #include "lib/log.h" #include "bgpd/rfapi/vnc_debug.h" diff --git a/lib/Makefile.am b/lib/Makefile.am index 1d2392f0e..723950681 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -12,13 +12,15 @@ libzebra_la_SOURCES = \ network.c pid_output.c getopt.c getopt1.c \ checksum.c vector.c linklist.c vty.c command.c \ sockunion.c prefix.c thread.c if.c buffer.c table.c hash.c \ - filter.c routemap.c distribute.c stream.c str.c log.c plist.c \ + filter.c routemap.c distribute.c stream.c log.c plist.c \ zclient.c sockopt.c smux.c agentx.c snmp.c md5.c if_rmap.c keychain.c privs.c \ sigevent.c pqueue.c jhash.c workqueue.c nexthop.c json.c \ ptm_lib.c csv.c bfd.c vrf.c systemd.c ns.c memory.c memory_vty.c \ imsg-buffer.c imsg.c skiplist.c \ qobj.c \ - event_counter.c + event_counter.c \ + strlcpy.c \ + strlcat.c BUILT_SOURCES = route_types.h gitversion.h @@ -28,7 +30,7 @@ pkginclude_HEADERS = \ buffer.h checksum.h command.h filter.h getopt.h hash.h \ if.h linklist.h log.h \ memory.h network.h prefix.h routemap.h distribute.h sockunion.h \ - str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \ + stream.h table.h thread.h vector.h version.h vty.h zebra.h \ plist.h zclient.h sockopt.h smux.h md5.h if_rmap.h keychain.h \ privs.h sigevent.h pqueue.h jhash.h zassert.h \ workqueue.h route_types.h libospf.h nexthop.h json.h \ @@ -34,7 +34,6 @@ #include "memory.h" #include "table.h" #include "buffer.h" -#include "str.h" #include "log.h" DEFINE_MTYPE( LIB, IF, "Interface") diff --git a/lib/nexthop.c b/lib/nexthop.c index 23ee28b7d..d7d8f0cd3 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -23,7 +23,6 @@ #include "prefix.h" #include "table.h" #include "memory.h" -#include "str.h" #include "command.h" #include "if.h" #include "log.h" diff --git a/lib/sockunion.c b/lib/sockunion.c index 2aa19dc74..f4b6ce12c 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -25,7 +25,6 @@ #include "vty.h" #include "sockunion.h" #include "memory.h" -#include "str.h" #include "log.h" #include "jhash.h" diff --git a/lib/str.c b/lib/str.c deleted file mode 100644 index 619cffdfe..000000000 --- a/lib/str.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * zebra string function - * - * XXX This version of snprintf does not check bounds! - */ - -/* - The implementations of strlcpy and strlcat are copied from rsync (GPL): - Copyright (C) Andrew Tridgell 1998 - Copyright (C) 2002 by Martin Pool - - Note that these are not terribly efficient, since they make more than one - pass over the argument strings. At some point, they should be optimized. - - The implementation of strndup is copied from glibc-2.3.5: - Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc. -*/ - -/* - * This file is part of Quagga. - * - * Quagga is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2, or (at your option) any - * later version. - * - * Quagga is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Quagga; see the file COPYING. If not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include <zebra.h> - -#ifndef HAVE_STRLCPY -/* - * 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 - -#ifndef HAVE_STRLCAT -/** - * Like strncat() but does not 0 fill the buffer and always null - * terminates. - * - * @param bufsize length of the buffer, which should be one more than - * the maximum resulting string length. - **/ -size_t -strlcat(char *d, const char *s, size_t bufsize) -{ - size_t len1 = strlen(d); - size_t len2 = strlen(s); - size_t ret = len1 + len2; - - if (len1 < bufsize - 1) { - if (len2 >= bufsize - len1) - len2 = bufsize - len1 - 1; - memcpy(d+len1, s, len2); - d[len1+len2] = 0; - } - return ret; -} -#endif diff --git a/lib/str.h b/lib/str.h deleted file mode 100644 index 9c0e515db..000000000 --- a/lib/str.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * $Id: str.h,v 1.4 2005/09/19 09:53:21 hasso Exp $ - */ - -#ifndef _ZEBRA_STR_H -#define _ZEBRA_STR_H - -#ifndef HAVE_STRLCPY -extern size_t strlcpy(char *, const char *, size_t); -#endif - -#ifndef HAVE_STRLCAT -extern size_t strlcat(char *, const char *, size_t); -#endif - -#endif /* _ZEBRA_STR_H */ - diff --git a/lib/strlcat.c b/lib/strlcat.c new file mode 100644 index 000000000..1d04b43d9 --- /dev/null +++ b/lib/strlcat.c @@ -0,0 +1,71 @@ +/* Append a null-terminated string to another string, with length checking. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +/* adapted for Quagga from glibc patch submission originally from + * Florian Weimer <fweimer@redhat.com>, 2016-05-18 */ + +#include <stdint.h> +#include <string.h> + +#include "config.h" + +#ifndef HAVE_STRLCAT +#undef strlcat + +size_t +strlcat (char *__restrict dest, const char *__restrict src, size_t size); + +size_t +strlcat (char *__restrict dest, const char *__restrict src, size_t size) +{ + size_t src_length = strlen (src); + + /* Our implementation strlcat supports dest == NULL if size == 0 + (for consistency with snprintf and strlcpy), but strnlen does + not, so we have to cover this case explicitly. */ + if (size == 0) + return src_length; + + size_t dest_length = strnlen (dest, size); + if (dest_length != size) + { + /* Copy at most the remaining number of characters in the + destination buffer. Leave for the NUL terminator. */ + size_t to_copy = size - dest_length - 1; + /* But not more than what is available in the source string. */ + if (to_copy > src_length) + to_copy = src_length; + + char *target = dest + dest_length; + memcpy (target, src, to_copy); + target[to_copy] = '\0'; + } + + /* If the sum wraps around, we have more than SIZE_MAX + 2 bytes in + the two input strings (including both null terminators). If each + byte in the address space can be assigned a unique size_t value + (which the static_assert checks), then by the pigeonhole + principle, the two input strings must overlap, which is + undefined. */ +#if __STDC_VERSION__ >= 201112L + _Static_assert (sizeof (uintptr_t) == sizeof (size_t), + "theoretical maximum object size covers address space"); +#endif + return dest_length + src_length; +} +#endif /* HAVE_STRLCAT */ diff --git a/lib/strlcpy.c b/lib/strlcpy.c new file mode 100644 index 000000000..41bab97ea --- /dev/null +++ b/lib/strlcpy.c @@ -0,0 +1,56 @@ +/* Copy a null-terminated string to a fixed-size buffer, with length checking. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +/* adapted for Quagga from glibc patch submission originally from + * Florian Weimer <fweimer@redhat.com>, 2016-05-18 */ + +#include <string.h> + +#include "config.h" + +#ifndef HAVE_STRLCPY +#undef strlcpy + +size_t +strlcpy (char *__restrict dest, const char *__restrict src, size_t size); + +size_t +strlcpy (char *__restrict dest, const char *__restrict src, size_t size) +{ + size_t src_length = strlen (src); + + if (__builtin_expect (src_length >= size, 0)) + { + if (size > 0) + { + /* Copy the leading portion of the string. The last + character is subsequently overwritten with the NUL + terminator, but the destination size is usually a + multiple of a small power of two, so writing it twice + should be more efficient than copying an odd number of + bytes. */ + memcpy (dest, src, size); + dest[size - 1] = '\0'; + } + } + else + /* Copy the string and its terminating NUL character. */ + memcpy (dest, src, src_length + 1); + return src_length; +} +#endif /* HAVE_STRLCPY */ @@ -29,7 +29,6 @@ #include "command.h" #include "sockunion.h" #include "memory.h" -#include "str.h" #include "log.h" #include "prefix.h" #include "filter.h" diff --git a/lib/zebra.h b/lib/zebra.h index 9a73d2d30..a67713c30 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -221,8 +221,13 @@ typedef unsigned char u_int8_t; #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */ #include "zassert.h" -#include "str.h" +#ifndef HAVE_STRLCAT +size_t strlcat (char *__restrict dest, const char *__restrict src, size_t size); +#endif +#ifndef HAVE_STRLCPY +size_t strlcpy (char *__restrict dest, const char *__restrict src, size_t size); +#endif #ifdef HAVE_BROKEN_CMSG_FIRSTHDR /* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>; diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 6cb9f7859..bcd92e15f 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -33,7 +33,6 @@ #include "zebra_memory.h" #include "ioctl.h" #include "log.h" -#include "str.h" #include "table.h" #include "rib.h" #include "privs.h" diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index 2bde3f4b0..b2c99d981 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -29,7 +29,6 @@ #include "prefix.h" #include "sockunion.h" #include "log.h" -#include "str.h" #include "privs.h" #include "zebra/debug.h" diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 15e5c330e..3b19a5da0 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -24,7 +24,6 @@ #include "prefix.h" #include "table.h" #include "memory.h" -#include "str.h" #include "command.h" #include "if.h" #include "log.h" diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 394469950..8b36eb806 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -26,7 +26,6 @@ #include "table.h" #include "memory.h" #include "zebra_memory.h" -#include "str.h" #include "command.h" #include "log.h" #include "sockunion.h" diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index fdb187a23..f88a6f0a9 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -24,7 +24,6 @@ #include "prefix.h" #include "table.h" #include "memory.h" -#include "str.h" #include "command.h" #include "if.h" #include "log.h" |