diff --git a/backupSession.c b/backupSession.c index e767076..6fe97f2 100644 --- a/backupSession.c +++ b/backupSession.c @@ -801,7 +801,10 @@ void load_queue_event(mxml_node_t *tree, struct cwmp *cwmp) while (b) { if (mxmlGetType(b) == MXML_ELEMENT) { const char *element = mxmlGetElement(b); - + if (element == NULL) { + b = mxmlWalkNext(b, tree, MXML_NO_DESCEND); + continue; + } if (strcmp(element, "command_key") == 0) { if (idx != -1) { if (EVENT_CONST[idx].RETRY & EVENT_RETRY_AFTER_REBOOT) { diff --git a/config.c b/config.c index 0751795..d2aff6a 100755 --- a/config.c +++ b/config.c @@ -53,6 +53,8 @@ void get_dhcp_vend_info_cb(struct ubus_request *req, int type __attribute__((unu if (tb[E_VENDOR_INFO]) { char *info = blobmsg_get_string(tb[E_VENDOR_INFO]); + if (info == NULL) + info = ""; int len = strlen(info) + 1; *v_info = (char *)malloc(len); if (*v_info == NULL) diff --git a/cwmp_zlib.c b/cwmp_zlib.c index 7495fa5..8aa3ae6 100644 --- a/cwmp_zlib.c +++ b/cwmp_zlib.c @@ -63,7 +63,7 @@ int zlib_compress(char *message, unsigned char **zmsg, int *zlen, int type) if (strm_init(&strm, type)) return -1; strm.next_in = (unsigned char *)message; - strm.avail_in = strlen(message); + strm.avail_in = strlen(message ? message : ""); do { int have; strm.avail_out = CHUNK; diff --git a/datamodel_interface.c b/datamodel_interface.c index 304d4e2..c5b5c74 100755 --- a/datamodel_interface.c +++ b/datamodel_interface.c @@ -48,6 +48,10 @@ struct blob_attr *get_parameters_array(struct blob_attr *msg) struct blob_attr *cur; int rem; + if (msg == NULL) { + CWMP_LOG(ERROR, "get_parameters_array: msg is null"); + return NULL; + } blobmsg_for_each_attr(cur, msg, rem) { if (blobmsg_type(cur) == BLOBMSG_TYPE_ARRAY) { @@ -60,6 +64,10 @@ struct blob_attr *get_parameters_array(struct blob_attr *msg) char *get_status(struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "get_status: msg is null"); + return NULL; + } char *status = NULL; const struct blobmsg_policy p[1] = { { "status", BLOBMSG_TYPE_STRING } }; struct blob_attr *tb[1] = { NULL }; @@ -71,6 +79,10 @@ char *get_status(struct blob_attr *msg) int get_fault(struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "get_fault: msg is null"); + return FAULT_CPE_INTERNAL_ERROR; + } int fault = FAULT_CPE_NO_FAULT; const struct blobmsg_policy p[1] = { { "fault", BLOBMSG_TYPE_INT32 } }; struct blob_attr *tb[1] = { NULL }; @@ -134,6 +146,10 @@ int get_single_fault_from_blob_attr(struct blob_attr *msg) */ void ubus_transaction_commit_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: msg is null", __FUNCTION__); + return; + } bool *status = (bool *)req->priv; const struct blobmsg_policy p[1] = { { "status", BLOBMSG_TYPE_BOOL } }; struct blob_attr *updated_services = NULL; @@ -173,7 +189,12 @@ void ubus_transaction_commit_callback(struct ubus_request *req __attribute__((un void ubus_transaction_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: msg is null", __FUNCTION__); + return; + } bool *status = (bool *)req->priv; + const struct blobmsg_policy p[2] = { { "status", BLOBMSG_TYPE_BOOL }, { "transaction_id", BLOBMSG_TYPE_INT32 } }; struct blob_attr *tb[2] = { NULL, NULL }; blobmsg_parse(p, 2, tb, blobmsg_data(msg), blobmsg_len(msg)); @@ -184,7 +205,12 @@ void ubus_transaction_callback(struct ubus_request *req __attribute__((unused)), void ubus_transaction_status_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: msg is null", __FUNCTION__); + return; + } bool *status = (bool *)req->priv; + char *status_str = NULL; const struct blobmsg_policy p[2] = { { "status", BLOBMSG_TYPE_STRING } }; struct blob_attr *tb[2] = { NULL, NULL }; @@ -296,10 +322,16 @@ bool cwmp_transaction_status() void ubus_get_single_parameter_callback(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: msg is null", __FUNCTION__); + return; + } struct blob_attr *parameters = get_parameters_array(msg); struct cwmp_dm_parameter *result = (struct cwmp_dm_parameter *)req->priv; + if (parameters == NULL) { int fault_code = get_fault(msg); + CWMP_LOG(ERROR, "dm_iface %s: returned parameters is null fault: %d", __FUNCTION__, fault_code); result->name = NULL; result->type = NULL; icwmp_asprintf(&result->value, "%d", fault_code); @@ -390,11 +422,17 @@ int cwmp_get_leaf_value(char *leaf, char **value) */ void ubus_get_parameter_callback(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: msg is null", __FUNCTION__); + return; + } struct blob_attr *parameters = get_parameters_array(msg); struct list_params_result *result = (struct list_params_result *)req->priv; + int fault_code = FAULT_CPE_NO_FAULT; if (parameters == NULL) { fault_code = get_fault(msg); + CWMP_LOG(ERROR, "dm_iface %s: parameters is null fault: %d", __FUNCTION__, fault_code); snprintf(result->fault, 5, "%d", fault_code); result->type = FAULT; return; @@ -477,9 +515,10 @@ char *cwmp_get_parameter_names(char *object_name, bool next_level, struct list_h struct cwmp *cwmp = &cwmp_main; struct blob_buf b = { 0 }; + char *object = object_name ? object_name : ""; memset(&b, 0, sizeof(struct blob_buf)); blob_buf_init(&b, 0); - bb_add_string(&b, "path", object_name); + bb_add_string(&b, "path", object); blobmsg_add_u8(&b, "next-level", next_level); bb_add_string(&b, "proto", "cwmp"); blobmsg_add_u32(&b, "instance_mode", cwmp->conf.instance_mode); @@ -506,6 +545,10 @@ char *cwmp_get_parameter_names(char *object_name, bool next_level, struct list_h void ubus_setm_values_callback(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: msg is null", __FUNCTION__); + return; + } struct setm_values_res *set_result = (struct setm_values_res *)req->priv; const struct blobmsg_policy p[2] = { { "status", BLOBMSG_TYPE_BOOL }, { "flag", BLOBMSG_TYPE_INT64 } }; struct blob_attr *tb[2] = { NULL, NULL }; @@ -520,6 +563,10 @@ void ubus_setm_values_callback(struct ubus_request *req, int type __attribute__( } set_result->status = false; struct blob_attr *faults_params = get_parameters_array(msg); + if (faults_params == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: faults_param is null", __FUNCTION__); + return; + } const struct blobmsg_policy pfault[3] = { { "path", BLOBMSG_TYPE_STRING }, { "fault", BLOBMSG_TYPE_INT32 }, { "status", BLOBMSG_TYPE_BOOL } }; struct blob_attr *cur; int rem; @@ -553,7 +600,7 @@ int cwmp_set_multiple_parameters_values(struct list_head *parameters_values_list blobmsg_close_table(&b, tbl); } blobmsg_close_array(&b, arr); - bb_add_string(&b, "key", parameter_key); + bb_add_string(&b, "key", parameter_key ? parameter_key : ""); blobmsg_add_u32(&b, "transaction_id", transaction_id); bb_add_string(&b, "proto", "cwmp"); blobmsg_add_u32(&b, "instance_mode", cwmp->conf.instance_mode); @@ -579,8 +626,16 @@ int cwmp_set_multiple_parameters_values(struct list_head *parameters_values_list void ubus_objects_callback(struct ubus_request *req, int type __attribute__((unused)), struct blob_attr *msg) { + if (msg == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: msg is null", __FUNCTION__); + return; + } int fault_code = get_single_fault_from_blob_attr(msg); struct object_result *result = (struct object_result *)req->priv; + if (result == NULL) { + CWMP_LOG(ERROR, "dm_iface %s: result is null", __FUNCTION__); + return; + } if (fault_code != FAULT_CPE_NO_FAULT) { snprintf(result->fault, 5, "%d", fault_code); result->status = false; @@ -610,8 +665,9 @@ static void prepare_add_delete_blobmsg(struct blob_buf *b, char *object_name, ch if (b == NULL) return; - bb_add_string(b, "path", object_name); - bb_add_string(b, "key", key); + char *object = CWMP_STRLEN(object_name) ? object_name : DM_ROOT_OBJ; + bb_add_string(b, "path", object); + bb_add_string(b, "key", key ? key : ""); blobmsg_add_u32(b, "transaction_id", transaction_id); bb_add_string(b, "proto", "cwmp"); blobmsg_add_u32(b, "instance_mode", cwmp_main.conf.instance_mode); diff --git a/digauth.c b/digauth.c index 4f13bb6..d4febe6 100644 --- a/digauth.c +++ b/digauth.c @@ -89,7 +89,10 @@ static void clear_param_values(void) static int get_param_index(char *key) { unsigned int i; - + if (key == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: key is null", __FUNCTION__); + return -1; + } for (i = 0; i < (sizeof(param)/sizeof(param[0])); i++) { if (strncmp(key, param[i].key, strlen(param[i].key)) == 0) return i; @@ -100,6 +103,10 @@ static int get_param_index(char *key) void strip_lead_trail_char(char *str, char ch) { + if (str == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: str is null", __FUNCTION__); + return; + } /* First remove leading strip-char */ const char* first_valid = str; @@ -124,8 +131,10 @@ static void get_hexstring(unsigned const char *hash, int len, char *hexstr, int { int i; - if (hash == NULL || hexstr == NULL) + if (hash == NULL || hexstr == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: hash or hexstr is null: %p %p", __FUNCTION__, hash, hexstr); return; + } if (buflen <= len * 2) return; @@ -144,8 +153,10 @@ static void get_hexstring(unsigned const char *hash, int len, char *hexstr, int static void get_value_from_header(const char *data) { - if (data == NULL) + if (data == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: data is null", __FUNCTION__); return; + } int header_len = strlen(data) + 1; char header[header_len]; @@ -191,13 +202,17 @@ static void get_digest_ha1(const char *algo, const char *uname, const char *rlm, MD5_CTX context; if (algo == NULL || uname == NULL || rlm == NULL || - psw == NULL || nonce == NULL || cnonce == NULL || skey == NULL) + psw == NULL || nonce == NULL || cnonce == NULL || skey == NULL) { + CWMP_LOG(ERROR, "digest_authentication an argument of the function %s is null: %p %p %p %p %p %p %p", __FUNCTION__, algo, uname, rlm, psw, nonce, cnonce, skey); return; + } int len = strlen(uname) + strlen(rlm) + strlen(psw) + 3; char *a = (char *)calloc(sizeof(char), len); - if (a == NULL) + if (a == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: a is null", __FUNCTION__); return; + } snprintf(a, len, "%s:%s:%s", uname, rlm, psw); @@ -211,8 +226,10 @@ static void get_digest_ha1(const char *algo, const char *uname, const char *rlm, if (0 == strcasecmp(algo, "md5-sess")) { len = strlen(nonce) + strlen(cnonce) + 3; a = (char *)calloc(sizeof(char), len); - if (a == NULL) + if (a == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: a is null", __FUNCTION__); return; + } snprintf(a, len, ":%s:%s", nonce, cnonce); @@ -232,13 +249,17 @@ static void get_digest_ha2(const char *method, const char *uri, char *ha2, int h unsigned char digest[MD5_DIGEST_SIZE]; MD5_CTX context; - if (method == NULL || uri == NULL || ha2 == NULL) + if (method == NULL || uri == NULL || ha2 == NULL) { + CWMP_LOG(ERROR, "digest_authentication an argument of the function %s is null: %p %p %p", __FUNCTION__, method, uri, ha2); return; + } int len = strlen(method) + strlen(uri) + 2; char *a = (char *)calloc(sizeof(char), len); - if (a == NULL) + if (a == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: a is null", __FUNCTION__); return; + } snprintf(a, len, "%s:%s", method, uri); @@ -259,13 +280,17 @@ static void get_digest_response(const char *ha1, const char *nonce, const char * unsigned char digest[MD5_DIGEST_SIZE]; if (ha1 == NULL || nonce == NULL || nonce_cnt == NULL || cnonce == NULL || - qop == NULL || ha2 == NULL || resp == NULL) + qop == NULL || ha2 == NULL || resp == NULL) { + CWMP_LOG(ERROR, "digest_authentication an argument of the function %s is null: %p %p %p %p %p %p %p", __FUNCTION__, ha1, nonce, nonce_cnt, cnonce, qop, ha2, resp); return; + } int len = strlen(nonce) + 3; char *a = (char *)calloc(sizeof(char), len); - if (a == NULL) + if (a == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: a is null", __FUNCTION__); return; + } snprintf(a, len, ":%s:", nonce); @@ -273,6 +298,7 @@ static void get_digest_response(const char *ha1, const char *nonce, const char * len = len + strlen(nonce_cnt) + strlen(cnonce) + strlen(qop) + 3; char *b = (char *)calloc(sizeof(char), len); if (b == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: b is null", __FUNCTION__); free(a); return; } @@ -299,8 +325,10 @@ static void get_nonce(uint32_t time, const char* method, const char *rand, { unsigned char ts[4]; - if (method == NULL || uri == NULL || rlm == NULL || nonce == NULL) + if (method == NULL || uri == NULL || rlm == NULL || nonce == NULL) { + CWMP_LOG(ERROR, "digest_authentication an argument of the function %s is null: %p %p %p %p", __FUNCTION__, method, uri, rlm, nonce); return; + } int i; for (i = 3; i >= 0; i--) { @@ -312,14 +340,17 @@ static void get_nonce(uint32_t time, const char* method, const char *rand, unsigned int len = strlen(method) + 3; char *meth = (char *)calloc(sizeof(char), len); - if (meth == NULL) + if (meth == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: meth is null", __FUNCTION__); return; + } snprintf(meth, len, ":%s:", method); len = strlen(uri) + strlen(rlm) + 3; char *uri_realm = (char *)calloc(sizeof(char), len); if (uri_realm == NULL) { + CWMP_LOG(ERROR, "digest_authentication %s: uri_realm is null", __FUNCTION__); free(meth); return; } @@ -348,8 +379,11 @@ static void get_nonce(uint32_t time, const char* method, const char *rand, int http_authentication_failure_resp(FILE *fp, const char *http_meth, const char *uri, const char *rlm, const char *opq) { - if (fp == NULL || http_meth == NULL || uri == NULL || rlm == NULL || opq == NULL) + if (fp == NULL || http_meth == NULL || uri == NULL || rlm == NULL || opq == NULL) { + CWMP_LOG(ERROR, "digest_authentication an argument of the function %s is null: %p %p %p %p %p", __FUNCTION__, fp, http_meth, uri, rlm, opq); return 0; + } + int len; char nonce[MD5_HASH_HEX_LEN + 9]; @@ -407,8 +441,10 @@ int validate_http_digest_auth(const char *http_meth, const char *uri, const char } if (nonce_key ==NULL) { - if (get_nonce_key() != CWMP_OK) + if (get_nonce_key() != CWMP_OK) { + CWMP_LOG(ERROR, "digest_authentication %s: fail to get nonce key", __FUNCTION__); return -1; + } } char nonce[MD5_HASH_HEX_LEN + 9]; diff --git a/event.c b/event.c index 3b1216b..9f31a9a 100644 --- a/event.c +++ b/event.c @@ -40,6 +40,10 @@ const struct EVENT_CONST_STRUCT EVENT_CONST[] = {[EVENT_IDX_0BOOTSTRAP] = { "0 B void cwmp_save_event_container(struct event_container *event_container) //to be moved to backupsession { + if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); + return; + } if (EVENT_CONST[event_container->code].RETRY & EVENT_RETRY_AFTER_REBOOT) { struct list_head *ilist; mxml_node_t *b; @@ -64,6 +68,7 @@ struct event_container *cwmp_add_event_container(struct cwmp *cwmp, int event_co struct session *session; session = cwmp_add_queue_session(cwmp); if (session == NULL) { + CWMP_LOG(ERROR, "event %s: session is null", __FUNCTION__); return NULL; } cwmp->head_event_container = &(session->head_event_container); @@ -80,15 +85,16 @@ struct event_container *cwmp_add_event_container(struct cwmp *cwmp, int event_co } event_container = calloc(1, sizeof(struct event_container)); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); return NULL; } INIT_LIST_HEAD(&(event_container->head_dm_parameter)); list_add(&(event_container->list), ilist->prev); event_container->code = event_code; event_container->command_key = command_key ? strdup(command_key) : strdup(""); - if ((cwmp->event_id < 0) || (cwmp->event_id >= MAX_INT_ID)) { + if ((cwmp->event_id < 0) || (cwmp->event_id >= MAX_INT_ID)) cwmp->event_id = 0; - } + cwmp->event_id++; event_container->id = cwmp->event_id; return event_container; @@ -102,6 +108,7 @@ void cwmp_root_cause_event_ipdiagnostic(void) pthread_mutex_lock(&(cwmp->mutex_session_queue)); event_container = cwmp_add_event_container(cwmp, EVENT_IDX_8DIAGNOSTICS_COMPLETE, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return; } @@ -119,6 +126,7 @@ int cwmp_root_cause_event_boot(struct cwmp *cwmp) cwmp->env.boot = 0; event_container = cwmp_add_event_container(cwmp, EVENT_IDX_1BOOT, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -186,6 +194,7 @@ int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp) event_container = cwmp_add_event_container(cwmp, EVENT_IDX_0BOOTSTRAP, ""); FREE(acsurl); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -204,6 +213,7 @@ int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp) pthread_mutex_lock(&(cwmp->mutex_session_queue)); event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -232,6 +242,7 @@ int cwmp_root_cause_transfer_complete(struct cwmp *cwmp, struct transfer_complet pthread_mutex_lock(&(cwmp->mutex_session_queue)); event_container = cwmp_add_event_container(cwmp, EVENT_IDX_7TRANSFER_COMPLETE, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -239,6 +250,7 @@ int cwmp_root_cause_transfer_complete(struct cwmp *cwmp, struct transfer_complet case TYPE_DOWNLOAD: event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Download, p->command_key ? p->command_key : ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -246,6 +258,7 @@ int cwmp_root_cause_transfer_complete(struct cwmp *cwmp, struct transfer_complet case TYPE_UPLOAD: event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Upload, p->command_key ? p->command_key : ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -253,6 +266,7 @@ int cwmp_root_cause_transfer_complete(struct cwmp *cwmp, struct transfer_complet case TYPE_SCHEDULE_DOWNLOAD: event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_Schedule_Download, p->command_key ? p->command_key : ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -277,12 +291,14 @@ int cwmp_root_cause_changedustate_complete(struct cwmp *cwmp, struct du_state_ch pthread_mutex_lock(&(cwmp->mutex_session_queue)); event_container = cwmp_add_event_container(cwmp, EVENT_IDX_11DU_STATE_CHANGE_COMPLETE, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } event_container = cwmp_add_event_container(cwmp, EVENT_IDX_M_ChangeDUState, p->command_key ? p->command_key : ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -306,6 +322,7 @@ int cwmp_root_cause_get_rpc_method(struct cwmp *cwmp) cwmp->env.periodic = 0; event_container = cwmp_add_event_container(cwmp, EVENT_IDX_2PERIODIC, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -441,6 +458,7 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version) cwmp_load_saved_session(cwmp, &bip, CR_IP); if (bip == NULL) { + CWMP_LOG(ERROR, "event %s: bip is null", __FUNCTION__); bkp_session_simple_insert_in_parent("connection_request", ip_version, ip_value); bkp_session_save(); return; @@ -450,6 +468,7 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version) pthread_mutex_lock(&(cwmp->mutex_session_queue)); event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); FREE(bip); pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return; @@ -473,6 +492,7 @@ void connection_request_port_value_change(struct cwmp *cwmp, int port) cwmp_load_saved_session(cwmp, &bport, CR_PORT); if (bport == NULL) { + CWMP_LOG(ERROR, "event %s: bport is null", __FUNCTION__); bkp_session_simple_insert_in_parent("connection_request", "port", bufport); bkp_session_save(); return; @@ -481,6 +501,7 @@ void connection_request_port_value_change(struct cwmp *cwmp, int port) struct event_container *event_container; event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, ""); if (event_container == NULL) { + CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__); FREE(bport); return; } diff --git a/http.c b/http.c index 1bbb2c7..62e88d7 100644 --- a/http.c +++ b/http.c @@ -229,7 +229,7 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char ** } } - if (!strlen(*msg_in)) + if (*msg_in && !strlen(*msg_in)) FREE(*msg_in); curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip); diff --git a/notifications.c b/notifications.c index 8d846ac..f4c7897 100644 --- a/notifications.c +++ b/notifications.c @@ -713,6 +713,10 @@ static void send_udp_message(struct addrinfo *servaddr, char *msg) { int fd; + if (msg == NULL) { + CWMP_LOG(ERROR, "notifications %s: msg is null", __FUNCTION__); + return; + } fd = socket(servaddr->ai_family, SOCK_DGRAM, 0); if (fd >= 0) { @@ -741,7 +745,7 @@ static void free_all_list_lw_notify() void cwmp_lwnotification() { - char msg[1024], *msg_out; + char msg[1024], *msg_out = NULL; char signature[41]; struct addrinfo *servaddr; struct cwmp *cwmp = &cwmp_main; @@ -750,6 +754,10 @@ void cwmp_lwnotification() udplw_server_param(&servaddr); xml_prepare_lwnotification_message(&msg_out); + if (msg_out == NULL) { + CWMP_LOG(ERROR, "notifications %s: msg_out is null", __FUNCTION__); + return; + } message_compute_signature(msg_out, signature, sizeof(signature)); snprintf(msg, sizeof(msg), "%s \n %s: %s \n %s: %s \n %s: %zu\n %s: %s\n\n%s", "POST /HTTPS/1.1", "HOST", conf->lw_notification_hostname, "Content-Type", "test/xml; charset=utf-8", "Content-Lenght", strlen(msg_out), "Signature", signature, msg_out);