]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Clean up getclhoststr in ipropd_svc.c
authorGreg Hudson <ghudson@mit.edu>
Thu, 21 Mar 2013 05:48:22 +0000 (01:48 -0400)
committerGreg Hudson <ghudson@mit.edu>
Thu, 21 Mar 2013 05:59:46 +0000 (01:59 -0400)
Based on a patch from Xi Wang <xi@mit.edu>.

src/kadmin/server/ipropd_svc.c

index ca96295c46f5e9a9c0a4f5f3326c68f419c476f5..008bff01eb301779701ec9b99c03be610decfb70 100644 (file)
@@ -239,24 +239,16 @@ out:
  * Return arg cl str ptr on success, else NULL.
  */
 static char *
-getclhoststr(char *clprinc, char *cl, size_t len)
+getclhoststr(const char *clprinc, char *cl, size_t len)
 {
-    char *s;
-    if ((s = strchr(clprinc, '/')) != NULL) {
-       /* XXX "!++s"?  */
-       if (!++s)
-           return NULL;
-       if (strlcpy(cl, s, len) >= len)
-           return NULL;
-       /* XXX Copy with @REALM first, with bounds check, then
-          chop off the realm??  */
-       if ((s = strchr(cl, '@')) != NULL) {
-           *s = '\0';
-           return (cl); /* success */
-       }
-    }
-
-    return (NULL);
+    const char *s, *e;
+
+    if ((s = strchr(clprinc, '/')) == NULL || (e = strchr(++s, '@')) == NULL ||
+       (size_t)(e - s) >= len)
+       return NULL;
+    memcpy(cl, s, e - s);
+    cl[e - s] = '\0';
+    return (cl);
 }
 
 static kdb_fullresync_result_t *