Skip to content

Commit 7f67724

Browse files
Proper type casts
1 parent fc76544 commit 7f67724

3 files changed

Lines changed: 54 additions & 52 deletions

File tree

src/proxy_protocol.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,17 @@ static uint8_t tlv_array_append_tlv_new_usascii(tlv_array_t *tlv_array, uint8_t
272272
return 1;
273273
}
274274

275-
uint8_t pp_info_add_alpn(pp_info_t *pp_info, uint16_t length, const void *alpn)
275+
uint8_t pp_info_add_alpn(pp_info_t *pp_info, uint16_t length, const uint8_t *alpn)
276276
{
277277
return tlv_array_append_tlv_new(&pp_info->pp2_info.tlv_array, PP2_TYPE_ALPN, length, alpn);
278278
}
279279

280-
uint8_t pp_info_add_authority(pp_info_t *pp_info, uint16_t length, const void *host_name)
280+
uint8_t pp_info_add_authority(pp_info_t *pp_info, uint16_t length, const uint8_t *host_name)
281281
{
282282
return tlv_array_append_tlv_new(&pp_info->pp2_info.tlv_array, PP2_TYPE_AUTHORITY, length, host_name);
283283
}
284284

285-
uint8_t pp_info_add_unique_id(pp_info_t *pp_info, uint16_t length, const void *unique_id)
285+
uint8_t pp_info_add_unique_id(pp_info_t *pp_info, uint16_t length, const uint8_t *unique_id)
286286
{
287287
if (length > 128)
288288
{
@@ -291,7 +291,7 @@ uint8_t pp_info_add_unique_id(pp_info_t *pp_info, uint16_t length, const void *u
291291
return tlv_array_append_tlv_new(&pp_info->pp2_info.tlv_array, PP2_TYPE_UNIQUE_ID, length, unique_id);
292292
}
293293

294-
static void pp_info_add_subtype_ssl(uint8_t *value, uint16_t *index, uint8_t subtype_ssl, uint16_t length, const uint8_t *subtype_ssl_value)
294+
static void pp_info_add_subtype_ssl(uint8_t *value, uint16_t *index, uint8_t subtype_ssl, uint16_t length, const void *subtype_ssl_value)
295295
{
296296
if (!length || !subtype_ssl_value)
297297
{
@@ -304,7 +304,7 @@ static void pp_info_add_subtype_ssl(uint8_t *value, uint16_t *index, uint8_t sub
304304
*index += length;
305305
}
306306

307-
uint8_t pp_info_add_ssl(pp_info_t *pp_info, const char *version, const char *cipher, const char *sig_alg, const char *key_alg, const char *cn, uint16_t cn_value_len)
307+
uint8_t pp_info_add_ssl(pp_info_t *pp_info, const char *version, const char *cipher, const char *sig_alg, const char *key_alg, const uint8_t *cn, uint16_t cn_value_len)
308308
{
309309
const pp2_ssl_info_t *pp2_ssl_info = &pp_info->pp2_info.pp2_ssl_info;
310310
uint8_t client = pp2_ssl_info->ssl | pp2_ssl_info->cert_in_connection << 1 | pp2_ssl_info->cert_in_connection << 2;
@@ -330,24 +330,24 @@ uint8_t pp_info_add_ssl(pp_info_t *pp_info, const char *version, const char *cip
330330
value[index++] = client;
331331
memcpy(value + index, &verify, sizeof(verify));
332332
index += sizeof(verify);
333-
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_VERSION, (uint16_t)version_value_len, version);
334-
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_CIPHER, (uint16_t)cipher_value_len, cipher);
335-
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_SIG_ALG, (uint16_t)sig_alg_value_len, sig_alg);
336-
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_KEY_ALG, (uint16_t)key_alg_value_len, key_alg);
333+
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_VERSION, (uint16_t) version_value_len, version);
334+
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_CIPHER, (uint16_t) cipher_value_len, cipher);
335+
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_SIG_ALG, (uint16_t) sig_alg_value_len, sig_alg);
336+
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_KEY_ALG, (uint16_t) key_alg_value_len, key_alg);
337337
pp_info_add_subtype_ssl(value, &index, PP2_SUBTYPE_SSL_CN, cn_value_len, cn);
338-
uint8_t rc = tlv_array_append_tlv_new(&pp_info->pp2_info.tlv_array, PP2_TYPE_SSL, (uint16_t)length, value);
338+
uint8_t rc = tlv_array_append_tlv_new(&pp_info->pp2_info.tlv_array, PP2_TYPE_SSL, (uint16_t) length, value);
339339
free(value);
340340
return rc;
341341
}
342342

343343
uint8_t pp_info_add_netns(pp_info_t *pp_info, const char *netns)
344344
{
345-
return tlv_array_append_tlv_new(&pp_info->pp2_info.tlv_array, PP2_TYPE_NETNS, (uint16_t)strlen(netns), netns);
345+
return tlv_array_append_tlv_new(&pp_info->pp2_info.tlv_array, PP2_TYPE_NETNS, (uint16_t) strlen(netns), netns);
346346
}
347347

348348
uint8_t pp_info_add_aws_vpce_id(pp_info_t *pp_info, const char *vpce_id)
349349
{
350-
uint16_t length = (uint16_t)(sizeof_pp2_tlv_aws_t + strlen(vpce_id));
350+
uint16_t length = (uint16_t) (sizeof_pp2_tlv_aws_t + strlen(vpce_id));
351351
pp2_tlv_aws_t *pp2_tlv_aws = malloc(length);
352352
pp2_tlv_aws->type = PP2_SUBTYPE_AWS_VPCE_ID;
353353
memcpy(pp2_tlv_aws->value, vpce_id, strlen(vpce_id));
@@ -356,7 +356,7 @@ uint8_t pp_info_add_aws_vpce_id(pp_info_t *pp_info, const char *vpce_id)
356356

357357
uint8_t pp_info_add_azure_linkid(pp_info_t *pp_info, uint32_t linkid)
358358
{
359-
uint16_t length = (uint16_t)sizeof(pp2_tlv_azure_t);
359+
uint16_t length = (uint16_t) sizeof(pp2_tlv_azure_t);
360360
pp2_tlv_azure_t *pp2_tlv_azure = malloc(length);
361361
pp2_tlv_azure->type = PP2_SUBTYPE_AZURE_PRIVATEENDPOINT_LINKID;
362362
pp2_tlv_azure->linkid = linkid;
@@ -761,7 +761,7 @@ uint8_t *pp_create_hdr(uint8_t version, const pp_info_t *pp_info, uint16_t *pp_h
761761
static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t *pp_info)
762762
{
763763
const uint8_t *pp2_hdr = buffer;
764-
const proxy_hdr_v2_t *proxy_hdr_v2 = (proxy_hdr_v2_t *) buffer;
764+
const proxy_hdr_v2_t *proxy_hdr_v2 = (proxy_hdr_v2_t*) buffer;
765765

766766
/* The next byte (the 13th one) is the protocol version and command */
767767
/* The highest four bits contains the version. Only \x2 is accepted */
@@ -836,7 +836,7 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
836836
* - destination layer 4 address if any, in network byte order (port)
837837
*/
838838
buffer += sizeof(proxy_hdr_v2_t);
839-
proxy_addr_t *addr = (proxy_addr_t *) buffer;
839+
proxy_addr_t *addr = (proxy_addr_t*) buffer;
840840
uint16_t tlv_vectors_len = 0;
841841
if (fam == AF_UNSPEC)
842842
{
@@ -890,7 +890,7 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
890890
/* Any TLV vector must be at least 3 bytes */
891891
while (tlv_vectors_len > 3)
892892
{
893-
pp2_tlv_t *pp2_tlv = (pp2_tlv_t *) buffer;
893+
pp2_tlv_t *pp2_tlv = (pp2_tlv_t*) buffer;
894894
uint16_t pp2_tlv_len = pp2_tlv->length_hi << 8 | pp2_tlv->length_lo;
895895
uint16_t pp2_tlv_offset = 3 + pp2_tlv_len;
896896
if (pp2_tlv_offset > tlv_vectors_len)
@@ -949,7 +949,7 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
949949
break;
950950
case PP2_TYPE_SSL:
951951
{
952-
pp2_tlv_ssl_t *pp2_tlv_ssl = (pp2_tlv_ssl_t*)pp2_tlv->value;
952+
pp2_tlv_ssl_t *pp2_tlv_ssl = (pp2_tlv_ssl_t*) pp2_tlv->value;
953953

954954
/* Set the pp2_ssl_info */
955955
pp_info->pp2_info.pp2_ssl_info.ssl = !!(pp2_tlv_ssl->client & PP2_CLIENT_SSL);
@@ -962,7 +962,7 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
962962
uint16_t pp2_sub_tlv_offset = 0;
963963
while (pp2_sub_tlv_offset < pp2_tlvs_ssl_len)
964964
{
965-
pp2_tlv_t *pp2_sub_tlv_ssl = (pp2_tlv_t * )((uint8_t*) pp2_tlv_ssl->sub_tlv + pp2_sub_tlv_offset);
965+
pp2_tlv_t *pp2_sub_tlv_ssl = (pp2_tlv_t*) ((uint8_t*) pp2_tlv_ssl->sub_tlv + pp2_sub_tlv_offset);
966966
uint16_t pp2_sub_tlv_ssl_len = pp2_sub_tlv_ssl->length_hi << 8 | pp2_sub_tlv_ssl->length_lo;
967967
switch (pp2_sub_tlv_ssl->type)
968968
{
@@ -1006,7 +1006,7 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
10061006
{
10071007
return -ERR_PP2_TYPE_AWS;
10081008
}
1009-
pp2_tlv_aws_t *pp2_tlv_aws = (pp2_tlv_aws_t *) pp2_tlv->value;
1009+
pp2_tlv_aws_t *pp2_tlv_aws = (pp2_tlv_aws_t*) pp2_tlv->value;
10101010
/* Connection is done through Private Link/Interface VPC endpoint */
10111011
if (pp2_tlv_aws->type == PP2_SUBTYPE_AWS_VPCE_ID) /* US-ASCII */
10121012
{
@@ -1024,7 +1024,7 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
10241024
{
10251025
return -ERR_PP2_TYPE_AZURE;
10261026
}
1027-
pp2_tlv_azure_t *pp2_tlv_azure = (pp2_tlv_azure_t *) pp2_tlv->value;
1027+
pp2_tlv_azure_t *pp2_tlv_azure = (pp2_tlv_azure_t*) pp2_tlv->value;
10281028
/* Connection is done through Private Link service */
10291029
if (pp2_tlv_azure->type == PP2_TYPE_AZURE) /* 32-bit number */
10301030
{

src/proxy_protocol.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ typedef struct
128128
* $value_param(s) The value(s) of the specified TLV
129129
* return 1: success 0: failure
130130
*/
131-
uint8_t pp_info_add_alpn(pp_info_t *pp_info, uint16_t length, const void *alpn);
132-
uint8_t pp_info_add_authority(pp_info_t *pp_info, uint16_t length, const void *host_name);
133-
uint8_t pp_info_add_unique_id(pp_info_t *pp_info, uint16_t length, const void *unique_id);
134-
uint8_t pp_info_add_ssl(pp_info_t *pp_info, const char *version, const char *cipher, const char *sig_alg, const char *key_alg, const char *cn, uint16_t cn_len);
131+
uint8_t pp_info_add_alpn(pp_info_t *pp_info, uint16_t length, const uint8_t *alpn);
132+
uint8_t pp_info_add_authority(pp_info_t *pp_info, uint16_t length, const uint8_t *host_name);
133+
uint8_t pp_info_add_unique_id(pp_info_t *pp_info, uint16_t length, const uint8_t *unique_id);
134+
uint8_t pp_info_add_ssl(pp_info_t *pp_info, const char *version, const char *cipher, const char *sig_alg, const char *key_alg, const uint8_t *cn, uint16_t cn_len);
135135
uint8_t pp_info_add_netns(pp_info_t *pp_info, const char *netns);
136136
uint8_t pp_info_add_aws_vpce_id(pp_info_t *pp_info, const char *vpce_id);
137137
uint8_t pp_info_add_azure_linkid(pp_info_t *pp_info, uint32_t linkid);

tests/test.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ static uint8_t pp_add_tlvs(pp_info_t *pp_info, const test_tlv_t (*add_tlvs)[10])
134134
{
135135
uint8_t i;
136136
uint8_t rc = 1;
137+
uint32_t azure_linkid = 0;
137138
uint16_t ssl_cn_len = 0;
139+
uint8_t *ssl_cn = NULL;
138140
char *ssl_version = NULL;
139-
char *ssl_cn = NULL;
140141
char *ssl_cipher = NULL;
141142
char *ssl_sig_alg = NULL;
142143
char *ssl_key_alg = NULL;
@@ -157,29 +158,30 @@ static uint8_t pp_add_tlvs(pp_info_t *pp_info, const test_tlv_t (*add_tlvs)[10])
157158
rc = pp_info_add_unique_id(pp_info, test_tlv->value_len, test_tlv->value);
158159
break;
159160
case PP2_SUBTYPE_SSL_VERSION:
160-
ssl_version = test_tlv->value;
161+
ssl_version = (char*) test_tlv->value;
161162
break;
162163
case PP2_SUBTYPE_SSL_CN:
163164
ssl_cn_len = test_tlv->value_len;
164165
ssl_cn = test_tlv->value;
165166
break;
166167
case PP2_SUBTYPE_SSL_CIPHER:
167-
ssl_cipher = test_tlv->value;
168+
ssl_cipher = (char*) test_tlv->value;
168169
break;
169170
case PP2_SUBTYPE_SSL_SIG_ALG:
170-
ssl_sig_alg = test_tlv->value;
171+
ssl_sig_alg = (char*) test_tlv->value;
171172
break;
172173
case PP2_SUBTYPE_SSL_KEY_ALG:
173-
ssl_key_alg = test_tlv->value;
174+
ssl_key_alg = (char*) test_tlv->value;
174175
break;
175176
case PP2_TYPE_NETNS:
176-
rc = pp_info_add_netns(pp_info, test_tlv->value);
177+
rc = pp_info_add_netns(pp_info, (char*) test_tlv->value);
177178
break;
178179
case PP2_TYPE_AWS:
179-
rc = pp_info_add_aws_vpce_id(pp_info, test_tlv->value);
180+
rc = pp_info_add_aws_vpce_id(pp_info, (char*) test_tlv->value);
180181
break;
181182
case PP2_TYPE_AZURE:
182-
rc = pp_info_add_azure_linkid(pp_info, (uint32_t) test_tlv->value);
183+
memcpy(&azure_linkid, (uint32_t*) test_tlv->value, sizeof(uint32_t));
184+
rc = pp_info_add_azure_linkid(pp_info, azure_linkid);
183185
break;
184186
default:
185187
break;
@@ -309,15 +311,15 @@ int main()
309311
test_t tests[] = {
310312
{
311313
.name = "v1 PROXY protocol header: UNKNOWN - short",
312-
.raw_bytes_in = (uint8_t *) "PROXY UNKNOWN\r\n",
313-
.raw_bytes_in_length = strlen((char*)tests[0].raw_bytes_in),
314-
.rc_expected = strlen((char*)tests[0].raw_bytes_in),
314+
.raw_bytes_in = (uint8_t*) "PROXY UNKNOWN\r\n",
315+
.raw_bytes_in_length = strlen((char*) tests[0].raw_bytes_in),
316+
.rc_expected = strlen((char*) tests[0].raw_bytes_in),
315317
},
316318
{
317319
.name = "v1 PROXY protocol header: UNKNOWN - full",
318-
.raw_bytes_in = (uint8_t *) "PROXY UNKNOWN ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535 65535\r\n",
319-
.raw_bytes_in_length = strlen((char *) tests[1].raw_bytes_in),
320-
.rc_expected = strlen((char *) tests[1].raw_bytes_in),
320+
.raw_bytes_in = (uint8_t*) "PROXY UNKNOWN ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535 65535\r\n",
321+
.raw_bytes_in_length = strlen((char*) tests[1].raw_bytes_in),
322+
.rc_expected = strlen((char*) tests[1].raw_bytes_in),
321323
},
322324
{
323325
.name = "v2 PROXY protocol header: PROXY, TCP over IPv4. TLVs: PP2_TYPE_CRC32C, PP2_TYPE_AWS(PP2_SUBTYPE_AWS_VPCE_ID)",
@@ -337,13 +339,13 @@ int main()
337339
{
338340
.type = PP2_TYPE_CRC32C,
339341
.value_len = 4,
340-
.value = (uint8_t*)"\xe5\x18\x86\xf8"
342+
.value = (uint8_t*) "\xe5\x18\x86\xf8"
341343
},
342344
{
343345
.type = PP2_TYPE_AWS,
344346
.subtype = PP2_SUBTYPE_AWS_VPCE_ID,
345347
.value_len = 23,
346-
.value = (uint8_t*)"vpce-23d8ezjk38bchilm4"
348+
.value = (uint8_t*) "vpce-23d8ezjk38bchilm4"
347349
},
348350
},
349351
},
@@ -446,39 +448,39 @@ int main()
446448
{
447449
.type = PP2_SUBTYPE_SSL_VERSION,
448450
.value_len = 8,
449-
.value = (uint8_t*)"TLSv1.2"
451+
.value = (uint8_t*) "TLSv1.2"
450452
},
451453
{
452454
.type = PP2_SUBTYPE_SSL_CN,
453455
.value_len = 11,
454456
/* example.com */
455-
.value = (uint8_t*)"\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d"
457+
.value = (uint8_t*) "\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d"
456458
},
457459
{
458460
.type = PP2_SUBTYPE_SSL_CIPHER,
459461
.value_len = 28,
460-
.value = (uint8_t*)"ECDHE-RSA-AES128-GCM-SHA256"
462+
.value = (uint8_t*) "ECDHE-RSA-AES128-GCM-SHA256"
461463
},
462464
{
463465
.type = PP2_SUBTYPE_SSL_SIG_ALG,
464466
.value_len = 7,
465-
.value = (uint8_t*)"SHA256"
467+
.value = (uint8_t*) "SHA256"
466468
},
467469
{
468470
.type = PP2_SUBTYPE_SSL_KEY_ALG,
469471
.value_len = 8,
470-
.value = (uint8_t*)"RSA2048"
472+
.value = (uint8_t*) "RSA2048"
471473
},
472474
{
473475
.type = PP2_TYPE_AWS,
474476
.subtype = PP2_SUBTYPE_AWS_VPCE_ID,
475477
.value_len = 23,
476-
.value = (uint8_t*)"vpce-24d8ezjk38bchilm4"
478+
.value = (uint8_t*) "vpce-24d8ezjk38bchilm4"
477479
},
478480
{
479481
.type = PP2_TYPE_CRC32C,
480482
.value_len = 4,
481-
.value = (uint8_t*)"\x72\x45\x29\xd8"
483+
.value = (uint8_t*) "\x72\x45\x29\xd8"
482484
},
483485
},
484486
.pp_info_out_expected = tests[9].pp_info_in,
@@ -509,28 +511,28 @@ int main()
509511
{
510512
.type = PP2_SUBTYPE_SSL_VERSION,
511513
.value_len = 8,
512-
.value = (uint8_t*)"TLSv1.2"
514+
.value = (uint8_t*) "TLSv1.2"
513515
},
514516
{
515517
.type = PP2_SUBTYPE_SSL_CN,
516518
.value_len = 11,
517519
/* example.com */
518-
.value = (uint8_t*)"\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d"
520+
.value = (uint8_t*) "\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d"
519521
},
520522
{
521523
.type = PP2_SUBTYPE_SSL_CIPHER,
522524
.value_len = 28,
523-
.value = (uint8_t*)"ECDHE-RSA-AES128-GCM-SHA256"
525+
.value = (uint8_t*) "ECDHE-RSA-AES128-GCM-SHA256"
524526
},
525527
{
526528
.type = PP2_SUBTYPE_SSL_SIG_ALG,
527529
.value_len = 7,
528-
.value = (uint8_t*)"SHA256"
530+
.value = (uint8_t*) "SHA256"
529531
},
530532
{
531533
.type = PP2_SUBTYPE_SSL_KEY_ALG,
532534
.value_len = 8,
533-
.value = (uint8_t*)"RSA2048"
535+
.value = (uint8_t*) "RSA2048"
534536
},
535537
},
536538
},

0 commit comments

Comments
 (0)