blob: cde8c29222ec90828cd4a518fabf5797a24ff474 (
plain)
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
49
50
51
|
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <util.h>
#include "dhcp-protocol.h"
#include "dhcp-internal.h"
static void test_invalid_buffer_length(void)
{
DHCPMessage message;
assert(dhcp_option_parse(&message, 0, NULL, NULL) == -EINVAL);
assert(dhcp_option_parse(&message, sizeof(DHCPMessage), NULL, NULL)
== -EINVAL);
}
static void test_cookie(void)
{
DHCPMessage *message;
size_t len = sizeof(DHCPMessage) + 4;
uint8_t *opt;
message = malloc0(len);
opt = (uint8_t *)(message + 1);
opt[0] = 0xff;
assert(dhcp_option_parse(message, len, NULL, NULL) == -EINVAL);
opt[0] = 99;
opt[1] = 130;
opt[2] = 83;
opt[3] = 99;
assert(dhcp_option_parse(message, len, NULL, NULL) == -ENOMSG);
free(message);
}
int main(int argc, char *argv[])
{
test_invalid_buffer_length();
test_cookie();
return 0;
}
|