Skip to content

Commit 86362a5

Browse files
committed
bring in safe math changes in to link.c
1 parent 74e469c commit 86362a5

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

  • src/vendor/azure-uamqp-c/src

src/vendor/azure-uamqp-c/src/link.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "azure_c_shared_utility/xlogging.h"
1111
#include "azure_c_shared_utility/singlylinkedlist.h"
1212
#include "azure_c_shared_utility/tickcounter.h"
13+
#include "azure_c_shared_utility/safe_math.h"
1314
#include "azure_uamqp_c/link.h"
1415
#include "azure_uamqp_c/session.h"
1516
#include "azure_uamqp_c/amqpvalue.h"
@@ -57,7 +58,7 @@ typedef struct LINK_INSTANCE_TAG
5758
sequence_no initial_delivery_count;
5859
uint64_t max_message_size;
5960
uint64_t peer_max_message_size;
60-
int32_t current_link_credit;
61+
uint32_t current_link_credit;
6162
uint32_t max_link_credit;
6263
uint32_t available;
6364
fields attach_properties;
@@ -279,7 +280,6 @@ static int send_attach(LINK_INSTANCE* link, const char* name, handle handle, rol
279280
{
280281
(void)attach_set_properties(attach, link->attach_properties);
281282
}
282-
283283
if (link->desired_capabilities != NULL)
284284
{
285285
if(attach_set_desired_capabilities(attach, link->desired_capabilities) != 0)
@@ -413,9 +413,9 @@ static void link_frame_received(void* context, AMQP_VALUE performative, uint32_t
413413
}
414414
}
415415
}
416-
}
417416

418-
flow_destroy(flow_handle);
417+
flow_destroy(flow_handle);
418+
}
419419
}
420420
else if (is_transfer_type_by_descriptor(descriptor))
421421
{
@@ -452,10 +452,12 @@ static void link_frame_received(void* context, AMQP_VALUE performative, uint32_t
452452
/* If this is a continuation transfer or if this is the first chunk of a multi frame transfer */
453453
if ((link_instance->received_payload_size > 0) || more)
454454
{
455-
unsigned char* new_received_payload = (unsigned char*)realloc(link_instance->received_payload, link_instance->received_payload_size + payload_size);
456-
if (new_received_payload == NULL)
455+
unsigned char* new_received_payload;;
456+
size_t realloc_size = safe_add_size_t((size_t)link_instance->received_payload_size, payload_size);
457+
if (realloc_size == SIZE_MAX ||
458+
(new_received_payload = (unsigned char*)realloc(link_instance->received_payload, realloc_size)) == NULL)
457459
{
458-
LogError("Could not allocate memory for the received payload");
460+
LogError("Could not allocate memory for the received payload, size:%zu", realloc_size);
459461
}
460462
else
461463
{
@@ -1121,7 +1123,6 @@ int link_get_peer_max_message_size(LINK_HANDLE link, uint64_t* peer_max_message_
11211123

11221124
return result;
11231125
}
1124-
11251126
int link_get_desired_capabilities(LINK_HANDLE link, AMQP_VALUE* desired_capabilities)
11261127
{
11271128
int result;
@@ -1734,7 +1735,6 @@ void link_dowork(LINK_HANDLE link)
17341735
else
17351736
{
17361737
tickcounter_ms_t current_tick;
1737-
17381738
if (link->current_link_credit <= 0)
17391739
{
17401740
link->current_link_credit = link->max_link_credit;
@@ -1822,4 +1822,4 @@ void link_unsubscribe_on_link_detach_received(ON_LINK_DETACH_EVENT_SUBSCRIPTION_
18221822
event_subscription->on_link_detach_received = NULL;
18231823
event_subscription->context = NULL;
18241824
}
1825-
}
1825+
}

0 commit comments

Comments
 (0)