]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[dns] Ensure DNS names are NUL-terminated when used as diagnostic strings
authorMichael Brown <mcb30@ipxe.org>
Thu, 7 Sep 2017 11:17:18 +0000 (12:17 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 7 Sep 2017 11:19:35 +0000 (12:19 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/udp/dns.c

index 897e0f8579864f090e7709db38e045cb41aff8f2..f412f71090dba851bc10a60cb0338eb2ceb1e8b1 100644 (file)
@@ -417,7 +417,7 @@ static const char * dns_name ( struct dns_name *name ) {
        static char buf[256];
        int len;
 
-       len = dns_decode ( name, buf, sizeof ( buf ) );
+       len = dns_decode ( name, buf, ( sizeof ( buf ) - 1 /* NUL */ ) );
        return ( ( len < 0 ) ? "<INVALID>" : buf );
 }
 
@@ -877,10 +877,16 @@ static void dns_xfer_close ( struct dns_request *dns, int rc ) {
  */
 static int dns_progress ( struct dns_request *dns,
                          struct job_progress *progress ) {
+       int len;
 
        /* Show current question as progress message */
-       dns_decode ( &dns->name, progress->message,
-                    sizeof ( progress->message ) );
+       len = dns_decode ( &dns->name, progress->message,
+                          ( sizeof ( progress->message ) - 1 /* NUL */ ) );
+       if ( len < 0 ) {
+               /* Ignore undecodable names */
+               progress->message[0] = '\0';
+       }
+
        return 0;
 }