vibrator: Add strdup() usage handling code 70/305670/1 accepted/tizen_unified_toolchain accepted/tizen/unified/20240208.163953 accepted/tizen/unified/toolchain/20240311.065603 accepted/tizen/unified/x/20240214.051939
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 6 Feb 2024 06:06:41 +0000 (15:06 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 6 Feb 2024 06:10:35 +0000 (15:10 +0900)
When the strdup() returns NULL, it should be handled properly.

Change-Id: I0f9639b47e804d7d8d2b11826a5227e22c1f95ff
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/vibrator.c

index e758c31..86b6ed0 100644 (file)
@@ -291,6 +291,11 @@ check_pattern:
                converted_pattern = profile->get_strong_buzz(pattern);
 
        temp = strdup(profile->str_pattern(converted_pattern));
+       if (!temp) {
+               _E("Failed to get vibration string pattern"); //LCOV_EXCL_LINE
+               return -ENOMEM; //LCOV_EXCL_LINE
+       }
+
        data = trim_str(temp);
        if (!data) {
                free(temp); //LCOV_EXCL_LINE
@@ -374,6 +379,11 @@ static int vibrator_is_supported(int pattern, bool *supported)
 
        /* get vibration data */
        temp = strdup(profile->str_pattern(pattern));
+       if (!temp) {
+               _E("Failed to get vibration string pattern"); //LCOV_EXCL_LINE
+               return -ENOMEM; //LCOV_EXCL_LINE
+       }
+
        data = trim_str(temp);
        if (!data) {
                free(temp); //LCOV_EXCL_LINE