fix(rtc): Prevent core dump if \r used in rt file 69/269/1
authorE. Scott Daniels <daniels@research.att.com>
Thu, 6 Jun 2019 12:10:26 +0000 (12:10 +0000)
committerE. Scott Daniels <daniels@research.att.com>
Thu, 6 Jun 2019 12:10:26 +0000 (12:10 +0000)
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 <daniels@research.att.com>
Change-Id: Ic18d5828f5a4b6855492b03718d105b57406431e

CMakeLists.txt
src/rmr/common/src/rt_generic_static.c
test/sr_nano_static_test.c

index 05385a5..40660c1 100644 (file)
@@ -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" )
index 7add33c..253e7ab 100644 (file)
@@ -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 );
 }
 
index 1eae96d..ef6e496 100644 (file)
@@ -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