Skip to content

Commit

Permalink
Fix code scanning alerts
Browse files Browse the repository at this point in the history
Fix code scanning alert no.1: signed overflow
Fix code scanning alert no.2: Too few arguments to formatting function
Fix code scanning alert no.3: Too few arguments to formatting function
Fix code scanning alert no.4: Time-of-check time-of-use filesystem race condition

Signed-off-by: Tharun Kumar Merugu <quic_mtharu@quicinc.com>
  • Loading branch information
quic-mtharu authored and quic-ekangupt committed Nov 15, 2024
1 parent be09d63 commit 033196d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/apps_std_imp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "rpcmem_internal.h"
#include "verify.h"
#include <dirent.h>
#include <limits.h>
#include <dlfcn.h>
#include <errno.h>
#include <inttypes.h>
Expand Down Expand Up @@ -720,7 +721,7 @@ __QAIC_IMPL(apps_std_fseek)(apps_std_FILE sin, int offset,
sinfo->u.binfo.pos += offset;
break;
case APPS_STD_SEEK_END:
VERIFYC(offset + sinfo->u.binfo.flen <= sinfo->u.binfo.flen, AEE_EFILE);
VERIFYC(offset <= INT_MAX - sinfo->u.binfo.flen, AEE_EFILE);
sinfo->u.binfo.pos += offset + sinfo->u.binfo.flen;
break;
}
Expand Down
9 changes: 6 additions & 3 deletions src/fastrpc_cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>

#define FARF_ERROR 1

Expand Down Expand Up @@ -58,11 +59,12 @@ static inline uint32_t fastrpc_check_if_dsp_present_rproc(uint32_t domain) {
while (1) {
memset(buffer, 0, BUF_SIZE);
snprintf(buffer, BUF_SIZE, "%s%d", dir_base_path, dir_index);
if (stat(buffer, &dir_stat) == -1) {
std_strlcat(buffer, "/name", BUF_SIZE);
int fd = open(buffer, O_RDONLY);
if (fd == -1) {
break;
}
std_strlcat(buffer, "/name", BUF_SIZE);
FILE *file = fopen(buffer, "r");
FILE *file = fdopen(fd, "r");
if (file != NULL) {
memset(buffer, 0, BUF_SIZE);
if (fgets(buffer, BUF_SIZE, file) != NULL) {
Expand All @@ -75,6 +77,7 @@ static inline uint32_t fastrpc_check_if_dsp_present_rproc(uint32_t domain) {
}
fclose(file);
}
close(fd);
dir_index++;
}
bail :
Expand Down
2 changes: 1 addition & 1 deletion src/fastrpc_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int fastrpc_wake_lock_deinit() {
pthread_mutex_unlock(&wakelock.wmut);

if (nErr)
FARF(ERROR, "Error 0x%x (%d): %s failed (errno %s)\n", nErr, __func__,
FARF(ERROR, "Error 0x%x (%d): %s failed (errno %s)\n", nErr, nErr, __func__,
strerror(errno));
else
FARF(ALWAYS, "%s done", __func__);
Expand Down
2 changes: 1 addition & 1 deletion src/listener_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static void listener(listener_config *me) {
result = AEE_EBADPARM;
FARF(RUNTIME_RPC_HIGH,
"adsp_listener_invoke_get_in_bufs2 failed, size is invalid req %d "
"inBufsLen %d result %d %x",
"inBufsLen %d result %d",
req, inBufsLen, result);
goto invoke;
}
Expand Down

0 comments on commit 033196d

Please sign in to comment.