GH-1269: Fix LogAscii::enable_leftover_log_rotation crash in bad dirs

Running with that option enabled inside a bad directory (e.g. lack of
permissions) crashed due to not checking for failure of opendir().
This commit is contained in:
Jon Siwek 2020-11-06 19:16:39 -08:00
parent 8337b4cf2d
commit 0eb6839dae

View file

@ -710,6 +710,21 @@ static std::vector<LeftoverLog> find_leftover_logs()
auto d = opendir(".");
struct dirent* dp;
if ( ! d )
{
char cwd[PATH_MAX];
if ( ! getcwd(cwd, sizeof(cwd)) )
{
cwd[0] = '.';
cwd[1] = '\0';
}
reporter->Error("failed to open directory '%s' in search of leftover logs: %s",
cwd, strerror(errno));
return rval;
}
while ( (dp = readdir(d)) )
{
if ( strncmp(dp->d_name, shadow_file_prefix, prefix_len) != 0 )