aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoonas Kylmälä <joonas.kylmala@iki.fi>2020-12-02 15:25:44 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-12-03 01:40:28 +0100
commitc9828bb0cd3b03fc453328c62bcccd06b3517267 (patch)
tree75cb1d6bff4685d4ed7307f4567548e0617281c9
parent2cfe1119318c1b58e50dbedf6d5ceebc94cebba9 (diff)
downloadhardware_replicant_libsamsung-ipc-c9828bb0cd3b03fc453328c62bcccd06b3517267.tar.gz
hardware_replicant_libsamsung-ipc-c9828bb0cd3b03fc453328c62bcccd06b3517267.tar.bz2
hardware_replicant_libsamsung-ipc-c9828bb0cd3b03fc453328c62bcccd06b3517267.zip
samsung-ipc: rfs: fix incorrect sign comparison for md5 file length
When compiling with warnings (-Werror -W -Wall -Wunused -Wunused-function) enabled we get: rfs.c: In function ‘ipc_nv_data_md5_path_check’: rfs.c:115:17: error: comparison of integer expressions of different signedness: ‘__off_t’ {aka ‘long int’} and ‘long unsigned int’ [-Werror=sign-compare] if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) { ^ This simplifies the comparison by making sure we have exactly 32 bytes (2*MD5_DIGEST_LENGTH, i.e. md5 digest in ascii) in the file we read the MD5 digest from. Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> Tested-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> Acked-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--samsung-ipc/rfs.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/samsung-ipc/rfs.c b/samsung-ipc/rfs.c
index 114df99..93d2b6e 100644
--- a/samsung-ipc/rfs.c
+++ b/samsung-ipc/rfs.c
@@ -32,6 +32,8 @@
#include "ipc.h"
+#define MD5_DIGEST_LENGTH_ASCII (2 * MD5_DIGEST_LENGTH)
+
char *ipc_nv_data_md5_calculate(struct ipc_client *client,
const char *path, const char *secret,
size_t size, size_t chunk_size)
@@ -112,7 +114,7 @@ int ipc_nv_data_md5_path_check(struct ipc_client *client)
return -1;
}
- if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) {
+ if (st.st_size != MD5_DIGEST_LENGTH_ASCII) {
ipc_client_log(client, "Checking nv_data md5 size failed");
return -1;
}
@@ -173,7 +175,7 @@ int ipc_nv_data_backup_md5_path_check(struct ipc_client *client)
return -1;
}
- if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) {
+ if (st.st_size != MD5_DIGEST_LENGTH_ASCII) {
ipc_client_log(client,
"Checking nv_data backup md5 size failed");
return -1;
@@ -493,7 +495,7 @@ int ipc_nv_data_restore(struct ipc_client *client)
free(data);
data = NULL;
- length = 2 * sizeof(char) * MD5_DIGEST_LENGTH;
+ length = MD5_DIGEST_LENGTH_ASCII;
data = file_data_read(client, backup_md5_path, length, length, 0);
if (data == NULL) {