Ticket #2229: 0001-Panic-on-RTEMS_FAST_MUTEX-network-semaphore-claim-re.2.patch

File 0001-Panic-on-RTEMS_FAST_MUTEX-network-semaphore-claim-re.2.patch, 1.7 KB (added by Ben Gras, on 02/01/15 at 23:20:07)

2nd iteration

  • cpukit/libnetworking/rtems/rtems_glue.c

    From 8dcc846eb4b2b411f2c0bd8b9d7e606804657aa7 Mon Sep 17 00:00:00 2001
    From: Chris Johns <chrisj@rtems.org>
    Date: Mon, 22 Dec 2014 11:50:31 +1100
    Subject: [PATCH] Panic on RTEMS_FAST_MUTEX network semaphore claim/release.
    
    Fix the code to panic rather than perform a bad access if the network
    semaphore is accessed without the stack being intialised.
    
    Closes #2229.
    ---
     cpukit/libnetworking/rtems/rtems_glue.c | 9 ++++++++-
     1 file changed, 8 insertions(+), 1 deletion(-)
    
    diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c
    index 9d122e4..7484cce 100644
    a b uint32_t 
    117117rtems_bsdnet_semaphore_release_recursive(void)
    118118{
    119119#ifdef RTEMS_FAST_MUTEX
    120         uint32_t nest_count = the_networkSemaphore->Core_control.mutex.nest_count;
     120        uint32_t nest_count;
    121121        uint32_t i;
    122122
     123        nest_count =
     124                the_networkSemaphore ?
     125                the_networkSemaphore->Core_control.mutex.nest_count : 0;
    123126        for (i = 0; i < nest_count; ++i) {
    124127                rtems_bsdnet_semaphore_release();
    125128        }
    rtems_bsdnet_semaphore_obtain (void) 
    379382        _Thread_Disable_dispatch();
    380383#endif
    381384        _ISR_Disable (level);
     385        if (!the_networkSemaphore)
     386                rtems_panic ("rtems-net: network sema obtain: network not initialised\n");
    382387        executing = _Thread_Executing;
    383388        _CORE_mutex_Seize (
    384389                &the_networkSemaphore->Core_control.mutex,
    rtems_bsdnet_semaphore_release (void) 
    414419        int i;
    415420
    416421        _Thread_Disable_dispatch();
     422        if (!the_networkSemaphore)
     423                rtems_panic ("rtems-net: network sema obtain: network not initialised\n");
    417424        i = _CORE_mutex_Surrender (
    418425                &the_networkSemaphore->Core_control.mutex,
    419426                networkSemaphore,