⬢ DragonFlyBSD Kernel Audit
DF-2230 / userland_full.c
← back to finding ↓ download raw
/*
 * DF-2230 verification rig -- USERLAND full-path test.
 *
 * Same XML case matrix as the kernel module, parsed by the userland
 * build of the same proplib (libprop is built from sys/libprop via
 * .PATH in lib/libprop/Makefile).  This is the desync counterpart:
 * userland HAS errno, so the ERANGE check that the kernel build
 * compiles out is active here.
 *
 * Output line format identical to the kernel side:
 *	DF2230|U|in=<input>|array=<0/1>|cnt=<n>|elem=<yes/NO>|is_unsigned=<0/1/-1>|signed=<dec> (0x<hex>)|unsigned=<dec> (0x<hex>)
 */
#include <stdio.h>
#include <libprop/proplib.h>

static const char *df2230_vals[] = {
	"0",
	"42",
	"-1",
	"-9223372036854775808",
	"-9223372036854775809",
	"9223372036854775807",
	"9223372036854775808",
	"10000000000000000000",
	"18446744073709551615",
	"99999999999999999999",
	"0x7fffffffffffffff",
	"0x8000000000000000",
	"0xffffffffffffffff",
	"0Xffffffffffffffff",
};
#define	DF2230_NVALS	((int)(sizeof(df2230_vals) / sizeof(df2230_vals[0])))

int
main(void)
{
	int i;

	printf("DF2230|U|BEGIN matrix (userland prop_array_internalize)\n");
	for (i = 0; i < DF2230_NVALS; i++) {
		char xml[640];
		prop_array_t pa;
		prop_object_t o;
		int ok, cnt = -1, isu = -1;
		int64_t sv = 0;
		uint64_t uv = 0;

		snprintf(xml, sizeof(xml),
		    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
		    "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
		    "<plist version=\"1.0\">\n"
		    "<array>\n"
		    "<integer>%s</integer>\n"
		    "</array>\n"
		    "</plist>\n", df2230_vals[i]);

		pa = prop_array_internalize(xml);
		ok = (pa != NULL);
		o = NULL;
		if (ok) {
			cnt = prop_array_count(pa);
			o = prop_array_get(pa, 0);
			if (o != NULL &&
			    prop_object_type(o) == PROP_TYPE_NUMBER) {
				isu = prop_number_unsigned(o);
				sv = prop_number_integer_value(o);
				uv = prop_number_unsigned_integer_value(o);
			} else {
				o = NULL;
			}
		}
		printf("DF2230|U|in=%s|array=%d|cnt=%d|elem=%s|is_unsigned=%d|"
		    "signed=%lld (0x%llx)|unsigned=%llu (0x%llx)\n",
		    df2230_vals[i], ok, cnt, o ? "yes" : "NO", isu,
		    (long long)sv, (unsigned long long)sv,
		    (unsigned long long)uv, (unsigned long long)uv);
		if (ok)
			prop_object_release(pa);
	}
	printf("DF2230|U|END\n");
	return (0);
}