Merge pull request #34 from dartvader316/fix-misaligned

Fix usage of some misaligned pointers
This commit is contained in:
hufrea 2024-08-05 23:14:04 +03:00 committed by GitHub
commit 4ca7fab3dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 8 deletions

View File

@ -90,7 +90,7 @@ int mode_add_get(struct sockaddr_ina *dst, int m)
}
inline bool check_port(uint16_t *p, struct sockaddr_in6 *dst)
static inline bool check_port(uint16_t *p, struct sockaddr_in6 *dst)
{
return (dst->sin6_port >= p[0]
&& dst->sin6_port <= p[1]);

View File

@ -17,6 +17,10 @@
#define ANTOHS(data, i) \
(uint16_t)((data[i] << 8) + (uint8_t)data[i + 1])
#define SHTONA(data, i, x) \
data[i] = (uint8_t)(x >> 8); \
data[i + 1] = x & 0xff;
char tls_data[517] = {
"\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\x03\x5f"
@ -137,10 +141,10 @@ int change_tls_sni(const char *host, char *buffer, size_t bsize)
|| free_sz < diff) {
return -1;
}
*(uint16_t *)(sni + 2) = htons(old_sz + diff + 5);
*(uint16_t *)(sni + 4) = htons(old_sz + diff + 3);
*(uint16_t *)(sni + 7) = htons(old_sz + diff);
*(uint16_t *)(pad + 2) = htons(free_sz - diff);
SHTONA(sni, 2, old_sz + diff + 5);
SHTONA(sni, 4, old_sz + diff + 3);
SHTONA(sni, 7, old_sz + diff);
SHTONA(pad, 2, free_sz - diff);
char *host_end = sni + 9 + old_sz;
int oth_sz = bsize - (sni_offs + 9 + old_sz);
@ -410,7 +414,7 @@ int part_tls(char *buffer, size_t bsize, ssize_t n, long pos)
memmove(buffer + 5 + pos + 5, buffer + 5 + pos, n - (5 + pos));
memcpy(buffer + 5 + pos, buffer, 3);
*(uint16_t *)(buffer + 3) = htons(pos);
*(uint16_t *)(buffer + 5 + pos + 3) = htons(r_sz - pos);
SHTONA(buffer, 3, pos);
SHTONA(buffer, 5 + pos + 3, r_sz - pos);
return 5;
}

View File

@ -274,7 +274,7 @@ int s5_get_addr(char *buffer, size_t n,
addr->in6.sin6_addr = r->i6;
}
}
addr->in.sin_port = *(uint16_t *)&buffer[o - 2];
memcpy(&addr->in.sin_port, &buffer[o - 2], sizeof(uint16_t));
return o;
}