diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-06 19:26:56 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-06 19:26:56 +0000 |
commit | 53afba1268c9ec94f35d9692a49204ab7ff3e367 (patch) | |
tree | 5a68306b034d2216778da5930a0874be367a71a8 | |
parent | 2009-08-06 Joel Sherrill <joel.sherrill@OARcorp.com> (diff) | |
download | rtems-53afba1268c9ec94f35d9692a49204ab7ff3e367.tar.bz2 |
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.
-rw-r--r-- | cpukit/ChangeLog | 7 | ||||
-rw-r--r-- | cpukit/posix/src/mqueuecreatesupp.c | 22 | ||||
-rw-r--r-- | cpukit/posix/src/mqueuenametoid.c | 23 | ||||
-rw-r--r-- | cpukit/posix/src/mqueueopen.c | 16 | ||||
-rw-r--r-- | cpukit/posix/src/semaphorecreatesupp.c | 24 |
5 files changed, 35 insertions, 57 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 219a8ff6ed..494448f519 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,10 @@ +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> * rtems/include/rtems/rtems/types.h: Improve documentation. diff --git a/cpukit/posix/src/mqueuecreatesupp.c b/cpukit/posix/src/mqueuecreatesupp.c index 335d1fc74d..90bab33ed7 100644 --- a/cpukit/posix/src/mqueuecreatesupp.c +++ b/cpukit/posix/src/mqueuecreatesupp.c @@ -11,7 +11,7 @@ * 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). * * The license and distribution terms for this file may be @@ -67,8 +67,7 @@ int _POSIX_Message_queue_Create_support( size_t n; n = strnlen( name_arg, NAME_MAX ); - if ( n > NAME_MAX ) - return ENAMETOOLONG; + /* length of name has already been validated */ _Thread_Disable_dispatch(); @@ -78,7 +77,6 @@ int _POSIX_Message_queue_Create_support( * compatibility. See README.mqueue for an example program we * think will print out the defaults. Report anything you find with it. */ - if ( attr_ptr == NULL ) { attr.mq_maxmsg = 10; attr.mq_msgsize = 16; @@ -111,25 +109,25 @@ int _POSIX_Message_queue_Create_support( * Make a copy of the user's string for name just in case it was * dynamically constructed. */ - - name = _Workspace_Allocate(n); + name = _Workspace_Allocate(n+1); if (!name) { _POSIX_Message_queue_Free( the_mq ); _Thread_Enable_dispatch(); 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 + /* + * 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, attr.mq_maxmsg, diff --git a/cpukit/posix/src/mqueuenametoid.c b/cpukit/posix/src/mqueuenametoid.c index fc99638594..f52e3383c2 100644 --- a/cpukit/posix/src/mqueuenametoid.c +++ b/cpukit/posix/src/mqueuenametoid.c @@ -1,17 +1,5 @@ /* - * 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). * * The license and distribution terms for this file may be @@ -39,14 +27,15 @@ #include <rtems/posix/mqueue.h> #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 * * Look up the specified name and attempt to locate the id * for the associated message queue. */ - int _POSIX_Message_queue_Name_to_id( const char *name, Objects_Id *id @@ -61,7 +50,7 @@ int _POSIX_Message_queue_Name_to_id( if ( !name[0] ) return EINVAL; - if( strlen(name) > PATH_MAX ) + if ( strnlen( name, NAME_MAX ) >= NAME_MAX ) return ENAMETOOLONG; status = _Objects_Name_to_id_string( diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c index 02d1b08e5e..2b96236fb5 100644 --- a/cpukit/posix/src/mqueueopen.c +++ b/cpukit/posix/src/mqueueopen.c @@ -11,7 +11,7 @@ * 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). * * The license and distribution terms for this file may be @@ -39,11 +39,9 @@ #include <rtems/posix/mqueue.h> #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, int oflag, @@ -85,14 +83,11 @@ mqd_t mq_open( * need to check to see if this is a "message queue does not exist" * 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 ); _Thread_Enable_dispatch(); @@ -100,11 +95,9 @@ mqd_t mq_open( } } 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 ); _Thread_Enable_dispatch(); @@ -115,7 +108,6 @@ mqd_t mq_open( * In this case we need to do an ID->pointer conversion to * check the mode. */ - the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); the_mq->open_count += 1; the_mq_fd->Queue = the_mq; @@ -134,7 +126,6 @@ mqd_t mq_open( * At this point, the message queue does not exist and everything has been * checked. We should go ahead and create a message queue. */ - status = _POSIX_Message_queue_Create_support( name, true, /* shared across processes */ @@ -145,10 +136,9 @@ mqd_t mq_open( /* * errno was set by Create_support, so don't set it again. */ - if ( status == -1 ) { - _Thread_Enable_dispatch(); _POSIX_Message_queue_Free_fd( the_mq_fd ); + _Thread_Enable_dispatch(); return (mqd_t) -1; } diff --git a/cpukit/posix/src/semaphorecreatesupp.c b/cpukit/posix/src/semaphorecreatesupp.c index da4050024c..42e530bf07 100644 --- a/cpukit/posix/src/semaphorecreatesupp.c +++ b/cpukit/posix/src/semaphorecreatesupp.c @@ -1,5 +1,5 @@ /* - * COPYRIGHT (c) 1989-2007. + * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -28,15 +28,16 @@ #include <rtems/posix/time.h> #include <rtems/seterr.h> -/*PAGE - * +/* pure ANSI mode does not have this prototype */ +size_t strnlen(const char *, size_t); + +/* * _POSIX_Semaphore_Create_support * * This routine does the actual creation and initialization of * a poxix semaphore. It is a support routine for sem_init and * sem_open. */ - int _POSIX_Semaphore_Create_support( const char *name, int pshared, @@ -48,21 +49,17 @@ int _POSIX_Semaphore_Create_support( CORE_semaphore_Attributes *the_sem_attr; char *name_p = (char *)name; - _Thread_Disable_dispatch(); - /* Sharing semaphores among processes is not currently supported */ - if (pshared != 0) { - _Thread_Enable_dispatch(); + if (pshared != 0) rtems_set_errno_and_return_minus_one( ENOSYS ); - } if ( name ) { - if( strlen(name) > PATH_MAX ) { - _Thread_Enable_dispatch(); + if ( strnlen( name, NAME_MAX ) >= NAME_MAX ) rtems_set_errno_and_return_minus_one( ENAMETOOLONG ); - } } + _Thread_Disable_dispatch(); + the_semaphore = _POSIX_Semaphore_Allocate(); if ( !the_semaphore ) { @@ -91,13 +88,11 @@ int _POSIX_Semaphore_Create_support( * thing is certain, no matter what we decide, it won't be * the same as all other POSIX implementations. :) */ - the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO; /* * This effectively disables limit checking. */ - the_sem_attr->maximum_count = 0xFFFFFFFF; _CORE_semaphore_Initialize( &the_semaphore->Semaphore, the_sem_attr, value ); @@ -105,7 +100,6 @@ int _POSIX_Semaphore_Create_support( /* * Make the semaphore available for use. */ - _Objects_Open_string( &_POSIX_Semaphore_Information, &the_semaphore->Object, |