This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug network/18237] New: dn_expand of empty name should succeed with "" when output size is 1
- From: "nszabolcs at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Fri, 10 Apr 2015 10:52:05 +0000
- Subject: [Bug network/18237] New: dn_expand of empty name should succeed with "" when output size is 1
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=18237
Bug ID: 18237
Summary: dn_expand of empty name should succeed with "" when
output size is 1
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: network
Assignee: unassigned at sourceware dot org
Reporter: nszabolcs at gmail dot com
dn_expand behaves inconsistently on empty name message.
if the length of the output is at least 2 then glibc writes a single \0 byte to
name, but if it is only 1 then dn_expand fails (eventhough the result would
fit).
the following code prints
dn_expand("", name, 1) returned -1, wanted 1
dn_expand("", name, 1) failed: got ".XX" name, wanted ""
dn_expand("\xc0\2", name, 1) returned -1, wanted 2
dn_expand("\xc0\2", name, 1) failed: got ".XX" name, wanted ""
#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#include <resolv.h>
#include <string.h>
#include <stdio.h>
int main(void)
{
unsigned char packet[4];
char name[4];
int r, N;
for (N=1; N<4; N++) {
memset(packet, 0, 4);
memcpy(name, "XXX", 4);
r = dn_expand(packet, packet+1, packet, name, N);
if (r!=1)
printf("dn_expand(\"\", name, %d) returned %d, wanted 1\n", N, r);
if (name[0])
printf("dn_expand(\"\", name, %d) failed: got \"%s\" name, wanted
\"\"\n", N, name);
/* empty name with offset pointer to 0 */
memcpy(packet, "\xc0\2\0", 4);
memcpy(name, "XXX", 4);
r = dn_expand(packet, packet+3, packet, name, N);
if (r!=2)
printf("dn_expand(\"\\xc0\\2\", name, %d) returned %d, wanted 2\n", N,
r);
if (name[0])
printf("dn_expand(\"\\xc0\\2\", name, %d) failed: got \"%s\" name,
wanted \"\"\n", N, name);
}
}
--
You are receiving this mail because:
You are on the CC list for the bug.