Fix app type checking in set_app_privilege().
authorRafal Krypa <r.krypa@samsung.com>
Tue, 18 Dec 2012 18:05:25 +0000 (19:05 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Tue, 8 Jan 2013 10:39:06 +0000 (11:39 +0100)
[Issue#] LINUXSWAP-417
[Bug] Passing type=NULL to set_app_privilege() caused segfault.
[Cause] Inappropriate handling of NULL value in this argument.
[Solution] Static function verify_app_type() now returns the app type.
[Verification] Build install, reboot target. Verify running of native applications and widgets.

Change-Id: I12c165048e8b049eb76b41afe3f214e0f92c0c55

src/privilege-control.c

index fa88a0a..62b1139 100644 (file)
@@ -57,7 +57,6 @@
 #define SMACK_DATA_SUFFIX       "_data"
 #define WRT_BASE_DEVCAP         "WRT"
 #define WRT_CLIENT_PATH         "/usr/bin/wrt-client"
-#define WRT_PKG_TYPE            "wgt"
 
 #ifdef USE_PRIVILEGE_CONTROL
 
 static int set_smack_for_wrt(const char* widget_id);
 #endif // WRT_SMACK_ENABLED
 
+typedef enum {
+       PKG_TYPE_WGT,
+       PKG_TYPE_OTHER
+} pkg_type_t;
+
 typedef struct {
        char user_name[10];
        int uid;
@@ -276,22 +280,19 @@ static int is_widget(const char* path)
  * @param path file path to executable
  * @return return void on success, terminate the process on error
  */
-static void verify_app_type(const char* type, const char* path)
+static pkg_type_t verify_app_type(const char* type, const char* path)
 {
        /* TODO: this should actually be treated as error, but until the old
         * set_privilege API is removed, it must be ignored */
        if (path == NULL)
-               return; /* good */
-
-       if (type == NULL)
-               exit(EXIT_FAILURE); /* bad */
+               return PKG_TYPE_OTHER; /* good */
 
        if (is_widget(path)) {
-               if (!strcmp(type, WRT_PKG_TYPE))
-                       return; /* good */
+               if (!strcmp(type, "wgt"))
+                       return PKG_TYPE_WGT; /* good */
        } else {
-               if (type == NULL || strcmp(type, WRT_PKG_TYPE))
-                       return /* good */;
+               if (type == NULL || strcmp(type, "wgt"))
+                       return PKG_TYPE_OTHER; /* good */
        }
 
        /* bad */
@@ -314,20 +315,23 @@ static const char* parse_widget_id(const char* path)
 API int set_app_privilege(const char* name, const char* type, const char* path)
 {
 #ifdef SMACK_ENABLED
+       const char* widget_id;
        int ret = PC_OPERATION_SUCCESS;
 
-       verify_app_type(type, path);
-       if (!strcmp(type, WRT_PKG_TYPE)) {
-               const char* widget_id = parse_widget_id(path);
+       switch(verify_app_type(type, path)) {
+       case PKG_TYPE_WGT:
+               widget_id = parse_widget_id(path);
                if (widget_id == NULL)
                        ret = PC_ERR_INVALID_PARAM;
 #ifdef WRT_SMACK_ENABLED
                else
                        ret = set_smack_for_wrt(widget_id);
 #endif
-       } else
+               break;
+       case PKG_TYPE_OTHER:
                if (path != NULL)
                ret = set_smack_from_binary(path);
+       }
 
        if (ret != PC_OPERATION_SUCCESS)
                return ret;