1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

Merge pull request #1285 from LudwigOrtmann/msg_fixup

core/msg: prevent null pointer dereference
This commit is contained in:
Ludwig Ortmann 2014-07-08 14:47:26 +02:00
commit 0a6a83d6f3
2 changed files with 20 additions and 6 deletions

View File

@ -105,6 +105,7 @@ int msg_send_to_self(msg_t *m);
*
* @return 1, if sending was successful
* @return 0, if receiver is not waiting and ``block == 0``
* @return -1, on error (invalid PID)
*/
int msg_send_int(msg_t *m, unsigned int target_pid);

View File

@ -58,20 +58,22 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
return msg_send_int(m, target_pid);
}
if (sched_active_pid == target_pid) {
return msg_send_to_self(m);
}
dINT();
tcb_t *target = (tcb_t*) sched_threads[target_pid];
m->sender_pid = sched_active_pid;
if (m->sender_pid == target_pid) {
return msg_send_to_self(m);
}
if (target == NULL) {
DEBUG("msg_send(): target thread does not exist\n");
eINT();
return -1;
}
dINT();
DEBUG("msg_send() %s:%i: Sending from %i to %i. block=%i src->state=%i target->state=%i\n", __FILE__, __LINE__, sched_active_pid, target_pid, block, sched_active_thread->status, target->status);
if (target->status != STATUS_RECEIVE_BLOCKED) {
@ -143,6 +145,11 @@ int msg_send_int(msg_t *m, unsigned int target_pid)
{
tcb_t *target = (tcb_t *) sched_threads[target_pid];
if (target == NULL) {
DEBUG("msg_send_int(): target thread does not exist\n");
return -1;
}
if (target->status == STATUS_RECEIVE_BLOCKED) {
DEBUG("msg_send_int: Direct msg copy from %i to %i.\n", thread_getpid(), target_pid);
@ -243,6 +250,7 @@ static int _msg_receive(msg_t *m, int block)
/* no message, fail */
if ((!block) && (queue_index == -1)) {
eINT();
return -1;
}
@ -268,6 +276,9 @@ static int _msg_receive(msg_t *m, int block)
/* sender copied message */
}
else {
eINT();
}
return 1;
}
@ -295,6 +306,8 @@ static int _msg_receive(msg_t *m, int block)
eINT();
return 1;
}
DEBUG("This should have never been reached!\n");
}
int msg_init_queue(msg_t *array, int num)