From 93c47a2b9422971513581b3f55edf466694bfa43 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 15 Apr 2024 18:14:50 +0200 Subject: [PATCH] tests: ensure sscan buffer is nul terminated Avoid reading past the read buffer when sscanf is used. --- test/lib/brick-shelltest.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h index 814171b1a..a35422c08 100644 --- a/test/lib/brick-shelltest.h +++ b/test/lib/brick-shelltest.h @@ -718,6 +718,7 @@ struct KMsg : Source { time_t tt; size_t len; + buf[ *sz ] = 0; if (sscanf( buf, "%u,%u,%lu,-;%n", &level, &num, &t, &pos ) == 3) { memcpy( newbuf, buf, *sz ); tt = time( 0 ); @@ -735,7 +736,7 @@ struct KMsg : Source { char buf[ buffer_size ]; if ( dev_kmsg() ) { - while ( (sz = ::read( fd, buf, buffer_size ) ) > 0 ) { + while ( (sz = ::read( fd, buf, buffer_size - 129 ) ) > 0 ) { transform( buf, &sz ); s->push( std::string( buf, sz ) ); } -- 2.43.5