Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions source/core/wifi_ctrl_wifiapi_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ void process_wifiapi_command(char *command, unsigned int len)
wifi_mgr_t *mgr = (wifi_mgr_t *)get_wifimgr_obj();
wifi_ctrl_t *ctrl = (wifi_ctrl_t *)get_wifictrl_obj();
FILE *json_file;
long fsize;
struct stat st;
size_t bytes_read;
char *raw = NULL;
wifi_vap_info_map_t *vap_map;
rdk_wifi_radio_t *radio;
Expand Down Expand Up @@ -753,23 +754,34 @@ void process_wifiapi_command(char *command, unsigned int len)
snprintf(buff, sizeof(buff), "%s: failed to open file '%s'", args[0], args[2]);
goto publish;
}
fseek(json_file, 0, SEEK_END);
fsize = ftell(json_file);
fseek(json_file, 0, SEEK_SET);
if (fsize == 0) {
snprintf(buff, sizeof(buff), "%s: Invalid content size (0). file '%s'", args[0], args[2]);

if (fstat(fileno(json_file), &st) != 0 || !S_ISREG(st.st_mode)) {
snprintf(buff, sizeof(buff), "%s: invalid input file type '%s'", args[0], args[2]);
fclose(json_file);
goto publish;
}

if (st.st_size <= 0) {
Comment thread
rshah-1 marked this conversation as resolved.
Resolved
snprintf(buff, sizeof(buff), "%s: invalid content size (%ld). file '%s'", args[0], (long)st.st_size, args[2]);
Comment thread
rshah-1 marked this conversation as resolved.
Resolved
fclose(json_file);
goto publish;
}
raw = malloc(fsize + 1);

raw = malloc((size_t)st.st_size + 1);
if(raw == NULL) {
snprintf(buff, sizeof(buff), "%s: failed to allocate memory", args[0]);
fclose(json_file);
goto publish;
}
fread(raw, fsize, 1, json_file);
memset(raw, 0, (size_t)st.st_size + 1);

bytes_read = fread(raw,1, (size_t)st.st_size, json_file);
Comment thread
rshah-1 marked this conversation as resolved.
Resolved
fclose(json_file);
raw[fsize] = '\0';
if (bytes_read != (size_t)st.st_size) {
snprintf(buff, sizeof(buff), "%s: failed to read complete file '%s'", args[0], args[2]);
goto publish;
}
raw[bytes_read] = '\0';

//webconfig decode
config = &ctrl->webconfig;
Expand Down Expand Up @@ -832,23 +844,34 @@ void process_wifiapi_command(char *command, unsigned int len)
snprintf(buff, sizeof(buff), "%s: failed to open file '%s'", args[0], args[2]);
goto publish;
}
fseek(json_file, 0, SEEK_END);
fsize = ftell(json_file);
fseek(json_file, 0, SEEK_SET);
if (fsize == 0) {
snprintf(buff, sizeof(buff), "%s: Invalid content size (0). file '%s'", args[0], args[2]);

if (fstat(fileno(json_file), &st) != 0 || !S_ISREG(st.st_mode)) {
snprintf(buff, sizeof(buff), "%s: invalid input file type '%s'", args[0], args[2]);
fclose(json_file);
goto publish;
}

if (st.st_size <= 0) {
Comment thread
Kondamma12345 marked this conversation as resolved.
Resolved
snprintf(buff, sizeof(buff), "%s: invalid content size (%ld). file '%s'", args[0], (long)st.st_size, args[2]);
Comment thread
rshah-1 marked this conversation as resolved.
Resolved
fclose(json_file);
goto publish;
}
raw = malloc(fsize + 1);

raw = malloc((size_t)st.st_size + 1);
if(raw == NULL) {
snprintf(buff, sizeof(buff), "%s: failed to allocate memory", args[0]);
fclose(json_file);
goto publish;
}
fread(raw, fsize, 1, json_file);
memset(raw, 0, (size_t)st.st_size + 1);

bytes_read = fread(raw, 1, (size_t)st.st_size, json_file);
fclose(json_file);
raw[fsize] = '\0';
if (bytes_read != (size_t)st.st_size) {
snprintf(buff, sizeof(buff), "%s: failed to read complete file '%s'", args[0], args[2]);
goto publish;
}
raw[bytes_read] = '\0';

//webconfig decode
config = &ctrl->webconfig;
Expand Down
Loading