Browse Source

[dns] Allow trailing dots in DNS names

Reported-by: Christian Hesse <list@eworm.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
187cd80106
1 changed files with 15 additions and 9 deletions
  1. 15
    9
      src/net/udp/dns.c

+ 15
- 9
src/net/udp/dns.c View File

222
  * DNS names consist of "<length>element" pairs.
222
  * DNS names consist of "<length>element" pairs.
223
  */
223
  */
224
 static char * dns_make_name ( const char *string, char *buf ) {
224
 static char * dns_make_name ( const char *string, char *buf ) {
225
-	char *length_byte = buf++;
225
+	char *length_byte;
226
 	char c;
226
 	char c;
227
 
227
 
228
-	while ( ( c = *(string++) ) ) {
229
-		if ( c == '.' ) {
230
-			*length_byte = buf - length_byte - 1;
231
-			length_byte = buf;
228
+	length_byte = buf++;
229
+	*length_byte = 0;
230
+	do {
231
+		c = *(string++);
232
+		if ( ( c == '.' ) || ( c == '\0' ) ) {
233
+			if ( *length_byte ) {
234
+				length_byte = buf++;
235
+				*length_byte = 0;
236
+			}
237
+		} else {
238
+			*(buf++) = c;
239
+			(*length_byte)++;
232
 		}
240
 		}
233
-		*(buf++) = c;
234
-	}
235
-	*length_byte = buf - length_byte - 1;
236
-	*(buf++) = '\0';
241
+	} while ( c );
242
+
237
 	return buf;
243
 	return buf;
238
 }
244
 }
239
 
245
 

Loading…
Cancel
Save