Commit Diff


commit - d57e3cc08300fbcf32fc7924936b620f0f0f78b98fc758a2cb29e5cb87194174
commit + d8edb9b3d7629efe31c0e33d56acc527255f73aed8d47bababbc7bdc0670105e
blob - dedb2ec105b27842a46afa595b9e6942b61209be3ec82f1e17a41db372842ac4
blob + 2af0187d821515c86be933cc2564b6c28b1aced8b0dfab94a29cccf92c815323
--- lib/gotsys_imsg.c	
+++ lib/gotsys_imsg.c	
@@ -456,12 +456,15 @@ gotsys_imsg_send_authorized_keys(struct gotsysd_imsgev
 			    "authorized key too long: %s:", k->key);
 		}
 
-		commentlen = strlen(k->comment);
-		if (commentlen > GOTSYS_AUTHORIZED_KEY_MAXLEN) {
-			return got_error_fmt(GOT_ERR_NO_SPACE,
-			    "authorized key comment too long: %s:",
-			    k->comment);
-		}
+		if (k->comment) {
+			commentlen = strlen(k->comment);
+			if (commentlen > GOTSYS_AUTHORIZED_KEY_MAXLEN) {
+				return got_error_fmt(GOT_ERR_NO_SPACE,
+				    "authorized key comment too long: %s:",
+				    k->comment);
+			}
+		} else
+			commentlen = 0;
 
 		klen = typelen + datalen + commentlen;
 		if (klen > GOTSYS_AUTHORIZED_KEY_MAXLEN) {
@@ -481,7 +484,7 @@ gotsys_imsg_send_authorized_keys(struct gotsysd_imsgev
 
 		ikey.keytype_len = strlen(k->keytype);
 		ikey.keydata_len = strlen(k->key);
-		ikey.comment_len = strlen(k->comment);
+		ikey.comment_len = k->comment ? strlen(k->comment) : 0;
 
 		klen = ikey.keytype_len + ikey.keydata_len + ikey.comment_len;
 
@@ -512,7 +515,8 @@ gotsys_imsg_send_authorized_keys(struct gotsysd_imsgev
 		if (imsg_add(wbuf, k->key, ikey.keydata_len) == -1)
 			return got_error_from_errno_fmt("imsg_add %d",
 			    imsg_type);
-		if (imsg_add(wbuf, k->comment, ikey.comment_len) == -1)
+		if (ikey.comment_len > 0 &&
+		    imsg_add(wbuf, k->comment, ikey.comment_len) == -1)
 			return got_error_from_errno_fmt("imsg_add %d",
 			    imsg_type);
 
blob - c0a753efb5f6d18a3dfeae377e1f0e9cf9d495a11c7fa01e393b6dc34c71adc1
blob + 95dd3a31375bd044b39db48fb6f59dbe1866e3dbb9b4d4467601a7fb9b1bffb9
--- regress/gotsysd/test_gotsysd.sh	
+++ regress/gotsysd/test_gotsysd.sh	
@@ -292,7 +292,8 @@ test_user_mod() {
 
 	crypted_vm_pw=`echo ${GOTSYSD_VM_PASSWORD} | encrypt | tr -d '\n'`
 	crypted_pw=`echo ${GOTSYSD_DEV_PASSWORD}1234 | encrypt | tr -d '\n'`
-	sshkey=`cat ${GOTSYSD_SSH_PUBKEY}`
+	# strip the optional ssh key comment for better test coverage
+	sshkey=`cat ${GOTSYSD_SSH_PUBKEY} | cut -d' ' -f 1,2`
 	cat > ${testroot}/wt/gotsys.conf <<EOF
 user ${GOTSYSD_TEST_USER} {
 	password "${crypted_vm_pw}"