tc_libc_syslog.c : Use of vulnerable function 'sprintf' at tc_libc_syslog.c:90. This function is unsafe, use snprintf instead.
tc_libc_unistd.c : Use of vulnerable function 'sprintf' at tc_libc_unistd.c:279. This function is unsafe, use snprintf instead.
tc_pthread.c : No unlock for mutex 'g_mutex' at tc_pthread.c:1284 after lock at tc_pthread.c:1278 by calling function 'pthread_mutex_lock'.
tc_sched.c : Dynamic memory referenced by 'status' was allocated at tc_sched.c:306 by calling function 'malloc' and lost at tc_sched.c
mm_heapinfo.c : Return value of a function 'sched_gettcb' is dereferenced at mm_heapinfo.c:277 without checking, but it is usually checked for this function
int g_prioidx[PRIORITY_NUM] = { LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG };
const char *g_priostr[PRIORITY_NUM] = { "Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Information", "Debug" };
-char g_syslogmsg[MAX_SYSLOG_MSG];
+char g_syslogmsg[MAX_SYSLOG_MSG + 1];
/**
* @fn :tc_libc_syslog_setlogmask
int i;
for (i = 0; i < PRIORITY_NUM; i++) {
- sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
+ snprintf(g_syslogmsg, MAX_SYSLOG_MSG, "%s message\n", g_priostr[i]);
usleep(USEC_100);
ret_chk = syslog(g_prioidx[i], g_syslogmsg);
TC_ASSERT_EQ("syslog", ret_chk, strlen(g_syslogmsg));
int i;
for (i = 0; i < PRIORITY_NUM; i++) {
- sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
+ snprintf(g_syslogmsg, MAX_SYSLOG_MSG, "%s message\n", g_priostr[i]);
usleep(USEC_100);
ret_chk = vsyslogFunc(g_prioidx[i], g_syslogmsg);
TC_ASSERT_EQ("vsyslog", ret_chk, strlen(g_syslogmsg));
int i;
for (i = 0; i < PRIORITY_NUM; i++) {
- sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
+ snprintf(g_syslogmsg, MAX_SYSLOG_MSG, "%s message\n", g_priostr[i]);
usleep(USEC_100);
ret_chk = lowsyslog(g_prioidx[i], g_syslogmsg);
TC_ASSERT_EQ("lowsyslog", ret_chk, strlen(g_syslogmsg));
int i;
for (i = 0; i < PRIORITY_NUM; i++) {
- sprintf(g_syslogmsg, "%s message\n", g_priostr[i]);
+ snprintf(g_syslogmsg, MAX_SYSLOG_MSG, "%s message\n", g_priostr[i]);
usleep(USEC_100);
ret_chk = lowvsyslogFunc(g_prioidx[i], g_syslogmsg);
TC_ASSERT_EQ("lowvsyslog", ret_chk, strlen(g_syslogmsg));
static void tc_libc_unistd_access(void)
{
int ret_chk;
- char path[BUFFSIZE];
+ char path[BUFFSIZE + 1];
getcwd(path, BUFFSIZE);
- sprintf(path, "%s/%s", path, __FILE__);
+ snprintf(path, BUFFSIZE, "%s/%s", path, __FILE__);
ret_chk = access(path, F_OK);
TC_ASSERT_EQ("access", ret_chk, 0);
TC_ASSERT_EQ("pthread_sem_take", ret_chk, OK);
sem_getvalue(&sem, &get_value);
- TC_ASSERT_EQ("sem_getvalue", get_value, VAL_TWO);
+ /* if get_value is not matched with VAL_TWO, then TC fails. but we will not use sem anymore, so destroy it */
+ TC_ASSERT_EQ_CLEANUP("sem_getvalue", get_value, VAL_TWO, sem_destroy(&sem));
ret_chk = pthread_sem_give(&sem);
TC_ASSERT_EQ("pthread_sem_give", ret_chk, OK);
ret_chk = pthread_create(&pthread_waiter, NULL, thread_cond_signal, NULL);
TC_ASSERT_EQ("pthread_create", ret_chk, OK);
- TC_ASSERT_EQ("pthread_mutex_lock", g_cond_sig_val, VAL_ONE);
+ /* if g_cond_sig_val is not matched with VAL_ONE, then TC fails. but we will not use g_mutex anymore, so destroy it */
+ TC_ASSERT_EQ_CLEANUP("pthread_mutex_lock", g_cond_sig_val, VAL_ONE, pthread_mutex_destroy(&g_mutex));
ret_chk = pthread_mutex_unlock(&g_mutex);
TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);
{
int ret_chk;
pid_t child_pid;
- int *status = (int *)malloc(sizeof(int));
+ int status;
child_pid = task_create("tc_waitpid", SCHED_PRIORITY_DEFAULT, TASK_STACKSIZE, function_wait, (char * const *)NULL);
TC_ASSERT_GT("task_create", child_pid, 0);
- ret_chk = waitpid(child_pid, status, 0);
- TC_ASSERT_EQ_ERROR_CLEANUP("waitpid", ret_chk, child_pid, errno, TC_FREE_MEMORY(status));
+ ret_chk = waitpid(child_pid, &status, 0);
+ TC_ASSERT_EQ("waitpid", ret_chk, child_pid);
- free(status);
TC_SUCCESS_RESULT();
}
#endif
node = (struct mm_allocnode_s *)(stack_ptr - SIZEOF_MM_ALLOCNODE);
rtcb = sched_gettcb(node->pid);
+ ASSERT(rtcb);
rtcb->curr_alloc_size -= node->size;
node->pid = HEAPINFO_STACK;
}