mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 14:25:44 +00:00
Bug fix: uninitialized padding eliminated (#137)
This commit is contained in:
parent
0a20d69537
commit
515129cccc
13
extend.c
13
extend.c
@ -49,17 +49,23 @@ int mode_add_get(struct sockaddr_ina *dst, int m)
|
|||||||
{
|
{
|
||||||
// m < 0: get, m > 0: set, m == 0: delete
|
// m < 0: get, m > 0: set, m == 0: delete
|
||||||
assert(m >= -1 && m < params.dp_count);
|
assert(m >= -1 && m < params.dp_count);
|
||||||
struct {
|
#pragma pack(push,4)
|
||||||
|
struct key_struct {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
uint16_t pad0; // fill with 0 before use!
|
||||||
union {
|
union {
|
||||||
struct in_addr i4;
|
struct in_addr i4;
|
||||||
struct in6_addr i6;
|
struct in6_addr i6;
|
||||||
};
|
};
|
||||||
} key = { .port = dst->in.sin_port };
|
} key = { .port = dst->in.sin_port, .pad0 = 0 };
|
||||||
|
#pragma pack(pop)
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
_Static_assert(offsetof(struct key_struct, i4) == sizeof(key.port)+sizeof(key.pad0), "key_struct");
|
||||||
|
#endif
|
||||||
|
|
||||||
time_t t = 0;
|
time_t t = 0;
|
||||||
struct elem *val = 0;
|
struct elem *val = 0;
|
||||||
int len = sizeof(dst->in.sin_port);
|
int len = offsetof(struct key_struct, i4);
|
||||||
|
|
||||||
if (dst->sa.sa_family == AF_INET) {
|
if (dst->sa.sa_family == AF_INET) {
|
||||||
len += sizeof(dst->in.sin_addr);
|
len += sizeof(dst->in.sin_addr);
|
||||||
@ -101,7 +107,6 @@ int mode_add_get(struct sockaddr_ina *dst, int m)
|
|||||||
val->time = t;
|
val->time = t;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user