From 3887c2c7b94bb5473274e93f7479c572a412f9ef Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Mon, 10 Mar 2014 10:13:07 +0100 Subject: [PATCH] Fix integer types [Issue#] N/A [Feature/Bug] ssize_t, size_t and int are misused [Problem] code does not compile on 64bit platforms [Cause] N/A [Solution] use proper types, check for integer overflow [Verification] Succesfully build on 32 and 64 bit platforms Change-Id: Ia1bee500ce312f8bfc9ecc7f0577274c2db75c5e Signed-off-by: Lukasz Wojciechowski --- src/common.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/common.c b/src/common.c index 1af350b..e145b77 100644 --- a/src/common.c +++ b/src/common.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -462,9 +463,15 @@ int base_name_from_perm(const char *s_perm, char **ps_name) return PC_ERR_INVALID_PARAM; } - ssize_t i_host_size = strlen(piri_parsed->host); - ssize_t i_path_start = 0; - char * pc_host_dot = NULL; + size_t i_host_size = strlen(piri_parsed->host); + if(i_host_size > INT_MAX) { + SECURE_C_LOGE("Permission name too long : %zu", i_host_size); + iri_destroy(piri_parsed); + return PC_ERR_INVALID_PARAM; + } + + size_t i_path_start = 0; + char *pc_host_dot = NULL; if(piri_parsed->path) { pc_host_dot = strrchr(piri_parsed->host, '.'); @@ -474,7 +481,7 @@ int base_name_from_perm(const char *s_perm, char **ps_name) int ret = asprintf(ps_name, "%s%s%.*s%s", pc_host_dot ? pc_host_dot + 1 : "", pc_host_dot ? "." : "", - pc_host_dot ? pc_host_dot - piri_parsed->host : i_host_size, + pc_host_dot ? (int)(pc_host_dot - piri_parsed->host) : (int)i_host_size, piri_parsed->host, piri_parsed->path ? piri_parsed->path : ""); if (ret == -1) { -- 2.7.4