Przeglądaj źródła

[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 13 lat temu
rodzic
commit
187cd80106
1 zmienionych plików z 15 dodań i 9 usunięć
  1. 15
    9
      src/net/udp/dns.c

+ 15
- 9
src/net/udp/dns.c Wyświetl plik

@@ -222,18 +222,24 @@ static char * dns_qualify_name ( const char *string ) {
222 222
  * DNS names consist of "<length>element" pairs.
223 223
  */
224 224
 static char * dns_make_name ( const char *string, char *buf ) {
225
-	char *length_byte = buf++;
225
+	char *length_byte;
226 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 243
 	return buf;
238 244
 }
239 245
 

Ładowanie…
Anuluj
Zapisz