summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
authorJames Peach <jpeach@samba.org>2006-02-08 05:13:11 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:51:52 -0500
commitb7f7adb2e1068d1c382f774e54d1b495e6345938 (patch)
tree6aeb827e6171d7d6ed6675ded0b0778509ba47ca /source4/libcli
parentd32b14c2bc1fa5ee80bc52feb9094edccc462674 (diff)
downloadsamba-b7f7adb2e1068d1c382f774e54d1b495e6345938.tar.gz
samba-b7f7adb2e1068d1c382f774e54d1b495e6345938.tar.bz2
samba-b7f7adb2e1068d1c382f774e54d1b495e6345938.zip
r13387: Make sure smbcli_parse_unc reports a failure for strings of
the form //server. Make sure failure cases are well-defined. (This used to be commit e0020df66bf38873eaaacb95cadac55e17f432be)
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/cliconnect.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c
index 9a5236a661..8103208a26 100644
--- a/source4/libcli/cliconnect.c
+++ b/source4/libcli/cliconnect.c
@@ -177,25 +177,29 @@ struct smbcli_state *smbcli_state_init(TALLOC_CTX *mem_ctx)
}
/* Insert a NULL at the first separator of the given path and return a pointer
- * to the location it was inserted at.
+ * to the remainder of the string.
*/
static char *
terminate_path_at_separator(char * path)
{
char * p;
+ if (!path) {
+ return NULL;
+ }
+
if ((p = strchr_m(path, '/'))) {
- *p = '\0';
- return(p);
+ *p = '\0';
+ return p + 1;
}
if ((p = strchr_m(path, '\\'))) {
- *p = '\0';
- return(p);
+ *p = '\0';
+ return p + 1;
}
- /* No terminator. Return pointer to the last byte. */
- return(p + strlen(path));
+ /* No separator. */
+ return NULL;
}
/*
@@ -206,6 +210,8 @@ BOOL smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
{
char *p;
+ *hostname = *sharename = NULL;
+
if (strncmp(unc_name, "\\\\", 2) &&
strncmp(unc_name, "//", 2)) {
return False;
@@ -214,10 +220,19 @@ BOOL smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
*hostname = talloc_strdup(mem_ctx, &unc_name[2]);
p = terminate_path_at_separator(*hostname);
- *sharename = talloc_strdup(mem_ctx, p+1);
- p = terminate_path_at_separator(*sharename);
+ if (p && *p) {
+ *sharename = talloc_strdup(mem_ctx, p);
+ terminate_path_at_separator(*sharename);
+ }
- return True;
+ if (*hostname && *sharename) {
+ return True;
+ }
+
+ talloc_free(*hostname);
+ talloc_free(*sharename);
+ *hostname = *sharename = NULL;
+ return False;
}