fd4b48
diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c
fd4b48
index 486c102..dc12a85 100644
fd4b48
--- a/bin/nsupdate/nsupdate.c
fd4b48
+++ b/bin/nsupdate/nsupdate.c
fd4b48
@@ -1566,16 +1566,20 @@ evaluate_realm(char *cmdline) {
fd4b48
 #ifdef GSSAPI
fd4b48
 	char *word;
fd4b48
 	char buf[1024];
fd4b48
+	int n;
fd4b48
 
fd4b48
-	word = nsu_strsep(&cmdline, " \t\r\n");
fd4b48
-	if (word == NULL || *word == 0) {
fd4b48
-		if (realm != NULL)
fd4b48
-			isc_mem_free(mctx, realm);
fd4b48
+	if (realm != NULL) {
fd4b48
+		isc_mem_free(mctx, realm);
fd4b48
 		realm = NULL;
fd4b48
-		return (STATUS_MORE);
fd4b48
 	}
fd4b48
 
fd4b48
-	snprintf(buf, sizeof(buf), "@%s", word);
fd4b48
+	word = nsu_strsep(&cmdline, " \t\r\n");
fd4b48
+	if (word == NULL || *word == 0)
fd4b48
+		return (STATUS_MORE);
fd4b48
+
fd4b48
+	n = snprintf(buf, sizeof(buf), "@%s", word);
fd4b48
+	if (n < 0 || (size_t)n >= sizeof(buf))
fd4b48
+		fatal("realm is too long");
fd4b48
 	realm = isc_mem_strdup(mctx, buf);
fd4b48
 	if (realm == NULL)
fd4b48
 		fatal("out of memory");