#include <stdio.h>
+#include <errno.h>
#include <getopt.h>
#include <string.h>
#include <stdlib.h>
+#include <stdint.h>
#include <ctype.h>
#include <unistd.h>
#include <system_info.h>
return 0;
}
-static size_t get_file_size(FILE* file)
+static off_t get_file_size(FILE* file)
{
fseek(file, 0, SEEK_END);
- size_t size = ftell(file);
+ off_t size = ftello(file);
+ if (size == -1)
+ ERR_ERRNO("File size check error.");
+
fseek(file, 0 , SEEK_SET);
return size;
}
size_t read_size = get_file_size(read_file);
- char* read_buf = (char*)malloc(read_size);
+ // It doesn't matter if it's because of an error or anything else, if the returned
+ // value is equal to SIZE_MAX then we have to stop executing the function.
+ if (read_size == SIZE_MAX)
+ return -1;
+
+ char* read_buf = (char*)malloc(read_size+1);
if (read_buf == NULL) {
ERR_ERRNO("malloc()");
return -1;
free(read_buf);
return -1;
}
+ read_buf[read_size] = '\0';
const char* separators = " =\n\"";
char* read_word = strtok(read_buf, separators);
static int compare_info_files(FILE* update_info_file, FILE* device_info_file, bool verbose_output)
{
+ int ret = 0;
size_t update_info_size, device_info_size;
+ char* device_read_buf = NULL;
+ char* update_read_buf = NULL;
+ char** device_strings = NULL;
+ char** update_strings = NULL;
+ int device_file_lines = 0;
+ int update_file_lines = 0;
+
update_info_size = get_file_size(update_info_file);
+ if (update_info_size == SIZE_MAX) {
+ ERR("Error checking size of the update_info file");
+ ret = -1;
+ goto cleanup;
+ }
device_info_size = get_file_size(device_info_file);
+ if (device_info_size == SIZE_MAX) {
+ ERR("Error checking size of the device_info file");
+ ret = -1;
+ goto cleanup;
+ }
// if there are no variables in update-info.ini file, delta should pass verification
if (update_info_size == 0) {
return 0;
}
- int ret = 0;
- char* device_read_buf = NULL;
- char* update_read_buf = NULL;
- char** device_strings = NULL;
- char** update_strings = NULL;
- int device_file_lines = 0;
- int update_file_lines = 0;
-
update_read_buf = (char*)malloc(update_info_size + 1);
if (update_read_buf == NULL) {
ERR_ERRNO("malloc()");
/* Check storage have delta.tar */
storage_delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILENAME, NULL);
+ if (storage_delta_path == NULL) {
+ _FLOGI("Memory allocation error for storage delta path.");
+ goto verify_destroy;
+ }
if (!g_file_test(storage_delta_path, G_FILE_TEST_EXISTS)) {
gchar *tmp_storage_delta_path = storage_delta_path;
storage_delta_path = g_strconcat(tmp_storage_delta_path, ".gz", NULL);
}
/* Check storage have appropriate delta */
- if (check_is_delta_appropriate(storage_delta_path, NULL) != 0) {
- ret = -1;
+ if (check_is_delta_appropriate(storage_delta_path, NULL) != 0)
goto verify_destroy;
- }
_FLOGI("Success to find delta from storage(%s)", storage_delta_path);
is_appropriate = true;