Fix integer types 55/17755/2 accepted/tizen_generic accepted/tizen_ivi_panda sandbox/rkrypa/tizen accepted/tizen/generic/20140319.144207 accepted/tizen/ivi/20140324.170921 accepted/tizen/ivi/panda/20140321.020538 submit/tizen/20140319.141934
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 10 Mar 2014 09:13:07 +0000 (10:13 +0100)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 10 Mar 2014 09:34:49 +0000 (10:34 +0100)
[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 <l.wojciechow@partner.samsung.com>
src/common.c

index 1af350b..e145b77 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>
+#include <limits.h>
 #include <unistd.h>
 #include <sys/smack.h>
 #include <sys/stat.h>
@@ -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) {