Ver código fonte

[dns] Ensure DNS names are NUL-terminated when used as diagnostic strings

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 anos atrás
pai
commit
af02a8d071
1 arquivos alterados com 9 adições e 3 exclusões
  1. 9
    3
      src/net/udp/dns.c

+ 9
- 3
src/net/udp/dns.c Ver arquivo

@@ -417,7 +417,7 @@ static const char * dns_name ( struct dns_name *name ) {
417 417
 	static char buf[256];
418 418
 	int len;
419 419
 
420
-	len = dns_decode ( name, buf, sizeof ( buf ) );
420
+	len = dns_decode ( name, buf, ( sizeof ( buf ) - 1 /* NUL */ ) );
421 421
 	return ( ( len < 0 ) ? "<INVALID>" : buf );
422 422
 }
423 423
 
@@ -877,10 +877,16 @@ static void dns_xfer_close ( struct dns_request *dns, int rc ) {
877 877
  */
878 878
 static int dns_progress ( struct dns_request *dns,
879 879
 			  struct job_progress *progress ) {
880
+	int len;
880 881
 
881 882
 	/* Show current question as progress message */
882
-	dns_decode ( &dns->name, progress->message,
883
-		     sizeof ( progress->message ) );
883
+	len = dns_decode ( &dns->name, progress->message,
884
+			   ( sizeof ( progress->message ) - 1 /* NUL */ ) );
885
+	if ( len < 0 ) {
886
+		/* Ignore undecodable names */
887
+		progress->message[0] = '\0';
888
+	}
889
+
884 890
 	return 0;
885 891
 }
886 892
 

Carregando…
Cancelar
Salvar