-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuprog_validate.c
executable file
·48 lines (40 loc) · 1.01 KB
/
uprog_validate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
char estring[256] = "HPE HACKATHON 2016!!";
int main()
{
int fd;
char *addr;
fd = open("/dev/hpehackon", O_RDWR);
if (fd == -1) {
fprintf(stderr, "failed to open the device file /dev/hpehackon\n");
exit (1);
}
addr = (char *)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (addr != MAP_FAILED) {
fprintf(stderr, "mmap should not succeed with write permission\n");
exit (1);
}
addr = (char *)mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED) {
fprintf(stderr, "failed to mmap from the device file\n");
exit (1);
}
if (strncmp(addr, estring, 256) != 0) {
fprintf(stderr, "failed to find the expected string in mmaped memory\n");
exit (1);
}
printf("%s\n", addr);
if (munmap(addr, 4096) != 0) {
fprintf(stderr, "failed to unmap the mmaped memory\n");
exit (1);
}
close(fd);
printf("Success\n");
exit(0);
}