[Replicant] [libsamsung-ipc] [PATCH 2/3] rfs: fix sign comparison

Joonas Kylmälä joonas.kylmala at iki.fi
Sun Nov 29 13:00:38 UTC 2020


Any idea why are we not just checking st.st_size == MD5_DIGEST_LENGTH ?
If we don't check that the data that exists on the file is not the same
length then we end up just comparing the first MD5_DIGEST_LENGTH / 16 bytes.

Joonas

Denis 'GNUtoo' Carikli:
> Without that fix, when building libsamsung-ipc under GNU/Linux
> with the "-Werror -W -Wall -Wunused -Wunused-function" CFLAGS,
> GCC and the autotools build system, we have:
>     samsung-ipc/rfs.c:115:17: error: comparison of integers
>     of different signs:
>     '__off_t' (aka 'long') and 'unsigned int' [-Werror,-Wsign-compare]
>         if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) {
>             ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     samsung-ipc/rfs.c:176:17: error: comparison of integers
>     of different signs:
>     '__off_t' (aka 'long') and 'unsigned int' [-Werror,-Wsign-compare]
>             if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) {
>                 ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     2 errors generated.
>     samsung-ipc/rfs.c:115:17: error: comparison of integers
>     of different signs:
>     '__off_t' (aka 'long') and 'unsigned int' [-Werror,-Wsign-compare]
>             if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) {
>                 ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     samsung-ipc/rfs.c:176:17: error: comparison of integers
>     of different signs:
>     '__off_t' (aka 'long') and 'unsigned int' [-Werror,-Wsign-compare]
>             if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) {
>                 ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
> ---
>  samsung-ipc/rfs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/samsung-ipc/rfs.c b/samsung-ipc/rfs.c
> index 114df99..3871b35 100644
> --- a/samsung-ipc/rfs.c
> +++ b/samsung-ipc/rfs.c
> @@ -112,7 +112,8 @@ int ipc_nv_data_md5_path_check(struct ipc_client *client)
>  		return -1;
>  	}
>  
> -	if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) {
> +	if ((unsigned long)st.st_size <
> +	    (2 * (unsigned long)sizeof(char) * MD5_DIGEST_LENGTH)) {
>  		ipc_client_log(client, "Checking nv_data md5 size failed");
>  		return -1;
>  	}
> @@ -173,7 +174,8 @@ 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 ((unsigned long)st.st_size <
> +	    (2 * (unsigned long)sizeof(char) * MD5_DIGEST_LENGTH)) {
>  		ipc_client_log(client,
>  			       "Checking nv_data backup md5 size failed");
>  		return -1;
> 


More information about the Replicant mailing list