Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Software security

Status
Not open for further replies.

iam3

Programmer
Oct 30, 2001
6
NO
I know nothing about C++...got this exercise in a course about security...can someone give me a hint??

#include <iostream>

main()
{
char command[40]; // Send command to
int time_of_day; // Avoid replay attack?
const bool ever = 1;

for ( ;ever; )
{
cin >> time_of_day >> command;
cout << &quot;Command was &quot; << command << &quot; at time &quot; << time_of_day << endl;
}
}

if we try input:
13 report
13 shoot-to-kill
15 shoot only if they shoot first
12:00 fire


how can someone perform a denial of service attack on this server? This same error was present in NT4, prior to service pack 2. This problem is difficult to fix with the C++ stream library, but easy to fix with C's I/O library:
#include <stdio.h>

#define ever 1

main()

{ char command[40]; // Send command to
int time_of_day; // Avoid replay attack?

for ( ;ever; )
{
scanf(&quot;%d %[^\n]&quot;,&time_of_day,command);
printf(&quot;Command %s at time %d\n&quot;,command,time_of_day);
}
}


The regular expression matcher %[^\n] means `match any object consisting of any character up to end of line'.
Why is it safer now?
 
The newline delimits the 40 char buffer.
Scanf is picky about what it will accept, unlike gets,
or evidently the c++ i/o stream.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top