From 641a98fc37222861b1930c5a33a92b2e428301aa Mon Sep 17 00:00:00 2001 From: suvendhu Date: Fri, 4 Nov 2022 10:18:21 +0530 Subject: [PATCH] Fix vendor log upload --- src/common.h | 4 ++-- src/cwmp.c | 4 ++-- src/rpc.c | 4 ++-- src/upload.c | 32 +++++++++++++++++++++++++------- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/common.h b/src/common.h index 7f37fa1..f9090bd 100644 --- a/src/common.h +++ b/src/common.h @@ -63,8 +63,8 @@ #define MAX_NBRE_SERVICES 256 #define FIREWALL_CWMP "/etc/firewall.cwmp" #define CWMP_VARSTATE_UCI_PACKAGE "/var/state/cwmp" -#define DM_PPP_INTERFACE_PATH "Device.PPP.Interface." -#define DM_IP_INTERFACE_PATH "Device.IP.Interface." +#define DM_PPP_INTERFACE_PATH "Device\\.PPP\\.Interface\\." +#define DM_IP_INTERFACE_PATH "Device\\.IP\\.Interface\\." #define foreach_elt_in_strlist(elt, str, delim) \ char *tmpchr; \ diff --git a/src/cwmp.c b/src/cwmp.c index 48ee0f1..6b42b29 100644 --- a/src/cwmp.c +++ b/src/cwmp.c @@ -50,8 +50,8 @@ static bool interface_reset_req(char *param_name, char *value) if (param_name == NULL || value == NULL) return false; - char reg_exp[60] = {0}; - snprintf(reg_exp, sizeof(reg_exp), "^(%s|%s)[0-9]+.Reset$", DM_IP_INTERFACE_PATH, DM_PPP_INTERFACE_PATH); + char reg_exp[100] = {0}; + snprintf(reg_exp, sizeof(reg_exp), "^(%s|%s)[0-9]+\\.Reset$", DM_IP_INTERFACE_PATH, DM_PPP_INTERFACE_PATH); if (match_reg_exp(reg_exp, param_name) == false) return false; diff --git a/src/rpc.c b/src/rpc.c index 03daf53..60baacc 100755 --- a/src/rpc.c +++ b/src/rpc.c @@ -407,8 +407,8 @@ end: static int validate_inform_parameter_name(struct list_head *parameters_values_list) { struct cwmp_dm_parameter *param_value = NULL; - char reg_exp[65] = {0}; - snprintf(reg_exp, sizeof(reg_exp), "^Device.ManagementServer.InformParameter.[0-9]+.ParameterName$"); + char reg_exp[100] = {0}; + snprintf(reg_exp, sizeof(reg_exp), "^Device\\.ManagementServer\\.InformParameter\\.[0-9]+\\.ParameterName$"); list_for_each_entry(param_value, parameters_values_list, list) { if (param_value->name == NULL || param_value->value == NULL) diff --git a/src/upload.c b/src/upload.c index e9e1df5..6a5e742 100644 --- a/src/upload.c +++ b/src/upload.c @@ -79,10 +79,17 @@ int upload_file(const char *file_path, const char *url, const char *username, co CWMP_LOG(ERROR, "upload %s: url is null", __FUNCTION__); return -1; } + if (file_path == NULL) { - file_path = "/tmp/upload_file"; + CWMP_LOG(ERROR, "upload file name unknown"); + return -1; } - stat(file_path, &file_info); + + if (0 != stat(file_path, &file_info)) { + CWMP_LOG(ERROR, "upload file %s not exists", file_path); + return -1; + } + fd_upload = fopen(file_path, "rb"); if (fd_upload == NULL) { CWMP_LOG(ERROR, "Failed to open url[%s] for upload", file_path); @@ -199,12 +206,20 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans cwmp_uci_export(file_path, UCI_STANDARD_CONFIG); cwmp_uci_exit(); } else if (pupload->file_type[0] == '2') { - snprintf(file_path, sizeof(file_path), "/tmp/syslog"); - copy("/var/log/syslog", file_path); + lookup_vlf_name(1, &name); + if (name && strlen(name) > 0) { + snprintf(file_path, sizeof(file_path), "/tmp/messages"); + // cppcheck-suppress uninitvar + if (copy(name, file_path) != 0) { + error = FAULT_CPE_UPLOAD_FAILURE; + FREE(name); + } + FREE(name); + } else + error = FAULT_CPE_UPLOAD_FAILURE; } else if (pupload->file_type[0] == '3') { lookup_vcf_name(pupload->f_instance, &name); if (name && strlen(name) > 0) { - // cppcheck-suppress uninitvar snprintf(file_path, sizeof(file_path), "/tmp/%s", name); cwmp_uci_init(); cwmp_uci_export_package(name, file_path, UCI_STANDARD_CONFIG); @@ -217,8 +232,11 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans } else { //file_type is 4 lookup_vlf_name(pupload->f_instance, &name); if (name && strlen(name) > 0) { - snprintf(file_path, sizeof(file_path), "/tmp/%s", name); - copy(name, file_path); + snprintf(file_path, sizeof(file_path), "/tmp/.cwmp_upload"); + if (copy(name, file_path) != 0) { + error = FAULT_CPE_UPLOAD_FAILURE; + FREE(name); + } FREE(name); } else error = FAULT_CPE_UPLOAD_FAILURE;