summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2004-07-14 21:05:38 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2004-07-14 21:05:38 +0000
commite18303d9975abbe9247214eea756cbb9f0982279 (patch)
treed477078d337393ad11871f25500569ea84c3c491 /cpukit/score
parent2004-07-14 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-e18303d9975abbe9247214eea756cbb9f0982279.tar.bz2
2004-07-14 Joel Sherrill <joel@OARcorp.com>
PR 650/rtems * src/coremsg.c: Check for mathemathical overflow when calculating amount of memory to allocate for message buffers.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/ChangeLog6
-rw-r--r--cpukit/score/src/coremsg.c20
2 files changed, 25 insertions, 1 deletions
diff --git a/cpukit/score/ChangeLog b/cpukit/score/ChangeLog
index 38a97c6630..903db628ad 100644
--- a/cpukit/score/ChangeLog
+++ b/cpukit/score/ChangeLog
@@ -1,3 +1,9 @@
+2004-07-14 Joel Sherrill <joel@OARcorp.com>
+
+ PR 650/rtems
+ * src/coremsg.c: Check for mathemathical overflow when calculating
+ amount of memory to allocate for message buffers.
+
2004-05-06 Joel Sherrill <joel@OARcorp.com>
PR 618/rtems
diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c
index 05238b3bc8..120e03e360 100644
--- a/cpukit/score/src/coremsg.c
+++ b/cpukit/score/src/coremsg.c
@@ -64,7 +64,8 @@ boolean _CORE_message_queue_Initialize(
_CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
/*
- * round size up to multiple of a ptr for chain init
+ * Round size up to multiple of a pointer for chain init and
+ * check for overflow on adding overhead to each message.
*/
allocated_message_size = maximum_message_size;
@@ -73,15 +74,32 @@ boolean _CORE_message_queue_Initialize(
allocated_message_size &= ~(sizeof(unsigned32) - 1);
}
+ if (allocated_message_size < maximum_message_size)
+ return FALSE;
+
+ /*
+ * Calculate how much total memory is required for message buffering and
+ * check for overflow on the multiplication.
+ */
message_buffering_required = maximum_pending_messages *
(allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
+ if (message_buffering_required < allocated_message_size)
+ return FALSE;
+
+ /*
+ * Attempt to allocate the message memory
+ */
the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
_Workspace_Allocate( message_buffering_required );
if (the_message_queue->message_buffers == 0)
return FALSE;
+ /*
+ * Initialize the pool of inactive messages, pending messages,
+ * and set of waiting threads.
+ */
_Chain_Initialize (
&the_message_queue->Inactive_messages,
the_message_queue->message_buffers,