Skip to content

Commit 9532796

Browse files
Fix error reporting from pp_create_hdr(). error shall be an int32_t
1 parent d57fa2b commit 9532796

3 files changed

Lines changed: 29 additions & 23 deletions

File tree

src/proxy_protocol.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void pp_info_clear(pp_info_t *pp_info)
392392
memset(pp_info, 0, sizeof(*pp_info));
393393
}
394394

395-
uint8_t *pp2_create_hdr(const pp_info_t *pp_info, uint16_t *pp2_hdr_len, uint32_t *error)
395+
uint8_t *pp2_create_hdr(const pp_info_t *pp_info, uint16_t *pp2_hdr_len, int32_t *error)
396396
{
397397
proxy_hdr_v2_t proxy_hdr_v2 = {
398398
.sig = "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A",
@@ -479,7 +479,7 @@ uint8_t *pp2_create_hdr(const pp_info_t *pp_info, uint16_t *pp2_hdr_len, uint32_
479479
return pp2_hdr;
480480
}
481481

482-
static uint8_t *pp1_create_hdr(const pp_info_t *pp_info, uint16_t *pp1_hdr_len, uint32_t *error)
482+
static uint8_t *pp1_create_hdr(const pp_info_t *pp_info, uint16_t *pp1_hdr_len, int32_t *error)
483483
{
484484
if (pp_info->transport_protocol != TRANSPORT_PROTOCOL_STREAM)
485485
{
@@ -530,7 +530,7 @@ static uint8_t *pp1_create_hdr(const pp_info_t *pp_info, uint16_t *pp1_hdr_len,
530530
return pp1_hdr;
531531
}
532532

533-
uint8_t *pp_create_hdr(uint8_t version, const pp_info_t *pp_info, uint16_t *pp_hdr_len, uint32_t *error)
533+
uint8_t *pp_create_hdr(uint8_t version, const pp_info_t *pp_info, uint16_t *pp_hdr_len, int32_t *error)
534534
{
535535
if (version == 1)
536536
{

src/proxy_protocol.h

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ typedef struct
9797
tlv_array_t *tlv_array;
9898
} pp_info_t;
9999

100-
/* Returns a descriptive error message.
100+
/* Returns a descriptive error message
101101
*
102-
* error int32_t value from other API functions.
103-
* return Pointer to the descriptive message if error value is recognized else NULL.
102+
* error int32_t value from other API functions
103+
* return Pointer to the descriptive message if error value is recognized else NULL
104104
*/
105105
const char *pp_strerror(int32_t error);
106106

107-
/* Searches for the specified TLV and returns its value.
107+
/* Searches for the specified TLV and returns its value
108108
*
109-
* pp_info Pointer to a pp_info_t structure used in pp_parse().
110-
* length Pointer to a uint16_t where the TLV's value length will be set.
109+
* pp_info Pointer to a pp_info_t structure used in pp_parse()
110+
* length Pointer to a uint16_t where the TLV's value length will be set
111111
* return Pointer to a buffer holding the TLV's value if found else NULL.
112112
* In case of US-ASCII value the buffer is NULL terminated
113113
*/
@@ -123,28 +123,34 @@ const uint8_t *pp_info_get_ssl_key_alg(const pp_info_t *pp_info, uint16_t *lengt
123123
const uint8_t *pp_info_get_ssl_netns(const pp_info_t *pp_info, uint16_t *length);
124124
const uint8_t *pp_info_get_aws_vpce_id(const pp_info_t *pp_info, uint16_t *length);
125125
const uint8_t *pp_info_get_azure_linkid(const pp_info_t *pp_info, uint16_t *length);
126-
void pp_info_clear(pp_info_t *pp_info);
127126

128-
/* Inpects the buffer for a PROXY protocol header and extracts all the information if any.
127+
/* Clears the pp_info_t structure and frees any allocated memory associated with it. Shall always be called after a call to pp_parse_hdr()
128+
*
129+
* pp_info Pointer to a filled pp_info_t structure which has been used to a previous call to pp_parse_hdr()
130+
*/
131+
void pp_info_clear(pp_info_t *pp_info);
132+
133+
/* Creates a PROXY protocol header considering the information inside the pp_info.
129134
*
130135
* version: 0 Create a v1 PROXY protocol header
131136
* 1 Create a v2 PROXY protocol header
132-
* pp_info Pointer to a filled pp_info_t structure whose information will be used for the creation of the PROXY protocol header.
133-
* pp_hdr_len Pointer to a uint16_t where the length of the create PROXY protocol header will be set.
134-
* error Pointer to a uint32_t where the error value will be set.
137+
* pp_info Pointer to a filled pp_info_t structure whose information will be used for the creation of the PROXY protocol header
138+
* pp_hdr_len Pointer to a uint16_t where the length of the create PROXY protocol header will be set
139+
* error Pointer to a uint32_t where the error value will be set
135140
* ERR_NULL No error occurred
136141
* < 0 Error
142+
* return Pointer to a heap allocated buffer containing the PROXY protocol header. Must be freed with free()
137143
*/
138-
uint8_t *pp_create_hdr(uint8_t version, const pp_info_t *pp_info, uint16_t *pp_hdr_len, uint32_t *error);
144+
uint8_t *pp_create_hdr(uint8_t version, const pp_info_t *pp_info, uint16_t *pp_hdr_len, int32_t *error);
139145

140-
/* Inpects the buffer for a PROXY protocol header and extracts all the information if any.
146+
/* Inpects the buffer for a PROXY protocol header and extracts all the information if any
141147
*
142-
* buffer Buffer to be inspected and parsed. Typically the buffer given for a read operation
143-
* length Buffer's length. Typically the bytes read from the read operation
144-
* pp_info Pointer to a pp_info_t structure which will get filled with all the extracted information.
145-
* return > 0 Length of the PROXY protocol header.
146-
* == 0 No PROXY protocol header found.
147-
* < 0 Error occurred. pp_strerror() with that value can be used to get a descriptive message
148+
* buffer Buffer to be inspected and parsed. Typically the buffer given for a read operation
149+
* buffer_length Buffer's length. Typically the bytes read from the read operation
150+
* pp_info Pointer to a pp_info_t structure which will get filled with all the extracted information
151+
* return > 0 Length of the PROXY protocol header
152+
* == 0 No PROXY protocol header found
153+
* < 0 Error occurred. pp_strerror() with that value can be used to get a descriptive message
148154
*/
149155
int32_t pp_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t *pp_info);
150156

tests/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ int main()
406406
else
407407
{
408408
uint16_t pp_hdr_len;
409-
uint32_t error;
409+
int32_t error;
410410
uint8_t *pp_hdr = pp_create_hdr(tests[i].version, &tests[i].pp_info_in, &pp_hdr_len, &error);
411411
if (!pp_hdr || error != ERR_NULL)
412412
{

0 commit comments

Comments
 (0)