]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[dns] Allow trailing dots in DNS names
authorMichael Brown <mcb30@ipxe.org>
Tue, 10 Jan 2012 23:25:00 +0000 (23:25 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 10 Jan 2012 23:25:00 +0000 (23:25 +0000)
Reported-by: Christian Hesse <list@eworm.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/udp/dns.c

index d1435e769a966edf78297d9360048694fe0f73d3..124a0e49214e050291f3f39a05760307812baa85 100644 (file)
@@ -222,18 +222,24 @@ static char * dns_qualify_name ( const char *string ) {
  * DNS names consist of "<length>element" pairs.
  */
 static char * dns_make_name ( const char *string, char *buf ) {
-       char *length_byte = buf++;
+       char *length_byte;
        char c;
 
-       while ( ( c = *(string++) ) ) {
-               if ( c == '.' ) {
-                       *length_byte = buf - length_byte - 1;
-                       length_byte = buf;
+       length_byte = buf++;
+       *length_byte = 0;
+       do {
+               c = *(string++);
+               if ( ( c == '.' ) || ( c == '\0' ) ) {
+                       if ( *length_byte ) {
+                               length_byte = buf++;
+                               *length_byte = 0;
+                       }
+               } else {
+                       *(buf++) = c;
+                       (*length_byte)++;
                }
-               *(buf++) = c;
-       }
-       *length_byte = buf - length_byte - 1;
-       *(buf++) = '\0';
+       } while ( c );
+
        return buf;
 }