Skip to content

Commit

Permalink
[loglevel] Avoid accessing null ptr in swssloglevel (sonic-net#349)
Browse files Browse the repository at this point in the history
* [loglevel] Fix issue: trying reading null pointer
* [loglevel] Return EXIT_FAILURE in case of access violation occuring.
  • Loading branch information
stephenxs authored Jun 9, 2020
1 parent 8fce898 commit cddfc4e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion common/loglevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ int main(int argc, char **argv)

if (print)
{
int errorCount = 0;

if (argc != 2)
{
exitWithUsage(EXIT_FAILURE, "-p option does not accept other options");
Expand All @@ -135,8 +137,20 @@ int main(int argc, char **argv)
{
const auto redis_key = std::string(key).append(":").append(key);
auto level = redisClient.hget(redis_key, DAEMON_LOGLEVEL);
std::cout << std::left << std::setw(30) << key << *level << std::endl;
if (nullptr == level)
{
std::cerr << std::left << std::setw(30) << key << "Unknown log level" << std::endl;
errorCount ++;
}
else
{
std::cout << std::left << std::setw(30) << key << *level << std::endl;
}
}

if (errorCount > 0)
return (EXIT_FAILURE);

return (EXIT_SUCCESS);
}

Expand Down

0 comments on commit cddfc4e

Please sign in to comment.