forked from Imagelibrary/rtems
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.
This commit is contained in:
@@ -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>
|
2009-08-06 Christian Mauderer <christian.mauderer@embedded-brains.de>
|
||||||
|
|
||||||
* rtems/include/rtems/rtems/types.h: Improve documentation.
|
* rtems/include/rtems/rtems/types.h: Improve documentation.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
|
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
|
||||||
* time.
|
* time.
|
||||||
*
|
*
|
||||||
* COPYRIGHT (c) 1989-2007.
|
* COPYRIGHT (c) 1989-2009.
|
||||||
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
@@ -67,8 +67,7 @@ int _POSIX_Message_queue_Create_support(
|
|||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
n = strnlen( name_arg, NAME_MAX );
|
n = strnlen( name_arg, NAME_MAX );
|
||||||
if ( n > NAME_MAX )
|
/* length of name has already been validated */
|
||||||
return ENAMETOOLONG;
|
|
||||||
|
|
||||||
_Thread_Disable_dispatch();
|
_Thread_Disable_dispatch();
|
||||||
|
|
||||||
@@ -78,7 +77,6 @@ int _POSIX_Message_queue_Create_support(
|
|||||||
* compatibility. See README.mqueue for an example program we
|
* compatibility. See README.mqueue for an example program we
|
||||||
* think will print out the defaults. Report anything you find with it.
|
* think will print out the defaults. Report anything you find with it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( attr_ptr == NULL ) {
|
if ( attr_ptr == NULL ) {
|
||||||
attr.mq_maxmsg = 10;
|
attr.mq_maxmsg = 10;
|
||||||
attr.mq_msgsize = 16;
|
attr.mq_msgsize = 16;
|
||||||
@@ -111,21 +109,21 @@ int _POSIX_Message_queue_Create_support(
|
|||||||
* Make a copy of the user's string for name just in case it was
|
* Make a copy of the user's string for name just in case it was
|
||||||
* dynamically constructed.
|
* dynamically constructed.
|
||||||
*/
|
*/
|
||||||
|
name = _Workspace_Allocate(n+1);
|
||||||
name = _Workspace_Allocate(n);
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
_POSIX_Message_queue_Free( the_mq );
|
_POSIX_Message_queue_Free( the_mq );
|
||||||
_Thread_Enable_dispatch();
|
_Thread_Enable_dispatch();
|
||||||
rtems_set_errno_and_return_minus_one( ENOMEM );
|
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.
|
* 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 = &the_mq->Message_queue.Attributes;
|
||||||
the_mq_attr->discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
|
the_mq_attr->discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* NOTE: The structure of the routines is identical to that of POSIX
|
* COPYRIGHT (c) 1989-2009.
|
||||||
* 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.
|
|
||||||
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
@@ -39,14 +27,15 @@
|
|||||||
#include <rtems/posix/mqueue.h>
|
#include <rtems/posix/mqueue.h>
|
||||||
#include <rtems/posix/time.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
|
* _POSIX_Message_queue_Name_to_id
|
||||||
*
|
*
|
||||||
* Look up the specified name and attempt to locate the id
|
* Look up the specified name and attempt to locate the id
|
||||||
* for the associated message queue.
|
* for the associated message queue.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int _POSIX_Message_queue_Name_to_id(
|
int _POSIX_Message_queue_Name_to_id(
|
||||||
const char *name,
|
const char *name,
|
||||||
Objects_Id *id
|
Objects_Id *id
|
||||||
@@ -61,7 +50,7 @@ int _POSIX_Message_queue_Name_to_id(
|
|||||||
if ( !name[0] )
|
if ( !name[0] )
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
if( strlen(name) > PATH_MAX )
|
if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
|
||||||
return ENAMETOOLONG;
|
return ENAMETOOLONG;
|
||||||
|
|
||||||
status = _Objects_Name_to_id_string(
|
status = _Objects_Name_to_id_string(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
|
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
|
||||||
* time.
|
* time.
|
||||||
*
|
*
|
||||||
* COPYRIGHT (c) 1989-2007.
|
* COPYRIGHT (c) 1989-2009.
|
||||||
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
@@ -39,11 +39,9 @@
|
|||||||
#include <rtems/posix/mqueue.h>
|
#include <rtems/posix/mqueue.h>
|
||||||
#include <rtems/posix/time.h>
|
#include <rtems/posix/time.h>
|
||||||
|
|
||||||
/*PAGE
|
/*
|
||||||
*
|
|
||||||
* 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
|
* 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mqd_t mq_open(
|
mqd_t mq_open(
|
||||||
const char *name,
|
const char *name,
|
||||||
int oflag,
|
int oflag,
|
||||||
@@ -85,14 +83,11 @@ mqd_t mq_open(
|
|||||||
* need to check to see if this is a "message queue does not exist"
|
* need to check to see if this is a "message queue does not exist"
|
||||||
* or some other miscellaneous error on the name.
|
* or some other miscellaneous error on the name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( status ) {
|
if ( status ) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unless provided a valid name that did not already exist
|
* Unless provided a valid name that did not already exist
|
||||||
* and we are willing to create then it is an error.
|
* and we are willing to create then it is an error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
|
if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
|
||||||
_POSIX_Message_queue_Free_fd( the_mq_fd );
|
_POSIX_Message_queue_Free_fd( the_mq_fd );
|
||||||
_Thread_Enable_dispatch();
|
_Thread_Enable_dispatch();
|
||||||
@@ -100,11 +95,9 @@ mqd_t mq_open(
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else { /* name -> ID translation succeeded */
|
} else { /* name -> ID translation succeeded */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for existence with creation.
|
* Check for existence with creation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
|
if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
|
||||||
_POSIX_Message_queue_Free_fd( the_mq_fd );
|
_POSIX_Message_queue_Free_fd( the_mq_fd );
|
||||||
_Thread_Enable_dispatch();
|
_Thread_Enable_dispatch();
|
||||||
@@ -115,7 +108,6 @@ mqd_t mq_open(
|
|||||||
* In this case we need to do an ID->pointer conversion to
|
* In this case we need to do an ID->pointer conversion to
|
||||||
* check the mode.
|
* check the mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
|
the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
|
||||||
the_mq->open_count += 1;
|
the_mq->open_count += 1;
|
||||||
the_mq_fd->Queue = the_mq;
|
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
|
* At this point, the message queue does not exist and everything has been
|
||||||
* checked. We should go ahead and create a message queue.
|
* checked. We should go ahead and create a message queue.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status = _POSIX_Message_queue_Create_support(
|
status = _POSIX_Message_queue_Create_support(
|
||||||
name,
|
name,
|
||||||
true, /* shared across processes */
|
true, /* shared across processes */
|
||||||
@@ -145,10 +136,9 @@ mqd_t mq_open(
|
|||||||
/*
|
/*
|
||||||
* errno was set by Create_support, so don't set it again.
|
* errno was set by Create_support, so don't set it again.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( status == -1 ) {
|
if ( status == -1 ) {
|
||||||
_Thread_Enable_dispatch();
|
|
||||||
_POSIX_Message_queue_Free_fd( the_mq_fd );
|
_POSIX_Message_queue_Free_fd( the_mq_fd );
|
||||||
|
_Thread_Enable_dispatch();
|
||||||
return (mqd_t) -1;
|
return (mqd_t) -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* COPYRIGHT (c) 1989-2007.
|
* COPYRIGHT (c) 1989-2009.
|
||||||
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
@@ -28,15 +28,16 @@
|
|||||||
#include <rtems/posix/time.h>
|
#include <rtems/posix/time.h>
|
||||||
#include <rtems/seterr.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
|
* _POSIX_Semaphore_Create_support
|
||||||
*
|
*
|
||||||
* This routine does the actual creation and initialization of
|
* This routine does the actual creation and initialization of
|
||||||
* a poxix semaphore. It is a support routine for sem_init and
|
* a poxix semaphore. It is a support routine for sem_init and
|
||||||
* sem_open.
|
* sem_open.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int _POSIX_Semaphore_Create_support(
|
int _POSIX_Semaphore_Create_support(
|
||||||
const char *name,
|
const char *name,
|
||||||
int pshared,
|
int pshared,
|
||||||
@@ -48,20 +49,16 @@ int _POSIX_Semaphore_Create_support(
|
|||||||
CORE_semaphore_Attributes *the_sem_attr;
|
CORE_semaphore_Attributes *the_sem_attr;
|
||||||
char *name_p = (char *)name;
|
char *name_p = (char *)name;
|
||||||
|
|
||||||
_Thread_Disable_dispatch();
|
|
||||||
|
|
||||||
/* Sharing semaphores among processes is not currently supported */
|
/* Sharing semaphores among processes is not currently supported */
|
||||||
if (pshared != 0) {
|
if (pshared != 0)
|
||||||
_Thread_Enable_dispatch();
|
|
||||||
rtems_set_errno_and_return_minus_one( ENOSYS );
|
rtems_set_errno_and_return_minus_one( ENOSYS );
|
||||||
}
|
|
||||||
|
|
||||||
if ( name ) {
|
if ( name ) {
|
||||||
if( strlen(name) > PATH_MAX ) {
|
if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
|
||||||
_Thread_Enable_dispatch();
|
|
||||||
rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
|
rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
_Thread_Disable_dispatch();
|
||||||
|
|
||||||
the_semaphore = _POSIX_Semaphore_Allocate();
|
the_semaphore = _POSIX_Semaphore_Allocate();
|
||||||
|
|
||||||
@@ -91,13 +88,11 @@ int _POSIX_Semaphore_Create_support(
|
|||||||
* thing is certain, no matter what we decide, it won't be
|
* thing is certain, no matter what we decide, it won't be
|
||||||
* the same as all other POSIX implementations. :)
|
* the same as all other POSIX implementations. :)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
|
the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This effectively disables limit checking.
|
* This effectively disables limit checking.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
the_sem_attr->maximum_count = 0xFFFFFFFF;
|
the_sem_attr->maximum_count = 0xFFFFFFFF;
|
||||||
|
|
||||||
_CORE_semaphore_Initialize( &the_semaphore->Semaphore, the_sem_attr, value );
|
_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.
|
* Make the semaphore available for use.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_Objects_Open_string(
|
_Objects_Open_string(
|
||||||
&_POSIX_Semaphore_Information,
|
&_POSIX_Semaphore_Information,
|
||||||
&the_semaphore->Object,
|
&the_semaphore->Object,
|
||||||
|
|||||||
Reference in New Issue
Block a user