Skip to content

Commit

Permalink
[dns] Ensure DNS names are NUL-terminated when used as diagnostic str…
Browse files Browse the repository at this point in the history
…ings

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Sep 7, 2017
1 parent e8f3057 commit af02a8d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/net/udp/dns.c
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit af02a8d

Please sign in to comment.