From e231e1c8c2d988cb7f5ce06090358b5ee633691a Mon Sep 17 00:00:00 2001 From: Young Ik Cho Date: Mon, 12 Aug 2013 19:41:29 +0900 Subject: [PATCH] fix osp-install crash with invalid initialization Change-Id: I657e9e5ce4b2bed92171b6f50855c29797b67efa Signed-off-by: Young Ik Cho --- appinfo/CMakeLists.txt | 2 +- appinfo/appinfo.c | 53 ++++++++++++++++++++++++++------------------------ appinfo/appinfo.h | 2 +- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/appinfo/CMakeLists.txt b/appinfo/CMakeLists.txt index e712a4d..9718a86 100644 --- a/appinfo/CMakeLists.txt +++ b/appinfo/CMakeLists.txt @@ -3,7 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(this_target appinfo) SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.1.0") +SET(VERSION "${VERSION_MAJOR}.1.1") #INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) diff --git a/appinfo/appinfo.c b/appinfo/appinfo.c index 5ea76c2..999c14a 100644 --- a/appinfo/appinfo.c +++ b/appinfo/appinfo.c @@ -35,10 +35,18 @@ #define _SECURE_LOGE(...) #endif +#ifndef likely +#define likely(x) __builtin_expect(!!(x), 1) +#endif +#ifndef unlikely +#define unlikely(x) __builtin_expect(!!(x), 0) +#endif + #ifdef __cplusplus extern "C" { #endif +static const char INVALID_EXEC_NAME[] = ""; static app_info_version_e _current_api_ver = APP_INFO_VERSION_2_2; static int _compat_mode = 0; static int _app_info_init = 0; @@ -53,7 +61,7 @@ static char __pkgid[MAX_OSP_PKGID+1]={'\0',}; static char __appid[MAX_APPID]={'\0',}; static const char* _pkgid = NULL; static const char* _appid = NULL; -static const char* _execname = NULL; +static const char* _execname = &INVALID_EXEC_NAME; /** @@ -69,7 +77,7 @@ static const char* _execname = NULL; int appinfo_init(const char* appid, int is_invalid_appid) { - if(!appid && strlen(appid) >= sizeof(__appid)) + if (!appid && strlen(appid) >= sizeof(__appid)) { return APP_INFO_ERROR_INVALID_ARG; } @@ -84,7 +92,7 @@ appinfo_init(const char* appid, int is_invalid_appid) } else { - if(strlen(appid) < sizeof(MAX_OSP_PKGID)) + if (strlen(appid) < sizeof(MAX_OSP_PKGID)) { return APP_INFO_ERROR_INVALID_ARG; } @@ -141,7 +149,7 @@ appinfo_set_api_version(int ver) app_info_version_e temp_ver; temp_ver = __get_api_version_from_str(appinfo_get_api_str_by_version(ver)); - if( temp_ver == APP_INFO_VERSION_INVALID) + if ( temp_ver == APP_INFO_VERSION_INVALID) { return APP_INFO_ERROR_INVALID_ARG; } @@ -187,40 +195,40 @@ appinfo_get_api_str_by_version(int ver) app_info_version_e appinfo_get_api_version_from_str(const char * ver_str) { - if(ver_str == NULL) + if (ver_str == NULL) { return APP_INFO_VERSION_INVALID; } - if(!strcmp(ver_str,"3.0")) + if (!strcmp(ver_str,"3.0")) { return APP_INFO_VERSION_3_0; } - else if(!strcmp(ver_str,"2.2")) + else if (!strcmp(ver_str,"2.2")) { return APP_INFO_VERSION_2_2; } - else if(!strcmp(ver_str,"2.1")) + else if (!strcmp(ver_str,"2.1")) { return APP_INFO_VERSION_2_1; } - else if(!strcmp(ver_str,"2.0")) + else if (!strcmp(ver_str,"2.0")) { return APP_INFO_VERSION_2_0; } - else if(!strcmp(ver_str,"1.2")) + else if (!strcmp(ver_str,"1.2")) { return APP_INFO_VERSION_1_2; } - else if(!strcmp(ver_str,"1.1")) + else if (!strcmp(ver_str,"1.1")) { return APP_INFO_VERSION_1_1; } - else if(!strcmp(ver_str,"1.0.2")) + else if (!strcmp(ver_str,"1.0.2")) { return APP_INFO_VERSION_1_0_2; } - else if(!strcmp(ver_str,"1.0")) + else if (!strcmp(ver_str,"1.0")) { return APP_INFO_VERSION_1_0; } @@ -252,7 +260,7 @@ appinfo_is_compat(void) int appinfo_set_compat(int compat) { - if(compat == 0 || compat == 1) + if (compat == 0 || compat == 1) { _compat_mode = compat; return APP_INFO_ERROR_NONE; @@ -269,7 +277,7 @@ appinfo_set_compat(int compat) const char* appinfo_get_appid(void) { - if(_app_info_init) + if (likely(_app_info_init)) { return _appid; } @@ -280,17 +288,12 @@ appinfo_get_appid(void) /** * @brief Returns the exec name for the application * - * @retval application exec name if valid, @c NULL otherwise + * @retval application exec name if valid, empty string otherwise */ const char* appinfo_get_execname(void) { - if(_app_info_init) - { - return _execname; - } - - return NULL; + return _execname; } @@ -302,7 +305,7 @@ appinfo_get_execname(void) const char* appinfo_get_packageid(void) { - if(_app_info_init) + if (likely(_app_info_init)) { return _pkgid; } @@ -324,7 +327,7 @@ appinfo_is_initialized(void) int appinfo_set_argv(int argc, char** argv) { - if(argc > 0 && argv) + if (argc > 0 && argv) { _argc = argc; _argv = argv; @@ -335,7 +338,7 @@ appinfo_set_argv(int argc, char** argv) int appinfo_get_argv(int* argc, char*** argv) { - if(_app_info_init && argc && argv) + if (_app_info_init && argc && argv) { *argc = _argc; *argv = _argv; diff --git a/appinfo/appinfo.h b/appinfo/appinfo.h index 70c2a1c..ea7963d 100644 --- a/appinfo/appinfo.h +++ b/appinfo/appinfo.h @@ -120,7 +120,7 @@ const char* appinfo_get_appid(void); /** * @brief Returns the exec name for the application * - * @retval application exec name if valid, @c NULL otherwise + * @retval application exec name if valid, empty string otherwise */ const char* appinfo_get_execname(void); -- 2.7.4