Fix static analysis issues 39/282739/3
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 11 Oct 2022 04:17:26 +0000 (04:17 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 11 Oct 2022 04:55:03 +0000 (04:55 +0000)
The following issues are fixed:
 - Use After free
 - Uninitialized scalar variable
 - Unnecessary header file

Change-Id: Ibaf4b4281cb138695a2ea342ba00e66205a860ea
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
lib/alarm-lib.c
server/alarm-manager-dbus.c
server/alarm-manager.c
server/plugin/platform/src/alarm-server-plugin.c
session-agent/agent.c

index 38c35e0..c8ee73d 100644 (file)
@@ -33,7 +33,6 @@
 #include <gio/gio.h>
 #include <pkgmgr-info.h>
 #include <notification.h>
-#include <tzplatform_config.h>
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__ ((visibility("default")))
index 2066bb0..43ff36f 100644 (file)
@@ -819,18 +819,21 @@ bool _initialize_dbus(void)
        subsc_id = g_dbus_connection_signal_subscribe(connection,
                        "org.freedesktop.DBus", "org.freedesktop.DBus",
                        "NameOwnerChanged", "/org/freedesktop/DBus", NULL,
-                       G_DBUS_SIGNAL_FLAGS_NONE, __on_bus_name_owner_changed, NULL, NULL);
+                       G_DBUS_SIGNAL_FLAGS_NONE, __on_bus_name_owner_changed,
+                       NULL, NULL);
        if (subsc_id == 0) {
                LOGE("Subscribing to signal for invoking callback is failed.");
                g_object_unref(connection);
                return false;
        }
 
-       introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error);
+       introspection_data = g_dbus_node_info_new_for_xml(introspection_xml,
+                       &error);
        if (!introspection_data) {
-               LOGE("g_dbus_node_info_new_for_xml error(%s)", error->message);
+               LOGE("g_dbus_node_info_new_for_xml error(%s)",
+                               error ? error->message : "");
                g_object_unref(connection);
-               g_error_free(error);
+               g_clear_error(&error);
                return false;
        }
 
@@ -840,10 +843,12 @@ bool _initialize_dbus(void)
                        &interface_vtable,
                        NULL, NULL, &error);
        if (reg_id == 0) {
-               LOGE("g_dbus_connection_register_object error(%s)", error->message);
+               LOGE("g_dbus_connection_register_object error(%s)",
+                               error ? error->message : "");
                g_dbus_node_info_unref(introspection_data);
                g_object_unref(connection);
-               g_error_free(error);
+               g_clear_error(&error);
+               return false;
        }
 
        owner_id = g_bus_own_name_on_connection(connection,
index feb3c85..21d6707 100644 (file)
@@ -2363,6 +2363,7 @@ int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid
        base_info.mode.u_interval.day_of_week = mode_day_of_week;
        base_info.mode.repeat = (alarm_repeat_mode_t)mode_repeat;
 
+       base_info.msec = 0;
        base_info.alarm_type = alarm_type;
        base_info.reserved_info = reserved_info;
 
@@ -2430,6 +2431,7 @@ int alarm_manager_alarm_create_noti(GVariant *parameters, uid_t uid, pid_t pid,
        base_info.mode.u_interval.day_of_week = mode_day_of_week;
        base_info.mode.repeat = (alarm_repeat_mode_t)mode_repeat;
 
+       base_info.msec = 0;
        base_info.alarm_type = alarm_type;
        base_info.reserved_info = reserved_info;
 
@@ -2737,6 +2739,7 @@ int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid, const
        base_info.mode.u_interval.interval = mode_interval;
        base_info.mode.repeat = (alarm_repeat_mode_t)mode_repeat;
 
+       base_info.msec = 0;
        base_info.alarm_type = alarm_type;
        base_info.reserved_info = reserved_info;
 
index 3f065a9..d41cef3 100644 (file)
@@ -20,7 +20,6 @@
 #include <errno.h>
 #include <dlog.h>
 #include <sys/ioctl.h>
-#include <sys/stat.h>
 #include <linux/rtc.h>
 
 #include "plugin.h"
index 308d235..5154694 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,9 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdbool.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/un.h>