XMALLOC(MTYPE_PCEP, sizeof(struct pcc_opts));
memcpy(&pcc_opts_copy->addr,
&pce_opts_cli->pce_opts.config_opts.source_ip,
- sizeof(struct pcc_opts));
+ sizeof(pcc_opts_copy->addr));
pcc_opts_copy->msd = pcc_msd_g;
pcc_opts_copy->port = pce_opts_cli->pce_opts.config_opts.source_port;
if (pcep_ctrl_update_pcc_options(pcep_g->fpt, pcc_opts_copy)) {
message_length +=
pcep_encode_object(node->data, versioning,
message_buffer + message_length);
- if (message_length > PCEP_MESSAGE_LENGTH) {
+ if (message_length >= PCEP_MESSAGE_LENGTH) {
message->encoded_message = NULL;
message->encoded_message_length = 0;
return;
msg_length = pcep_decode_msg_header(msg_buf, &msg_version, &msg_flags,
&msg_type);
+ if (msg_length == 0) {
+ pcep_log(LOG_INFO, "%s: Discarding empty message", __func__);
+ return NULL;
+ }
+ if (msg_length >= PCEP_MESSAGE_LENGTH) {
+ pcep_log(LOG_INFO, "%s: Discarding message too big", __func__);
+ return NULL;
+ }
struct pcep_message *msg =
pceplib_calloc(PCEPLIB_MESSAGES, sizeof(struct pcep_message));
ipv6 = pceplib_malloc(PCEPLIB_MESSAGES,
sizeof(struct in6_addr));
- decode_ipv6(uint32_ptr + LENGTH_4WORDS, ipv6);
+ decode_ipv6(uint32_ptr + 4, ipv6);
dll_append(sr_subobj->nai_list, ipv6);
read_count += LENGTH_8WORDS;
struct in_addr *ipv4 =
pceplib_malloc(PCEPLIB_MESSAGES,
sizeof(struct in_addr));
- ipv4->s_addr = uint32_ptr[LENGTH_4WORDS];
+ ipv4->s_addr = uint32_ptr[4];
dll_append(sr_subobj->nai_list, ipv4);
ipv6 = pceplib_malloc(PCEPLIB_MESSAGES,
sizeof(struct in6_addr));
- decode_ipv6(uint32_ptr + LENGTH_5WORDS, ipv6);
+ decode_ipv6(uint32_ptr + 5, ipv6);
dll_append(sr_subobj->nai_list, ipv6);
ipv4 = pceplib_malloc(PCEPLIB_MESSAGES,
sizeof(struct in_addr));
- ipv4->s_addr = uint32_ptr[LENGTH_9WORDS];
+ ipv4->s_addr = uint32_ptr[9];
dll_append(sr_subobj->nai_list, ipv4);
read_count += LENGTH_10WORDS;
(normalize_pcep_tlv_length(pol_name_length) > MAX_POLICY_NAME)
? MAX_POLICY_NAME
: pol_name_length;
- memcpy(tlv->name, pol_name, pol_name_length);
+ memcpy(tlv->name, pol_name, length);
tlv->name_length = length;
return tlv;
uint16_t length = (data_length > MAX_ARBITRARY_SIZE)
? MAX_ARBITRARY_SIZE
: data_length;
- memcpy(tlv->data, data, data_length);
+ memcpy(tlv->data, data, length);
tlv->data_length = length;
tlv->arbitraty_type = tlv_id;
uint16_t buf_index = normalize_pcep_tlv_length(
TLV_HEADER_LENGTH + LENGTH_1WORD + num_psts);
while ((tlv->header.encoded_tlv_length - buf_index) > TLV_HEADER_LENGTH
- && num_iterations++ > MAX_ITERATIONS) {
+ && num_iterations++ < MAX_ITERATIONS) {
struct pcep_object_tlv_header *sub_tlv =
pcep_decode_tlv(tlv_body_buf + buf_index);
if (sub_tlv == NULL) {
double_linked_list *pcep_msg_read(int sock_fd)
{
int ret;
- uint8_t buffer[PCEP_MAX_SIZE] = {0};
+ uint8_t buffer[PCEP_MESSAGE_LENGTH] = {0};
uint16_t buffer_read = 0;
- ret = read(sock_fd, &buffer, PCEP_MAX_SIZE);
+ ret = read(sock_fd, &buffer, PCEP_MESSAGE_LENGTH);
if (ret < 0) {
pcep_log(
double_linked_list *msg_list = dll_initialize();
struct pcep_message *msg = NULL;
- while ((ret - buffer_read) >= MESSAGE_HEADER_LENGTH) {
+ while (((uint16_t)ret - buffer_read) >= MESSAGE_HEADER_LENGTH) {
/* Get the Message header, validate it, and return the msg
* length */
- int32_t msg_hdr_length =
+ int32_t msg_length =
pcep_decode_validate_msg_header(buffer + buffer_read);
- if (msg_hdr_length < 0) {
+ if (msg_length < 0 || msg_length > PCEP_MESSAGE_LENGTH) {
/* If the message header is invalid, we cant keep
* reading since the length may be invalid */
pcep_log(
return msg_list;
}
- /* Check if the msg_hdr_length is longer than what was read,
+ /* Check if the msg_length is longer than what was read,
* in which case, we need to read the rest of the message. */
- if ((ret - buffer_read) < msg_hdr_length) {
- int read_len = (msg_hdr_length - (ret - buffer_read));
+ if ((ret - buffer_read) < msg_length) {
+ int read_len = (msg_length - (ret - buffer_read));
int read_ret = 0;
pcep_log(
LOG_INFO,
"%s: pcep_msg_read: Message not fully read! Trying to read %d bytes more, fd [%d]",
__func__, read_len, sock_fd);
- read_ret = read(sock_fd, &buffer[ret], read_len);
+ if (PCEP_MESSAGE_LENGTH - ret - buffer_read >= read_len )
+ read_ret =
+ read(sock_fd, &buffer[ret], read_len);
+ else {
+ pcep_log(
+ LOG_ERR,
+ "%s: Trying to read size (%d) offset (%d) in a buff of size (%d)",
+ __func__, read_len, ret, PCEP_MESSAGE_LENGTH);
+ return msg_list;
+ }
if (read_ret != read_len) {
pcep_log(
}
msg = pcep_decode_message(buffer + buffer_read);
- buffer_read += msg_hdr_length;
+ buffer_read += msg_length;
if (msg == NULL) {
return msg_list;
if (msg == NULL) {
return 0;
}
+ int msg_length = ntohs(msg->encoded_message_length);
+ if (msg_length > PCEP_MESSAGE_LENGTH) {
+ pcep_log(LOG_ERR, "%s: Not sended, size(% d) exceed max(% d) ",
+ __func__, msg_length, PCEP_MESSAGE_LENGTH);
+ return 0;
+ }
- return write(sock_fd, msg->encoded_message,
- ntohs(msg->encoded_message_length));
+ return write(sock_fd, msg->encoded_message, msg_length);
}
pcep_log(LOG_WARNING,
"%s: send_pce_report_message SRP object was NULL",
__func__);
+ dll_destroy_with_data(report_list);
return;
}
dll_append(report_list, obj);
pcep_log(LOG_WARNING,
"%s: send_pce_report_message LSP object was NULL",
__func__);
+ dll_destroy_with_data(report_list);
return;
}
dll_append(report_list, obj);
pcep_log(LOG_WARNING,
"%s: send_pce_report_message ERO object was NULL",
__func__);
+ dll_destroy_with_data(report_list);
return;
}
dll_append(report_list, obj);
memset(session_logic_handle_, 0, sizeof(pcep_session_logic_handle));
session_logic_handle_->active = true;
- session_logic_handle_->session_logic_condition = false;
session_logic_handle_->session_list =
ordered_list_initialize(pointer_compare_function);
session_logic_handle_->session_event_queue = queue_initialize();
return false;
}
+ pthread_mutex_lock(&(session_logic_handle_->session_logic_mutex));
+ session_logic_handle_->session_logic_condition = true;
+ pthread_cond_signal(&(session_logic_handle_->session_logic_cond_var));
+ pthread_mutex_unlock(&(session_logic_handle_->session_logic_mutex));
+
if (pthread_mutex_init(&(session_logic_handle_->session_list_mutex),
NULL)
!= 0) {
dll_append(
tlv_list,
pcep_tlv_create_stateful_pce_capability(
+ /* U flag */
session->pcc_config
- .support_stateful_pce_lsp_update, /* U
- flag
- */
- session->pcc_config
- .support_include_db_version, /* S flag
- */
- session->pcc_config
- .support_lsp_triggered_resync, /* T flag
- */
- session->pcc_config
- .support_lsp_delta_sync, /* D flag */
- session->pcc_config
- .support_pce_triggered_initial_sync, /* F flag */
+ .support_stateful_pce_lsp_update,
+ /* S flag */
+ session->pcc_config.support_include_db_version,
+ /* I flag */
session->pcc_config
- .support_pce_lsp_instantiation)); /* I
- flag
- */
+ .support_pce_lsp_instantiation,
+ /* T flag */
+ session->pcc_config.support_lsp_triggered_resync,
+ /* D flag */
+ session->pcc_config.support_lsp_delta_sync,
+ /* F flag */
+ session->pcc_config.support_pce_triggered_initial_sync));
}
if (session->pcc_config.support_include_db_version) {
} else if (msg_list->num_entries == 0) {
/* Invalid message received */
increment_unknown_message(session);
+ dll_destroy_with_data(msg_list);
} else {
/* Just logging the first of potentially several messages
* received */
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include "pcep_msg_encoding.h"
#include "pcep_session_logic.h"
struct pcep_object_open *open_obj =
(struct pcep_object_open *)pcep_obj_get(open_msg->obj_list,
PCEP_OBJ_CLASS_OPEN);
+ // open_msg can not have empty obj_list
+ assert(open_obj != NULL);
if (error_open_obj->open_deadtimer
!= session->pce_config.dead_timer_seconds) {
#include <stddef.h>
#include <string.h>
#include <unistd.h>
+#include <assert.h>
#include "pcep_socket_comm_internals.h"
#include "pcep_socket_comm_loop.h"
comm_session = (pcep_socket_comm_session *)node->data;
if (comm_session->socket_fd > max_fd) {
max_fd = comm_session->socket_fd;
+ } else if (comm_session->socket_fd < 0) {
+ pcep_log(LOG_ERR, "%s: Negative fd", __func__);
+ assert(comm_session->socket_fd > 0);
}
/*pcep_log(LOG_DEBUG, ld] socket_comm::build_fdSets set
comm_session = (pcep_socket_comm_session *)node->data;
if (comm_session->socket_fd > max_fd) {
max_fd = comm_session->socket_fd;
+ } else if (comm_session->socket_fd < 0) {
+ pcep_log(LOG_ERR, "%s: Negative fd", __func__);
+ assert(comm_session->socket_fd > 0);
}
/*pcep_log(LOG_DEBUG, "%s: [%ld] socket_comm::build_fdSets set
/* Test IPv4 */
struct pcep_object_rp *rp_obj =
pcep_obj_create_rp(0, false, false, false, false, 10, NULL);
- struct in_addr src_addr, dst_addr;
+ struct in_addr src_addr={}, dst_addr={};
struct pcep_object_endpoints_ipv4 *ipv4_obj =
pcep_obj_create_endpoint_ipv4(&src_addr, &dst_addr);
message = pcep_msg_create_request(rp_obj, ipv4_obj, NULL);
/* Should return NULL if obj_list is empty */
message = pcep_msg_create_update(obj_list);
CU_ASSERT_PTR_NULL(message);
+ if (message != NULL) {
+ pcep_msg_free_message(message);
+ message = NULL;
+ }
struct pcep_object_srp *srp = pcep_obj_create_srp(false, 100, NULL);
struct pcep_object_lsp *lsp =
CU_ASSERT_PTR_NULL(message);
dll_append(obj_list, ero);
+ if (message != NULL) {
+ pcep_msg_free_message(message);
+ message = NULL;
+ }
message = pcep_msg_create_update(obj_list);
CU_ASSERT_PTR_NOT_NULL(message);
pcep_encode_message(message, versioning);
/* Should return NULL if obj_list is empty */
struct pcep_message *message = pcep_msg_create_initiate(NULL);
CU_ASSERT_PTR_NULL(message);
+ if (message != NULL) {
+ pcep_msg_free_message(message);
+ message = NULL;
+ }
struct pcep_object_srp *srp = pcep_obj_create_srp(false, 100, NULL);
struct pcep_object_lsp *lsp =
dll_append(obj_list, srp);
message = pcep_msg_create_initiate(obj_list);
CU_ASSERT_PTR_NULL(message);
+ if (message != NULL) {
+ pcep_msg_free_message(message);
+ message = NULL;
+ }
dll_append(obj_list, lsp);
dll_append(obj_list, ero);
double_linked_list *list = dll_initialize();
tlv = pcep_tlv_create_speaker_entity_id(list);
CU_ASSERT_PTR_NULL(tlv);
+ if (tlv != NULL) {
+ pceplib_free(PCEPLIB_INFRA, tlv);
+ tlv = NULL;
+ }
uint32_t *speaker_entity =
pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t));
double_linked_list *pst_list = dll_initialize();
tlv = pcep_tlv_create_path_setup_type_capability(pst_list, NULL);
CU_ASSERT_PTR_NULL(tlv);
+ if (tlv != NULL) {
+ pcep_obj_free_tlv(&tlv->header);
+ tlv = NULL;
+ }
/* Should still return NULL if pst_list is NULL */
double_linked_list *sub_tlv_list = dll_initialize();
tlv = pcep_tlv_create_path_setup_type_capability(NULL, sub_tlv_list);
CU_ASSERT_PTR_NULL(tlv);
+ if (tlv != NULL) {
+ pcep_obj_free_tlv(&tlv->header);
+ tlv = NULL;
+ }
/* Should still return NULL if pst_list is empty */
tlv = pcep_tlv_create_path_setup_type_capability(pst_list,
sub_tlv_list);
CU_ASSERT_PTR_NULL(tlv);
+ if (tlv != NULL) {
+ pcep_obj_free_tlv(&tlv->header);
+ tlv = NULL;
+ }
/* Test only populating the pst list */
uint8_t *pst1 = pceplib_malloc(PCEPLIB_MESSAGES, 1);
tlv = pcep_tlv_create_path_setup_type_capability(pst_list,
sub_tlv_list);
CU_ASSERT_PTR_NOT_NULL(tlv);
+ if (tlv == NULL) {
+ CU_ASSERT_TRUE(tlv != NULL);
+ return;
+ }
pcep_encode_tlv(&tlv->header, versioning, tlv_buf);
CU_ASSERT_EQUAL(tlv->header.type,
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
#include <CUnit/CUnit.h>
int convert_hexstrs_to_binary(const char *hexbyte_strs[],
uint16_t hexbyte_strs_length)
{
- int fd = fileno(tmpfile());
+ mode_t oldumask;
+ oldumask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
+ /* Set umask before anything for security */
+ umask(0027);
+ char tmpfile[] = "/tmp/pceplib_XXXXXX";
+ int fd = mkstemp(tmpfile);
+ umask(oldumask);
+ if (fd == -1)
+ return -1;
int i = 0;
for (; i < hexbyte_strs_length; i++) {
{
int fd = convert_hexstrs_to_binary(pcep_initiate_hexbyte_strs,
pcep_initiate_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
{
int fd = convert_hexstrs_to_binary(pcep_initiate2_hexbyte_strs,
pcep_initiate2_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
{
int fd = convert_hexstrs_to_binary(pcep_open_odl_hexbyte_strs,
pcep_open_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
{
int fd = convert_hexstrs_to_binary(pcep_update_hexbyte_strs,
pcep_update_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
int fd = convert_hexstrs_to_binary(
pcep_open_initiate_odl_hexbyte_strs,
pcep_open_initiate_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 2);
int fd = convert_hexstrs_to_binary(
pcep_open_cisco_pce_hexbyte_strs,
pcep_open_cisco_pce_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
int fd = convert_hexstrs_to_binary(
pcep_update_cisco_pce_hexbyte_strs,
pcep_update_cisco_pce_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
int fd = convert_hexstrs_to_binary(
pcep_report_cisco_pcc_hexbyte_strs,
pcep_report_cisco_pcc_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
int fd = convert_hexstrs_to_binary(
pcep_initiate_cisco_pcc_hexbyte_strs,
pcep_initiate_cisco_pcc_hexbyte_strs_length);
+ if(fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
double_linked_list *msg_list = pcep_msg_read(fd);
CU_ASSERT_PTR_NOT_NULL(msg_list);
CU_ASSERT_EQUAL(msg_list->num_entries, 1);
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <CUnit/CUnit.h>
PCEPLIB_INFRA, sizeof(pcep_session_logic_handle));
memset(session_logic_handle_, 0, sizeof(pcep_session_logic_handle));
session_logic_handle_->active = true;
- session_logic_handle_->session_logic_condition = false;
session_logic_handle_->session_list =
ordered_list_initialize(pointer_compare_function);
session_logic_handle_->session_event_queue = queue_initialize();
pthread_mutex_init(&(session_logic_handle_->session_logic_mutex), NULL);
pthread_mutex_init(&(session_logic_handle_->session_list_mutex), NULL);
+ pthread_mutex_lock(&(session_logic_handle_->session_logic_mutex));
+ session_logic_handle_->session_logic_condition = true;
+ pthread_cond_signal(&(session_logic_handle_->session_logic_cond_var));
+ pthread_mutex_unlock(&(session_logic_handle_->session_logic_mutex));
+
session_logic_event_queue_ =
pceplib_malloc(PCEPLIB_INFRA, sizeof(pcep_event_queue));
memset(session_logic_event_queue_, 0, sizeof(pcep_event_queue));
/* Read from an empty file should return 0, thus
* session_logic_msg_ready_handler returns -1 */
- int fd = fileno(tmpfile());
+ mode_t oldumask;
+ oldumask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
+ /* Set umask before anything for security */
+ umask(0027);
+ char tmpfile[] = "/tmp/pceplib_XXXXXX";
+ int fd = mkstemp(tmpfile);
+ umask(oldumask);
+ if (fd == -1){
+ CU_ASSERT_TRUE(fd>=0);
+ return;
+ }
pcep_session session;
memset(&session, 0, sizeof(pcep_session));
session.session_id = 100;
timer->data = timer;
// Set the timer to expire 10 seconds ago
timer->expire_time = time(NULL) - 10;
+ pthread_mutex_lock(&test_timers_context->timer_list_lock);
timer->timer_id = TEST_EVENT_LOOP_TIMER_ID;
+ pthread_mutex_unlock(&test_timers_context->timer_list_lock);
ordered_list_add_node(test_timers_context->timer_list, timer);
walk_and_process_timers(test_timers_context);