11
12 /*
13 * Copyright (c) 2017, Joyent, Inc.
14 */
15
16 /*
17 * Test various error cases all of which should return EFAULT.
18 */
19
20 #include <stdio.h>
21 #include <errno.h>
22 #include <strings.h>
23 #include <err.h>
24 #include <libsff.h>
25 #include <unistd.h>
26 #include <sys/mman.h>
27
28 int
29 main(void)
30 {
31 int ret;
32 void *addr;
33 nvlist_t *nvl;
34 size_t len = getpagesize();
35
36 /*
37 * Get an unreadable page
38 */
39 if ((addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE | MAP_ANON, -1,
40 0)) == MAP_FAILED) {
41 err(1, "TEST FAILED: failed to mmap private page");
42 }
43
44 if (mprotect(addr, len, PROT_NONE) != 0) {
45 err(1, "TEST FAILED: failed to protect private page");
46 }
47
48 if ((ret = libsff_parse(addr, 128, 0xa0, &nvl)) != EFAULT) {
49 errx(1, "TEST FAILED: failed to return EFAULT on bad"
50 "data buffer\n");
51 }
52
53 return (0);
54 }
|
11
12 /*
13 * Copyright (c) 2017, Joyent, Inc.
14 */
15
16 /*
17 * Test various error cases all of which should return EFAULT.
18 */
19
20 #include <stdio.h>
21 #include <errno.h>
22 #include <strings.h>
23 #include <err.h>
24 #include <libsff.h>
25 #include <unistd.h>
26 #include <sys/mman.h>
27
28 int
29 main(void)
30 {
31 void *addr;
32 nvlist_t *nvl;
33 size_t len = getpagesize();
34 int ret;
35
36 /*
37 * Get an unreadable page
38 */
39 if ((addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE | MAP_ANON, -1,
40 0)) == MAP_FAILED) {
41 err(1, "TEST FAILED: failed to mmap private page");
42 }
43
44 if (mprotect(addr, len, PROT_NONE) != 0) {
45 err(1, "TEST FAILED: failed to protect private page");
46 }
47
48 if ((ret = libsff_parse(addr, 128, 0xa0, &nvl)) != EFAULT) {
49 errx(1, "TEST FAILED: failed to return EFAULT on bad "
50 "data buffer (%s instead)\n", strerror(ret));
51 }
52
53 return (0);
54 }
|