Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision e4f2fe13e777a9a0c44acdea42951b28356bf7dc)
+++ cpukit/ChangeLog	(revision 53afba1268c9ec94f35d9692a49204ab7ff3e367)
@@ -1,2 +1,9 @@
+2009-08-06	Joel Sherrill <joel.sherrill@OARcorp.com>
+
+	* posix/src/mqueuecreatesupp.c, posix/src/mqueuenametoid.c,
+	posix/src/mqueueopen.c, posix/src/semaphorecreatesupp.c: Tinker with
+	error handling for name too long. Use strnlen to ensure we do not run
+	off the end of the maximum length string.
+
 2009-08-06      Christian Mauderer <christian.mauderer@embedded-brains.de>
 
Index: cpukit/posix/src/mqueuecreatesupp.c
===================================================================
--- cpukit/posix/src/mqueuecreatesupp.c	(revision e4f2fe13e777a9a0c44acdea42951b28356bf7dc)
+++ cpukit/posix/src/mqueuecreatesupp.c	(revision 53afba1268c9ec94f35d9692a49204ab7ff3e367)
@@ -12,5 +12,5 @@
  *         time.
  *
- *  COPYRIGHT (c) 1989-2007.
+ *  COPYRIGHT (c) 1989-2009.
  *  On-Line Applications Research Corporation (OAR).
  *
@@ -68,6 +68,5 @@
 
   n = strnlen( name_arg, NAME_MAX );
-  if ( n > NAME_MAX )
-    return ENAMETOOLONG;
+  /* length of name has already been validated */
 
   _Thread_Disable_dispatch();
@@ -79,5 +78,4 @@
    *  think will print out the defaults.  Report anything you find with it.
    */
-
   if ( attr_ptr == NULL ) {
     attr.mq_maxmsg  = 10;
@@ -112,6 +110,5 @@
    * dynamically constructed.
    */
-
-  name = _Workspace_Allocate(n);
+  name = _Workspace_Allocate(n+1);
   if (!name) {
     _POSIX_Message_queue_Free( the_mq );
@@ -119,16 +116,17 @@
     rtems_set_errno_and_return_minus_one( ENOMEM );
   }
-  strcpy( name, name_arg );
+  strncpy( name, name_arg, n+1 );
 
-  /* XXX
+  /*
+   *  NOTE: That thread blocking discipline should be based on the
+   *  current scheduling policy.
    *
-   *  Note that thread blocking discipline should be based on the
-   *  current scheduling policy.
+   *  Joel: Cite POSIX or OpenGroup on above statement so we can determine
+   *        if it is a real requirement.
    */
-
   the_mq_attr = &the_mq->Message_queue.Attributes;
   the_mq_attr->discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
 
-  if ( ! _CORE_message_queue_Initialize(
+  if ( !_CORE_message_queue_Initialize(
            &the_mq->Message_queue,
            the_mq_attr,
Index: cpukit/posix/src/mqueuenametoid.c
===================================================================
--- cpukit/posix/src/mqueuenametoid.c	(revision e4f2fe13e777a9a0c44acdea42951b28356bf7dc)
+++ cpukit/posix/src/mqueuenametoid.c	(revision 53afba1268c9ec94f35d9692a49204ab7ff3e367)
@@ -1,16 +1,4 @@
 /*
- *  NOTE:  The structure of the routines is identical to that of POSIX
- *         Message_queues to leave the option of having unnamed message
- *         queues at a future date.  They are currently not part of the
- *         POSIX standard but unnamed message_queues are.  This is also
- *         the reason for the apparently unnecessary tracking of
- *         the process_shared attribute.  [In addition to the fact that
- *         it would be trivial to add pshared to the mq_attr structure
- *         and have process private message queues.]
- *
- *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
- *         time.
- *
- *  COPYRIGHT (c) 1989-2007.
+ *  COPYRIGHT (c) 1989-2009.
  *  On-Line Applications Research Corporation (OAR).
  *
@@ -40,6 +28,8 @@
 #include <rtems/posix/time.h>
 
-/*PAGE
- *
+/* pure ANSI mode does not have this prototype */
+size_t strnlen(const char *, size_t);
+
+/*
  *  _POSIX_Message_queue_Name_to_id
  *
@@ -47,5 +37,4 @@
  *  for the associated message queue.
  */
-
 int _POSIX_Message_queue_Name_to_id(
   const char          *name,
@@ -62,5 +51,5 @@
     return EINVAL;
 
-  if( strlen(name) > PATH_MAX )
+  if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
     return ENAMETOOLONG;
 
Index: cpukit/posix/src/mqueueopen.c
===================================================================
--- cpukit/posix/src/mqueueopen.c	(revision e4f2fe13e777a9a0c44acdea42951b28356bf7dc)
+++ cpukit/posix/src/mqueueopen.c	(revision 53afba1268c9ec94f35d9692a49204ab7ff3e367)
@@ -12,5 +12,5 @@
  *         time.
  *
- *  COPYRIGHT (c) 1989-2007.
+ *  COPYRIGHT (c) 1989-2009.
  *  On-Line Applications Research Corporation (OAR).
  *
@@ -40,9 +40,7 @@
 #include <rtems/posix/time.h>
 
-/*PAGE
- *
+/*
  *  15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
  */
-
 mqd_t mq_open(
   const char *name,
@@ -86,12 +84,9 @@
    *  or some other miscellaneous error on the name.
    */
-
   if ( status ) {
-
     /*
      * Unless provided a valid name that did not already exist
      * and we are willing to create then it is an error.
      */
-
     if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
       _POSIX_Message_queue_Free_fd( the_mq_fd );
@@ -101,9 +96,7 @@
 
   } else {                /* name -> ID translation succeeded */
-
     /*
      * Check for existence with creation.
      */
-
     if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
       _POSIX_Message_queue_Free_fd( the_mq_fd );
@@ -116,5 +109,4 @@
      * check the mode.
      */
-
     the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
     the_mq->open_count += 1;
@@ -135,5 +127,4 @@
    *  checked. We should go ahead and create a message queue.
    */
-
   status = _POSIX_Message_queue_Create_support(
     name,
@@ -146,8 +137,7 @@
    * errno was set by Create_support, so don't set it again.
    */
-
   if ( status == -1 ) {
+    _POSIX_Message_queue_Free_fd( the_mq_fd );
     _Thread_Enable_dispatch();
-    _POSIX_Message_queue_Free_fd( the_mq_fd );
     return (mqd_t) -1;
   }
Index: cpukit/posix/src/semaphorecreatesupp.c
===================================================================
--- cpukit/posix/src/semaphorecreatesupp.c	(revision e4f2fe13e777a9a0c44acdea42951b28356bf7dc)
+++ cpukit/posix/src/semaphorecreatesupp.c	(revision 53afba1268c9ec94f35d9692a49204ab7ff3e367)
@@ -1,4 +1,4 @@
 /*
- *  COPYRIGHT (c) 1989-2007.
+ *  COPYRIGHT (c) 1989-2009.
  *  On-Line Applications Research Corporation (OAR).
  *
@@ -29,6 +29,8 @@
 #include <rtems/seterr.h>
 
-/*PAGE
- *
+/* pure ANSI mode does not have this prototype */
+size_t strnlen(const char *, size_t);
+
+/*
  *  _POSIX_Semaphore_Create_support
  *
@@ -37,5 +39,4 @@
  *  sem_open.
  */
-
 int _POSIX_Semaphore_Create_support(
   const char                *name,
@@ -49,18 +50,14 @@
   char                      *name_p = (char *)name;
 
-  _Thread_Disable_dispatch();
+  /* Sharing semaphores among processes is not currently supported */
+  if (pshared != 0)
+    rtems_set_errno_and_return_minus_one( ENOSYS );
 
-  /* Sharing semaphores among processes is not currently supported */
-  if (pshared != 0) {
-    _Thread_Enable_dispatch();
-    rtems_set_errno_and_return_minus_one( ENOSYS );
+  if ( name ) {
+    if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
+      rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
   }
 
-  if ( name ) {
-    if( strlen(name) > PATH_MAX ) {
-      _Thread_Enable_dispatch();
-      rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
-    }
-  }
+  _Thread_Disable_dispatch();
 
   the_semaphore = _POSIX_Semaphore_Allocate();
@@ -92,5 +89,4 @@
    *  the same as  all other POSIX implementations. :)
    */
-
   the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
 
@@ -98,5 +94,4 @@
    *  This effectively disables limit checking.
    */
-
   the_sem_attr->maximum_count = 0xFFFFFFFF;
 
@@ -106,5 +101,4 @@
    *  Make the semaphore available for use.
    */
-
   _Objects_Open_string(
     &_POSIX_Semaphore_Information,
