*
* Returns CURLE_OK on success.
*/
-CURLcode Curl_parse_interface(const char *input, size_t len,
+CURLcode Curl_parse_interface(const char *input,
char **dev, char **iface, char **host)
{
static const char if_prefix[] = "if!";
static const char host_prefix[] = "host!";
static const char if_host_prefix[] = "ifhost!";
+ size_t len;
DEBUGASSERT(dev);
DEBUGASSERT(iface);
DEBUGASSERT(host);
- if(strncmp(if_prefix, input, strlen(if_prefix)) == 0) {
+ len = strlen(input);
+ if(len > 512)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ if(!strncmp(if_prefix, input, strlen(if_prefix))) {
input += strlen(if_prefix);
if(!*input)
return CURLE_BAD_FUNCTION_ARGUMENT;
*iface = Curl_memdup0(input, len - strlen(if_prefix));
return *iface ? CURLE_OK : CURLE_OUT_OF_MEMORY;
}
- if(strncmp(host_prefix, input, strlen(host_prefix)) == 0) {
+ else if(!strncmp(host_prefix, input, strlen(host_prefix))) {
input += strlen(host_prefix);
if(!*input)
return CURLE_BAD_FUNCTION_ARGUMENT;
*host = Curl_memdup0(input, len - strlen(host_prefix));
return *host ? CURLE_OK : CURLE_OUT_OF_MEMORY;
}
- if(strncmp(if_host_prefix, input, strlen(if_host_prefix)) == 0) {
+ else if(!strncmp(if_host_prefix, input, strlen(if_host_prefix))) {
const char *host_part;
input += strlen(if_host_prefix);
len -= strlen(if_host_prefix);
/*
* Parse interface option, and return the interface name and the host part.
*/
-CURLcode Curl_parse_interface(const char *input, size_t len,
+CURLcode Curl_parse_interface(const char *input,
char **dev, char **iface, char **host);
/*
return CURLE_OK;
}
-static CURLcode setstropt_interface(
- char *option, char **devp, char **ifacep, char **hostp)
+static CURLcode setstropt_interface(char *option, char **devp,
+ char **ifacep, char **hostp)
{
char *dev = NULL;
char *iface = NULL;
char *host = NULL;
- size_t len;
CURLcode result;
DEBUGASSERT(devp);
DEBUGASSERT(ifacep);
DEBUGASSERT(hostp);
- /* Parse the interface details */
- if(!option || !*option)
- return CURLE_BAD_FUNCTION_ARGUMENT;
- len = strlen(option);
- if(len > 255)
- return CURLE_BAD_FUNCTION_ARGUMENT;
-
- result = Curl_parse_interface(option, len, &dev, &iface, &host);
- if(result)
- return result;
-
+ if(option) {
+ /* Parse the interface details if set, otherwise clear them all */
+ result = Curl_parse_interface(option, &dev, &iface, &host);
+ if(result)
+ return result;
+ }
free(*devp);
*devp = dev;
char *dev = NULL;
char *iface = NULL;
char *host = NULL;
- CURLcode rc = Curl_parse_interface(
- input, strlen(input), &dev, &iface, &host);
+ CURLcode rc = Curl_parse_interface(input, &dev, &iface, &host);
fail_unless(rc == exp_rc, "Curl_parse_interface() failed");
fail_unless(!!exp_dev == !!dev, "dev expectation failed.");