Skip to content

Commit b7bb974

Browse files
committed
authkeys: Avoid double free
If any code after the first fclose(f) in Key::Parse() throws an exception, the exception handler will unconditionally call fclose(f) again. Fix this by setting f to NULL after the first fclose, and checking the value of f against NULL in the excepton handler. Signed-off-by: Wolfgang Wallner <[email protected]>
1 parent 7b68e60 commit b7bb974

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

common/src/authkeys.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ void Key::Parse(const std::string& filename, bool isSecret0)
170170
LOG_ERROR("Unsupported key file - %s\n Supported key formats: AMD Format & OpenSSL format", basefile.c_str());
171171
}
172172
fclose(f);
173+
f = NULL;
173174

174175
if(errCode != 0)
175176
{
@@ -195,7 +196,10 @@ void Key::Parse(const std::string& filename, bool isSecret0)
195196
}
196197
catch(...)
197198
{
198-
fclose(f);
199+
if (f!=NULL)
200+
{
201+
fclose(f);
202+
}
199203
throw;
200204
}
201205
}

0 commit comments

Comments
 (0)