audio-HAL: Fix for KW static analysis issues
- Add unlock for variable before exiting the method.
- Fix issue for Buffer Overflow - Non-null Terminated String.
Change-Id: Ied74e21de3a126d506fde1a05042af84c0211239
Signed-off-by: Kumar Anurag Singh <quic_kumaranu@quicinc.com>
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index 571b4f3..c7f5726 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -30,7 +30,7 @@
/*
* Changes from Qualcomm Innovation Center are provided under the following license:
*
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the
@@ -1370,8 +1370,10 @@
}
thermal_fd = open(wsa_path, O_RDONLY);
if (thermal_fd > 0) {
- if ((ret = read(thermal_fd, buf, sizeof(buf))) >= 0)
+ if ((ret = read(thermal_fd, buf, sizeof(buf))) >= 0) {
+ buf[ret-1] = '\0';
t0_spk_1 = atoi(buf);
+ }
else
ALOGE("%s: read fail for %s err:%d\n",
__func__, wsa_path, ret);
@@ -1404,8 +1406,10 @@
}
thermal_fd = open(wsa_path, O_RDONLY);
if (thermal_fd > 0) {
- if ((ret = read(thermal_fd, buf, sizeof(buf))) >= 0)
+ if ((ret = read(thermal_fd, buf, sizeof(buf))) >= 0) {
+ buf[ret-1] = '\0';
t0_spk_2 = atoi(buf);
+ }
else
ALOGE("%s: read fail for %s err:%d\n",
__func__, wsa_path, ret);
diff --git a/post_proc/bundle.c b/post_proc/bundle.c
index a9f95b9..f898f64 100644
--- a/post_proc/bundle.c
+++ b/post_proc/bundle.c
@@ -902,7 +902,8 @@
}
if (pCmdData == NULL || cmdSize != 2 * sizeof(uint32_t) ||
replySize == NULL || *replySize < 2*sizeof(int32_t)) {
- return -EINVAL;
+ status = -EINVAL;
+ goto exit;
}
memcpy(pReplyData, pCmdData, sizeof(int32_t)*2);
} break;