mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 15:48:49 -05:00
strlcat: remove function
This function was only used twice, both in places where performance
isn't crucial (socks + if2ip). Removing the use of this function removes
the need to have our private version for systems without it == reduced
amount of code.
Also, in the SOCKS case it is clearly better to fail gracefully rather
than to truncate the results.
This work was triggered by a bug report on the strcal prototype in
strequal.h.
strlcat was added in commit db70cd28
in February 2001!
Bug: http://curl.haxx.se/bug/view.cgi?id=1192
Reported by: Jeremy Huddleston
This commit is contained in:
parent
d821525cee
commit
358c5c0745
@ -3044,7 +3044,6 @@ CURL_CHECK_FUNC_STRCMPI
|
||||
CURL_CHECK_FUNC_STRDUP
|
||||
CURL_CHECK_FUNC_STRERROR_R
|
||||
CURL_CHECK_FUNC_STRICMP
|
||||
CURL_CHECK_FUNC_STRLCAT
|
||||
CURL_CHECK_FUNC_STRNCASECMP
|
||||
CURL_CHECK_FUNC_STRNCMPI
|
||||
CURL_CHECK_FUNC_STRNICMP
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -164,10 +164,6 @@
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
#define HAVE_VARIADIC_MACROS_GCC 1
|
||||
|
||||
#if (DJGPP_MINOR >= 4)
|
||||
#define HAVE_STRLCAT 1
|
||||
#endif
|
||||
|
||||
/* Because djgpp <= 2.03 doesn't have snprintf() etc. */
|
||||
#if (DJGPP_MINOR < 4)
|
||||
#define _MPRINTF_REPLACE
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -298,9 +298,6 @@
|
||||
/* Define if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H
|
||||
|
||||
/* Define if you have the `strlcat' function. */
|
||||
#undef HAVE_STRLCAT
|
||||
|
||||
/* Define if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -305,9 +305,6 @@
|
||||
/* Define if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H
|
||||
|
||||
/* Define if you have the `strlcat' function. */
|
||||
#undef HAVE_STRLCAT
|
||||
|
||||
/* Define if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -525,9 +525,6 @@
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strlcat' function. */
|
||||
#define HAVE_STRLCAT 1
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#define HAVE_STRLCPY 1
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -471,9 +471,6 @@
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strlcat' function. */
|
||||
/* #undef HAVE_STRLCAT */
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
/* #undef HAVE_STRLCPY */
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -592,9 +592,6 @@
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the strlcat function. */
|
||||
/* #undef HAVE_STRLCAT */
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
/* #undef HAVE_STRLCPY */
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -95,6 +95,7 @@ char *Curl_if2ip(int af, const char *interf, char *buf, int buf_size)
|
||||
curl_strequal(iface->ifa_name, interf)) {
|
||||
void *addr;
|
||||
char scope[12]="";
|
||||
char ipstr[64];
|
||||
#ifdef ENABLE_IPV6
|
||||
if(af == AF_INET6) {
|
||||
unsigned int scopeid = 0;
|
||||
@ -109,8 +110,9 @@ char *Curl_if2ip(int af, const char *interf, char *buf, int buf_size)
|
||||
else
|
||||
#endif
|
||||
addr = &((struct sockaddr_in *)iface->ifa_addr)->sin_addr;
|
||||
ip = (char *) Curl_inet_ntop(af, addr, buf, buf_size);
|
||||
strlcat(buf, scope, buf_size);
|
||||
ip = (char *) Curl_inet_ntop(af, addr, ipstr, sizeof(ipstr));
|
||||
snprintf(buf, buf_size, "%s%s", ip, scope);
|
||||
ip = buf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
13
lib/socks.c
13
lib/socks.c
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -196,8 +196,15 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
|
||||
* This is currently not supporting "Identification Protocol (RFC1413)".
|
||||
*/
|
||||
socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
|
||||
if(proxy_name)
|
||||
strlcat((char*)socksreq + 8, proxy_name, sizeof(socksreq) - 8);
|
||||
if(proxy_name) {
|
||||
size_t plen = strlen(proxy_name);
|
||||
if(plen >= sizeof(socksreq) - 8) {
|
||||
failf(data, "Too long SOCKS proxy name, can't use!\n");
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
}
|
||||
/* copy the proxy name WITH trailing zero */
|
||||
memcpy(socksreq + 8, proxy_name, plen+1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make connection
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -77,48 +77,3 @@ int curl_strnequal(const char *first, const char *second, size_t max)
|
||||
return toupper(*first) == toupper(*second);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/*
|
||||
* The strlcat() function appends the NUL-terminated string src to the end
|
||||
* of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-termi-
|
||||
* nating the result.
|
||||
*
|
||||
* The strlcpy() and strlcat() functions return the total length of the
|
||||
* string they tried to create. For strlcpy() that means the length of src.
|
||||
* For strlcat() that means the initial length of dst plus the length of
|
||||
* src. While this may seem somewhat confusing it was done to make trunca-
|
||||
* tion detection simple.
|
||||
*
|
||||
*
|
||||
*/
|
||||
size_t Curl_strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
union {
|
||||
ssize_t sig;
|
||||
size_t uns;
|
||||
} dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while(n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen.sig = d - dst;
|
||||
n = siz - dlen.uns;
|
||||
|
||||
if(n == 0)
|
||||
return(dlen.uns + strlen(s));
|
||||
while(*s != '\0') {
|
||||
if(n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen.uns + (s - src)); /* count does not include NUL */
|
||||
}
|
||||
#endif
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -27,10 +27,5 @@
|
||||
#define strequal(a,b) curl_strequal(a,b)
|
||||
#define strnequal(a,b,c) curl_strnequal(a,b,c)
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
#define strlcat(x,y,z) Curl_strlcat(x,y,z)
|
||||
#endif
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
|
||||
#endif /* HEADER_CURL_STREQUAL_H */
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
# Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file COPYING, which
|
||||
# you should have received as part of this distribution. The terms
|
||||
@ -21,7 +21,7 @@
|
||||
#***************************************************************************
|
||||
|
||||
# File version for 'aclocal' use. Keep it a single number.
|
||||
# serial 72
|
||||
# serial 73
|
||||
|
||||
|
||||
dnl CURL_INCLUDES_ARPA_INET
|
||||
@ -6472,92 +6472,6 @@ AC_DEFUN([CURL_CHECK_FUNC_STRICMP], [
|
||||
fi
|
||||
])
|
||||
|
||||
|
||||
dnl CURL_CHECK_FUNC_STRLCAT
|
||||
dnl -------------------------------------------------
|
||||
dnl Verify if strlcat is available, prototyped, and
|
||||
dnl can be compiled. If all of these are true, and
|
||||
dnl usage has not been previously disallowed with
|
||||
dnl shell variable curl_disallow_strlcat, then
|
||||
dnl HAVE_STRLCAT will be defined.
|
||||
|
||||
AC_DEFUN([CURL_CHECK_FUNC_STRLCAT], [
|
||||
AC_REQUIRE([CURL_INCLUDES_STRING])dnl
|
||||
#
|
||||
tst_links_strlcat="unknown"
|
||||
tst_proto_strlcat="unknown"
|
||||
tst_compi_strlcat="unknown"
|
||||
tst_allow_strlcat="unknown"
|
||||
#
|
||||
AC_MSG_CHECKING([if strlcat can be linked])
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_FUNC_LINK_TRY([strlcat])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_links_strlcat="yes"
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
tst_links_strlcat="no"
|
||||
])
|
||||
#
|
||||
if test "$tst_links_strlcat" = "yes"; then
|
||||
AC_MSG_CHECKING([if strlcat is prototyped])
|
||||
AC_EGREP_CPP([strlcat],[
|
||||
$curl_includes_string
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_proto_strlcat="yes"
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
tst_proto_strlcat="no"
|
||||
])
|
||||
fi
|
||||
#
|
||||
if test "$tst_proto_strlcat" = "yes"; then
|
||||
AC_MSG_CHECKING([if strlcat is compilable])
|
||||
AC_COMPILE_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
$curl_includes_string
|
||||
]],[[
|
||||
if(0 != strlcat(0, 0, 0))
|
||||
return 1;
|
||||
]])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_compi_strlcat="yes"
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
tst_compi_strlcat="no"
|
||||
])
|
||||
fi
|
||||
#
|
||||
if test "$tst_compi_strlcat" = "yes"; then
|
||||
AC_MSG_CHECKING([if strlcat usage allowed])
|
||||
if test "x$curl_disallow_strlcat" != "xyes"; then
|
||||
AC_MSG_RESULT([yes])
|
||||
tst_allow_strlcat="yes"
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
tst_allow_strlcat="no"
|
||||
fi
|
||||
fi
|
||||
#
|
||||
AC_MSG_CHECKING([if strlcat might be used])
|
||||
if test "$tst_links_strlcat" = "yes" &&
|
||||
test "$tst_proto_strlcat" = "yes" &&
|
||||
test "$tst_compi_strlcat" = "yes" &&
|
||||
test "$tst_allow_strlcat" = "yes"; then
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE_UNQUOTED(HAVE_STRLCAT, 1,
|
||||
[Define to 1 if you have the strlcat function.])
|
||||
ac_cv_func_strlcat="yes"
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
ac_cv_func_strlcat="no"
|
||||
fi
|
||||
])
|
||||
|
||||
|
||||
dnl CURL_CHECK_FUNC_STRNCASECMP
|
||||
dnl -------------------------------------------------
|
||||
dnl Verify if strncasecmp is available, prototyped, and
|
||||
|
Loading…
Reference in New Issue
Block a user