From b7a31bd94da349e9c49f6dd7a5bcded74877a8ae Mon Sep 17 00:00:00 2001 From: "E. Scott Daniels" Date: Thu, 6 Jun 2019 12:10:26 +0000 Subject: [PATCH] fix(rtc): Prevent core dump if \r used in rt file Some operating systems, and/or filesystems, insist on using \r as record termination (newline) indication rather than the standard \n. RMr was dependent on only finding \n as record termination when parsing the route table entries, however as it may be out of the user control to generate a static file with the proper termination this change allows \r to be in the static file. Signed-off-by: E. Scott Daniels Change-Id: Ic18d5828f5a4b6855492b03718d105b57406431e --- CMakeLists.txt | 2 +- src/rmr/common/src/rt_generic_static.c | 19 +++++++++++++++---- test/sr_nano_static_test.c | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05385a5..40660c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ cmake_minimum_required( VERSION 3.5 ) set( major_version "1" ) # should be automatically populated from git tag later, but until CI process sets a tag we use this set( minor_version "0" ) -set( patch_level "28" ) +set( patch_level "29" ) set( install_root "${CMAKE_INSTALL_PREFIX}" ) set( install_lib "lib" ) diff --git a/src/rmr/common/src/rt_generic_static.c b/src/rmr/common/src/rt_generic_static.c index 7add33c..253e7ab 100644 --- a/src/rmr/common/src/rt_generic_static.c +++ b/src/rmr/common/src/rt_generic_static.c @@ -489,22 +489,33 @@ static void read_static_rt( uta_ctx_t* ctx, int vlevel ) { return; } - if( (fbuf = uta_fib( fname ) ) == NULL ) { // read file into a single buffer - fprintf( stderr, "[WRN] seed route table could not be opened: %s: %s\n", fname, strerror( errno ) ); + if( (fbuf = uta_fib( fname ) ) == NULL ) { // read file into a single buffer (nil terminated string) + fprintf( stderr, "[WRN] rmr read_static: seed route table could not be opened: %s: %s\n", fname, strerror( errno ) ); return; } - if( DEBUG ) fprintf( stderr, "[INFO] seed route table successfully opened: %s\n", fname ); + if( DEBUG ) fprintf( stderr, "[DBUG] rmr: seed route table successfully opened: %s\n", fname ); + for( eor = fbuf; *eor; eor++ ) { // fix broken systems that use \r or \r\n to terminate records + if( *eor == '\r' ) { + *eor = '\n'; // will look like a blank line which is ok + } + } + for( rec = fbuf; rec && *rec; rec = eor+1 ) { rcount++; if( (eor = strchr( rec, '\n' )) != NULL ) { *eor = 0; + } else { + fprintf( stderr, "[WARN] rmr read_static: seed route table had malformed records (missing newline): %s\n", fname ); + fprintf( stderr, "[WARN] rmr read_static: seed route table not used%s\n", fname ); + free( fbuf ); + return; } parse_rt_rec( ctx, rec, vlevel ); } - if( DEBUG ) fprintf( stderr, "[INFO] seed route table successfully parsed: %d records\n", rcount ); + if( DEBUG ) fprintf( stderr, "[DBUG] rmr: seed route table successfully parsed: %d records\n", rcount ); free( fbuf ); } diff --git a/test/sr_nano_static_test.c b/test/sr_nano_static_test.c index 1eae96d..ef6e496 100644 --- a/test/sr_nano_static_test.c +++ b/test/sr_nano_static_test.c @@ -50,6 +50,7 @@ static void gen_rt( uta_ctx_t* ctx ) { char* rt_stuff; // strings for the route table rt_stuff = + "\r" // ensure we are not screwed by broken OSes that insist on using \r "newrt|end\n" // end of table check before start of table found "# comment to drive full comment test\n" "\n" // handle blank lines -- 2.16.6