1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

tests: ensure sscan buffer is nul terminated

Avoid reading past the read buffer when sscanf is used.
This commit is contained in:
Zdenek Kabelac 2024-04-15 18:14:50 +02:00
parent 4ca9d478d4
commit 93c47a2b94

View File

@ -718,6 +718,7 @@ struct KMsg : Source {
time_t tt; time_t tt;
size_t len; size_t len;
buf[ *sz ] = 0;
if (sscanf( buf, "%u,%u,%lu,-;%n", &level, &num, &t, &pos ) == 3) { if (sscanf( buf, "%u,%u,%lu,-;%n", &level, &num, &t, &pos ) == 3) {
memcpy( newbuf, buf, *sz ); memcpy( newbuf, buf, *sz );
tt = time( 0 ); tt = time( 0 );
@ -735,7 +736,7 @@ struct KMsg : Source {
char buf[ buffer_size ]; char buf[ buffer_size ];
if ( dev_kmsg() ) { if ( dev_kmsg() ) {
while ( (sz = ::read( fd, buf, buffer_size ) ) > 0 ) { while ( (sz = ::read( fd, buf, buffer_size - 129 ) ) > 0 ) {
transform( buf, &sz ); transform( buf, &sz );
s->push( std::string( buf, sz ) ); s->push( std::string( buf, sz ) );
} }