⬢ DragonFlyBSD Kernel Audit
DF-5698 / fixcheck.c
← back to finding ↓ download raw
/* Prints errno behavior of the TU under test: too-small dst + bad af */
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
char *dk_inet_ntop(int af, const void *src, char *dst, socklen_t size);
int main(void)
{
	char b[64];
	errno = 0;
	char *r1 = dk_inet_ntop(AF_INET, "\x01\x02\x03\x04", b, 2);
	int e1 = errno;
	errno = 0;
	char *r2 = dk_inet_ntop(AF_UNSPEC, "\x01\x02\x03\x04", b, 64);
	int e2 = errno;
	printf("variant=%s too_small: ret=%p errno=%d(%s) | bad_af: ret=%p errno=%d(%s)\n",
#ifdef FIXED
	       "FIXED",
#else
	       "BASELINE",
#endif
	       (void *)r1, e1, e1 == ENOSPC ? "ENOSPC" : "NOT-SET",
	       (void *)r2, e2, e2 == EAFNOSUPPORT ? "EAFNOSUPPORT" : "NOT-SET");
	return (e1 == ENOSPC && e2 == EAFNOSUPPORT) ? 0 : 1;
}