From fec12f5d645b15d224ed866d45869297f52b1a2b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 18 Sep 2018 03:09:14 +0200 Subject: [PATCH] Fix mkdir time of check to time of use (TOCTOU) issue --- src/foptimove.cpp | 8 ++++---- src/test/ftermdetection-test.cpp | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/foptimove.cpp b/src/foptimove.cpp index a9c87fa6..f03e2a9f 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -1122,24 +1122,24 @@ void FOptiMove::moveByMethod ( int method if ( F_carriage_return.cap ) { std::strncpy (move_ptr, F_carriage_return.cap, BUF_SIZE); + move_buf[BUF_SIZE - 1] ='\0'; move_ptr += F_carriage_return.length; relativeMove (move_ptr, 0, yold, xnew, ynew); - move_buf[BUF_SIZE - 1] ='\0'; } break; case 3: std::strncpy (move_ptr, F_cursor_home.cap, BUF_SIZE); + move_buf[BUF_SIZE - 1] ='\0'; move_ptr += F_cursor_home.length; relativeMove (move_ptr, 0, 0, xnew, ynew); - move_buf[BUF_SIZE - 1] ='\0'; break; case 4: std::strncpy (move_ptr, F_cursor_to_ll.cap, BUF_SIZE); + move_buf[BUF_SIZE - 1] ='\0'; move_ptr += F_cursor_to_ll.length; relativeMove (move_ptr, 0, screen_height - 1, xnew, ynew); - move_buf[BUF_SIZE - 1] ='\0'; break; case 5: @@ -1153,9 +1153,9 @@ void FOptiMove::moveByMethod ( int method std::strncat ( move_ptr , F_cursor_left.cap , BUF_SIZE - std::strlen(move_ptr) ); + move_buf[BUF_SIZE - 1] ='\0'; move_ptr += std::strlen(move_buf); relativeMove (move_ptr, screen_width - 1, yold - 1, xnew, ynew); - move_buf[BUF_SIZE - 1] ='\0'; break; default: diff --git a/src/test/ftermdetection-test.cpp b/src/test/ftermdetection-test.cpp index 0ba14348..dd0feeb7 100644 --- a/src/test/ftermdetection-test.cpp +++ b/src/test/ftermdetection-test.cpp @@ -1663,14 +1663,12 @@ void FTermDetectionTest::tmuxTest() //---------------------------------------------------------------------- void FTermDetectionTest::ttytypeTest() { - struct stat sb = { }; - - if ( stat("new-root-dir", &sb) == -1 ) - if ( mkdir("new-root-dir", 0755) == -1 ) + if ( mkdir("new-root-dir", 0755) == -1 ) + if ( errno != EEXIST ) return; - if ( stat("new-root-dir/etc", &sb) == -1 ) - if ( mkdir("new-root-dir/etc", 0755) == -1 ) + if ( mkdir("new-root-dir/etc", 0755) == -1 ) + if ( errno != EEXIST ) return; // Write a own /etc/ttytype file