Changeset 53afba12 in rtems


Ignore:
Timestamp:
Aug 6, 2009, 7:26:56 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
fba809c
Parents:
288f8498
Message:

2009-08-06 Joel Sherrill <joel.sherrill@…>

  • 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.
Location:
cpukit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r288f8498 r53afba12  
     12009-08-06      Joel Sherrill <joel.sherrill@OARcorp.com>
     2
     3        * posix/src/mqueuecreatesupp.c, posix/src/mqueuenametoid.c,
     4        posix/src/mqueueopen.c, posix/src/semaphorecreatesupp.c: Tinker with
     5        error handling for name too long. Use strnlen to ensure we do not run
     6        off the end of the maximum length string.
     7
    182009-08-06      Christian Mauderer <christian.mauderer@embedded-brains.de>
    29
  • cpukit/posix/src/mqueuecreatesupp.c

    r288f8498 r53afba12  
    1212 *         time.
    1313 *
    14  *  COPYRIGHT (c) 1989-2007.
     14 *  COPYRIGHT (c) 1989-2009.
    1515 *  On-Line Applications Research Corporation (OAR).
    1616 *
     
    6868
    6969  n = strnlen( name_arg, NAME_MAX );
    70   if ( n > NAME_MAX )
    71     return ENAMETOOLONG;
     70  /* length of name has already been validated */
    7271
    7372  _Thread_Disable_dispatch();
     
    7978   *  think will print out the defaults.  Report anything you find with it.
    8079   */
    81 
    8280  if ( attr_ptr == NULL ) {
    8381    attr.mq_maxmsg  = 10;
     
    112110   * dynamically constructed.
    113111   */
    114 
    115   name = _Workspace_Allocate(n);
     112  name = _Workspace_Allocate(n+1);
    116113  if (!name) {
    117114    _POSIX_Message_queue_Free( the_mq );
     
    119116    rtems_set_errno_and_return_minus_one( ENOMEM );
    120117  }
    121   strcpy( name, name_arg );
     118  strncpy( name, name_arg, n+1 );
    122119
    123   /* XXX
     120  /*
     121   *  NOTE: That thread blocking discipline should be based on the
     122   *  current scheduling policy.
    124123   *
    125    *  Note that thread blocking discipline should be based on the
    126    *  current scheduling policy.
     124   *  Joel: Cite POSIX or OpenGroup on above statement so we can determine
     125   *        if it is a real requirement.
    127126   */
    128 
    129127  the_mq_attr = &the_mq->Message_queue.Attributes;
    130128  the_mq_attr->discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
    131129
    132   if ( ! _CORE_message_queue_Initialize(
     130  if ( !_CORE_message_queue_Initialize(
    133131           &the_mq->Message_queue,
    134132           the_mq_attr,
  • cpukit/posix/src/mqueuenametoid.c

    r288f8498 r53afba12  
    11/*
    2  *  NOTE:  The structure of the routines is identical to that of POSIX
    3  *         Message_queues to leave the option of having unnamed message
    4  *         queues at a future date.  They are currently not part of the
    5  *         POSIX standard but unnamed message_queues are.  This is also
    6  *         the reason for the apparently unnecessary tracking of
    7  *         the process_shared attribute.  [In addition to the fact that
    8  *         it would be trivial to add pshared to the mq_attr structure
    9  *         and have process private message queues.]
    10  *
    11  *         This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
    12  *         time.
    13  *
    14  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2009.
    153 *  On-Line Applications Research Corporation (OAR).
    164 *
     
    4028#include <rtems/posix/time.h>
    4129
    42 /*PAGE
    43  *
     30/* pure ANSI mode does not have this prototype */
     31size_t strnlen(const char *, size_t);
     32
     33/*
    4434 *  _POSIX_Message_queue_Name_to_id
    4535 *
     
    4737 *  for the associated message queue.
    4838 */
    49 
    5039int _POSIX_Message_queue_Name_to_id(
    5140  const char          *name,
     
    6251    return EINVAL;
    6352
    64   if( strlen(name) > PATH_MAX )
     53  if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
    6554    return ENAMETOOLONG;
    6655
  • cpukit/posix/src/mqueueopen.c

    r288f8498 r53afba12  
    1212 *         time.
    1313 *
    14  *  COPYRIGHT (c) 1989-2007.
     14 *  COPYRIGHT (c) 1989-2009.
    1515 *  On-Line Applications Research Corporation (OAR).
    1616 *
     
    4040#include <rtems/posix/time.h>
    4141
    42 /*PAGE
    43  *
     42/*
    4443 *  15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
    4544 */
    46 
    4745mqd_t mq_open(
    4846  const char *name,
     
    8684   *  or some other miscellaneous error on the name.
    8785   */
    88 
    8986  if ( status ) {
    90 
    9187    /*
    9288     * Unless provided a valid name that did not already exist
    9389     * and we are willing to create then it is an error.
    9490     */
    95 
    9691    if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
    9792      _POSIX_Message_queue_Free_fd( the_mq_fd );
     
    10196
    10297  } else {                /* name -> ID translation succeeded */
    103 
    10498    /*
    10599     * Check for existence with creation.
    106100     */
    107 
    108101    if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
    109102      _POSIX_Message_queue_Free_fd( the_mq_fd );
     
    116109     * check the mode.
    117110     */
    118 
    119111    the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
    120112    the_mq->open_count += 1;
     
    135127   *  checked. We should go ahead and create a message queue.
    136128   */
    137 
    138129  status = _POSIX_Message_queue_Create_support(
    139130    name,
     
    146137   * errno was set by Create_support, so don't set it again.
    147138   */
    148 
    149139  if ( status == -1 ) {
     140    _POSIX_Message_queue_Free_fd( the_mq_fd );
    150141    _Thread_Enable_dispatch();
    151     _POSIX_Message_queue_Free_fd( the_mq_fd );
    152142    return (mqd_t) -1;
    153143  }
  • cpukit/posix/src/semaphorecreatesupp.c

    r288f8498 r53afba12  
    11/*
    2  *  COPYRIGHT (c) 1989-2007.
     2 *  COPYRIGHT (c) 1989-2009.
    33 *  On-Line Applications Research Corporation (OAR).
    44 *
     
    2929#include <rtems/seterr.h>
    3030
    31 /*PAGE
    32  *
     31/* pure ANSI mode does not have this prototype */
     32size_t strnlen(const char *, size_t);
     33
     34/*
    3335 *  _POSIX_Semaphore_Create_support
    3436 *
     
    3739 *  sem_open.
    3840 */
    39 
    4041int _POSIX_Semaphore_Create_support(
    4142  const char                *name,
     
    4950  char                      *name_p = (char *)name;
    5051
    51   _Thread_Disable_dispatch();
     52  /* Sharing semaphores among processes is not currently supported */
     53  if (pshared != 0)
     54    rtems_set_errno_and_return_minus_one( ENOSYS );
    5255
    53   /* Sharing semaphores among processes is not currently supported */
    54   if (pshared != 0) {
    55     _Thread_Enable_dispatch();
    56     rtems_set_errno_and_return_minus_one( ENOSYS );
     56  if ( name ) {
     57    if ( strnlen( name, NAME_MAX ) >= NAME_MAX )
     58      rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
    5759  }
    5860
    59   if ( name ) {
    60     if( strlen(name) > PATH_MAX ) {
    61       _Thread_Enable_dispatch();
    62       rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
    63     }
    64   }
     61  _Thread_Disable_dispatch();
    6562
    6663  the_semaphore = _POSIX_Semaphore_Allocate();
     
    9289   *  the same as  all other POSIX implementations. :)
    9390   */
    94 
    9591  the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
    9692
     
    9894   *  This effectively disables limit checking.
    9995   */
    100 
    10196  the_sem_attr->maximum_count = 0xFFFFFFFF;
    10297
     
    106101   *  Make the semaphore available for use.
    107102   */
    108 
    109103  _Objects_Open_string(
    110104    &_POSIX_Semaphore_Information,
Note: See TracChangeset for help on using the changeset viewer.