krb5 commit: Clean up getclhoststr in ipropd_svc.c

Greg Hudson ghudson at MIT.EDU
Thu Mar 21 02:00:02 EDT 2013


https://github.com/krb5/krb5/commit/093704b74884dca424ffe5a88765e3c513f71ecb
commit 093704b74884dca424ffe5a88765e3c513f71ecb
Author: Greg Hudson <ghudson at mit.edu>
Date:   Thu Mar 21 01:48:22 2013 -0400

    Clean up getclhoststr in ipropd_svc.c
    
    Based on a patch from Xi Wang <xi at mit.edu>.

 src/kadmin/server/ipropd_svc.c |   26 +++++++++-----------------
 1 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/src/kadmin/server/ipropd_svc.c b/src/kadmin/server/ipropd_svc.c
index ca96295..008bff0 100644
--- a/src/kadmin/server/ipropd_svc.c
+++ b/src/kadmin/server/ipropd_svc.c
@@ -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 *


More information about the cvs-krb5 mailing list