summaryrefslogtreecommitdiff
path: root/cifs.upcall.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@samba.org>2011-01-14 15:31:44 -0500
committerJeff Layton <jlayton@samba.org>2011-01-14 15:31:44 -0500
commitf704a1d4302613f43d35e9e90dde3debcf33f1d6 (patch)
tree5bdf79626612be58e841058945cd5eaf3cce4b0c /cifs.upcall.c
parent0b4bcc203d6c6934eedb8db756bb768457097142 (diff)
downloadcifs-utils-f704a1d4302613f43d35e9e90dde3debcf33f1d6.tar.gz
cifs-utils-f704a1d4302613f43d35e9e90dde3debcf33f1d6.tar.bz2
cifs-utils-f704a1d4302613f43d35e9e90dde3debcf33f1d6.zip
cifs.upcall: clean up key description decoding routine
...and switch the code to using strndup. Check for allocation errors as well, and fix some off-by-one bugs in the ones that decode strings. Signed-off-by: Jeff Layton <jlayton@samba.org> Acked-by: Igor Mammedov <niallain@gmail.com>
Diffstat (limited to 'cifs.upcall.c')
-rw-r--r--cifs.upcall.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/cifs.upcall.c b/cifs.upcall.c
index 33b7e4c..d83dddf 100644
--- a/cifs.upcall.c
+++ b/cifs.upcall.c
@@ -473,10 +473,13 @@ decode_key_description(const char *desc, struct decoded_args *arg)
else
len = pos - tkn;
- len -= 4;
+ len -= 5;
SAFE_FREE(arg->hostname);
- arg->hostname = calloc(sizeof(char), len);
- strlcpy(arg->hostname, tkn + 5, len);
+ arg->hostname = strndup(tkn + 5, len);
+ if (arg->hostname == NULL) {
+ syslog(LOG_ERR, "Unable to allocate memory");
+ return 1;
+ }
retval |= DKD_HAVE_HOSTNAME;
} else if (!strncmp(tkn, "ip4=", 4) || !strncmp(tkn, "ip6=", 4)) {
if (pos == NULL)
@@ -484,10 +487,13 @@ decode_key_description(const char *desc, struct decoded_args *arg)
else
len = pos - tkn;
- len -= 3;
+ len -= 4;
SAFE_FREE(arg->ip);
- arg->ip = calloc(sizeof(char), len);
- strlcpy(arg->ip, tkn + 4, len);
+ arg->ip = strndup(tkn + 4, len);
+ if (arg->ip == NULL) {
+ syslog(LOG_ERR, "Unable to allocate memory");
+ return 1;
+ }
retval |= DKD_HAVE_IP;
} else if (strncmp(tkn, "pid=", 4) == 0) {
errno = 0;
@@ -496,9 +502,8 @@ decode_key_description(const char *desc, struct decoded_args *arg)
syslog(LOG_ERR, "Invalid pid format: %s",
strerror(errno));
return 1;
- } else {
- retval |= DKD_HAVE_PID;
}
+ retval |= DKD_HAVE_PID;
} else if (strncmp(tkn, "sec=", 4) == 0) {
if (strncmp(tkn + 4, "krb5", 4) == 0) {
retval |= DKD_HAVE_SEC;
@@ -514,9 +519,8 @@ decode_key_description(const char *desc, struct decoded_args *arg)
syslog(LOG_ERR, "Invalid uid format: %s",
strerror(errno));
return 1;
- } else {
- retval |= DKD_HAVE_UID;
}
+ retval |= DKD_HAVE_UID;
} else if (strncmp(tkn, "creduid=", 8) == 0) {
errno = 0;
arg->creduid = strtol(tkn + 8, NULL, 16);
@@ -524,9 +528,8 @@ decode_key_description(const char *desc, struct decoded_args *arg)
syslog(LOG_ERR, "Invalid creduid format: %s",
strerror(errno));
return 1;
- } else {
- retval |= DKD_HAVE_CREDUID;
}
+ retval |= DKD_HAVE_CREDUID;
} else if (strncmp(tkn, "ver=", 4) == 0) { /* if version */
errno = 0;
arg->ver = strtol(tkn + 4, NULL, 16);
@@ -534,9 +537,8 @@ decode_key_description(const char *desc, struct decoded_args *arg)
syslog(LOG_ERR, "Invalid version format: %s",
strerror(errno));
return 1;
- } else {
- retval |= DKD_HAVE_VERSION;
}
+ retval |= DKD_HAVE_VERSION;
}
if (pos == NULL)
break;