Wednesday, August 31, 2005 6:13 PM
rsamona
Spot the Bug - August 31, 2005
It's been a little while since we've had a new bug up. We had some good feedback on the last one. Here is a shorter one:
Courtesy of Shanit Gupta, Consultant (Foundstone)
try
{
ElevatePrivilege();
ReadSecretFile();
LowerPrivilege();
}
catch(FileException fe)
{
ReportException();
}
Suggested Implementation:
try
{
ElevatePrivilege();
ReadSecretFile();
}
catch(FileException fe)
{
ReportFileException();
}
catch(Exception e)
{
ReportException();
}
finally()
{
LowerPrivilege();
AllDone();
}
return;
Description: In the error prone code there is no way for the application to lower privileges if there is any exception in “ReadSecretFile” function. But in the suggested code, the finally block will execute irrespective of whether exception occurs or not and hence the privileges will be lowered once the secret file is read.