From f02ae22405940ae28cf7dbfe7a9a25f07d27f425 Mon Sep 17 00:00:00 2001 From: sfalmo <52037539+sfalmo@users.noreply.github.com> Date: Fri, 16 Dec 2022 02:43:39 +0100 Subject: [PATCH] Fix undefined behavior in RSL_LITE (#1765) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit TYPE: bug fix KEYWORDS: RSL_LITE SOURCE: Florian Sammüller (Universität Bayreuth, Germany) DESCRIPTION OF CHANGES: Problem: RSL_LITE has undefined behavior due to implicitly declared functions. This may lead to a crash of `wrf.exe` in the initialization of nested domains if WRF is built with link-time optimization and with recent compilers (e.g. GCC 12). Solution: Declare rsl_free() and destroy_list() before first use. ISSUE: Fixes #1764 LIST OF MODIFIED FILES: M external/RSL_LITE/rsl_bcast.c M external/RSL_LITE/rsl_lite.h TESTS CONDUCTED: It passed regression tests. RELEASE NOTE: Fixed an undefined behavior of RSL_LITE due to implicitly declared functions, which might lead to a model abort when using GCC 12. --- external/RSL_LITE/rsl_bcast.c | 40 ++++++++++++++++++++-------------------- external/RSL_LITE/rsl_lite.h | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/external/RSL_LITE/rsl_bcast.c b/external/RSL_LITE/rsl_bcast.c index 55b8acc6..d3e7d106 100755 --- a/external/RSL_LITE/rsl_bcast.c +++ b/external/RSL_LITE/rsl_bcast.c @@ -80,6 +80,26 @@ static destroy_par_info ( p ) if ( p != NULL ) RSL_FREE( p ) ; } +static destroy_list( list, dfcn ) + rsl_list_t ** list ; /* pointer to pointer to list */ + int (*dfcn)() ; /* pointer to function for destroying + the data field of the list */ +{ + rsl_list_t *p, *trash ; + if ( list == NULL ) return(0) ; + if ( *list == NULL ) return(0) ; + for ( p = *list ; p != NULL ; ) + { + if ( dfcn != NULL ) (*dfcn)( p->data ) ; + trash = p ; + p = p->next ; + RSL_FREE( trash ) ; + } + *list = NULL ; + return(0) ; +} + + static rsl_list_t *Xlist, *Xp, *Xprev ; static rsl_list_t *stage ; static int stage_len = 0 ; /* 96/3/15 */ @@ -726,23 +746,3 @@ rsl_lite_from_peerpoint_msg ( len_p, buf ) /********************************************/ -destroy_list( list, dfcn ) - rsl_list_t ** list ; /* pointer to pointer to list */ - int (*dfcn)() ; /* pointer to function for destroying - the data field of the list */ -{ - rsl_list_t *p, *trash ; - if ( list == NULL ) return(0) ; - if ( *list == NULL ) return(0) ; - for ( p = *list ; p != NULL ; ) - { - if ( dfcn != NULL ) (*dfcn)( p->data ) ; - trash = p ; - p = p->next ; - RSL_FREE( trash ) ; - } - *list = NULL ; - return(0) ; -} - -/********************************************/ diff --git a/external/RSL_LITE/rsl_lite.h b/external/RSL_LITE/rsl_lite.h index 5fcad78f..da430be9 100644 --- a/external/RSL_LITE/rsl_lite.h +++ b/external/RSL_LITE/rsl_lite.h @@ -165,6 +165,7 @@ char * buffer_for_proc ( int P, int size, int code ) ; void * rsl_malloc( char * f, int l, int s ) ; +void rsl_free( char ** p ) ; typedef int * int_p ; #define INDEX_2(A,B,NB) ( (B) + (A)*(NB) ) -- 2.11.4.GIT