Fix mkdir time of check to time of use (TOCTOU) issue

This commit is contained in:
Markus Gans 2018-09-18 03:09:14 +02:00
parent b97fa7c61f
commit fec12f5d64
2 changed files with 8 additions and 10 deletions

View File

@ -1122,24 +1122,24 @@ void FOptiMove::moveByMethod ( int method
if ( F_carriage_return.cap ) if ( F_carriage_return.cap )
{ {
std::strncpy (move_ptr, F_carriage_return.cap, BUF_SIZE); std::strncpy (move_ptr, F_carriage_return.cap, BUF_SIZE);
move_buf[BUF_SIZE - 1] ='\0';
move_ptr += F_carriage_return.length; move_ptr += F_carriage_return.length;
relativeMove (move_ptr, 0, yold, xnew, ynew); relativeMove (move_ptr, 0, yold, xnew, ynew);
move_buf[BUF_SIZE - 1] ='\0';
} }
break; break;
case 3: case 3:
std::strncpy (move_ptr, F_cursor_home.cap, BUF_SIZE); std::strncpy (move_ptr, F_cursor_home.cap, BUF_SIZE);
move_buf[BUF_SIZE - 1] ='\0';
move_ptr += F_cursor_home.length; move_ptr += F_cursor_home.length;
relativeMove (move_ptr, 0, 0, xnew, ynew); relativeMove (move_ptr, 0, 0, xnew, ynew);
move_buf[BUF_SIZE - 1] ='\0';
break; break;
case 4: case 4:
std::strncpy (move_ptr, F_cursor_to_ll.cap, BUF_SIZE); std::strncpy (move_ptr, F_cursor_to_ll.cap, BUF_SIZE);
move_buf[BUF_SIZE - 1] ='\0';
move_ptr += F_cursor_to_ll.length; move_ptr += F_cursor_to_ll.length;
relativeMove (move_ptr, 0, screen_height - 1, xnew, ynew); relativeMove (move_ptr, 0, screen_height - 1, xnew, ynew);
move_buf[BUF_SIZE - 1] ='\0';
break; break;
case 5: case 5:
@ -1153,9 +1153,9 @@ void FOptiMove::moveByMethod ( int method
std::strncat ( move_ptr std::strncat ( move_ptr
, F_cursor_left.cap , F_cursor_left.cap
, BUF_SIZE - std::strlen(move_ptr) ); , BUF_SIZE - std::strlen(move_ptr) );
move_buf[BUF_SIZE - 1] ='\0';
move_ptr += std::strlen(move_buf); move_ptr += std::strlen(move_buf);
relativeMove (move_ptr, screen_width - 1, yold - 1, xnew, ynew); relativeMove (move_ptr, screen_width - 1, yold - 1, xnew, ynew);
move_buf[BUF_SIZE - 1] ='\0';
break; break;
default: default:

View File

@ -1663,14 +1663,12 @@ void FTermDetectionTest::tmuxTest()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermDetectionTest::ttytypeTest() void FTermDetectionTest::ttytypeTest()
{ {
struct stat sb = { }; if ( mkdir("new-root-dir", 0755) == -1 )
if ( errno != EEXIST )
if ( stat("new-root-dir", &sb) == -1 )
if ( mkdir("new-root-dir", 0755) == -1 )
return; 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; return;
// Write a own /etc/ttytype file // Write a own /etc/ttytype file