Discussion:
[Cppcms-users] [BUG] Custom 'syslog.id' and 'openlog'
Nazım Can Bedir
2017-02-20 23:49:00 UTC
Permalink
Hi Artyom,

For any reason, if user needs to specify custom syslog.id value; CppCMS
is calling 'openlog' function with id variable stored on the stack.

According to

* man page at https://linux.die.net/man/3/openlog, and
* this Debian bug report at
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=102350

'openlog' is free to use given 'ident' pointer as-is (without making a
copy of it). Even on Ubuntu 16.04 system, it's not copying given ident.

In the following code excerpt, the pointer given at the line colored
with red will point to invalid memory location at the moment code reach
to end of active if block.

_service.cpp_

if(settings.get("logging.syslog.enable",false)==true) {
#ifndef CPPCMS_POSIX
throw cppcms_error("Syslog is not availible on Windows");
#else
std::string id = settings.get("logging.syslog.id","");
std::vector<std::string> vops =
settings.get("logging.syslog.options",std::vector<std::string>());
std::string sfacility = settings.get("logging.syslog.options","");
int ops = 0;
for(unsigned i=0;i<vops.size();i++) {
std::string const &op=vops[i];
if(op=="LOG_CONS") ops|=LOG_CONS;
else if(op=="LOG_NDELAY") ops|=LOG_NDELAY;
else if(op=="LOG_NOWAIT") ops|=LOG_NOWAIT;
else if(op=="LOG_ODELAY") ops|=LOG_ODELAY;
#ifdef LOG_PERROR
else if(op=="LOG_PERROR") ops|=LOG_PERROR;
#endif
else if(op=="LOG_PID") ops|=LOG_PID;
}
if(id.empty())
::openlog(0,ops,0);
else
::openlog(id.c_str(),ops,0);
logger::instance().add_sink(booster::shared_ptr<sink>(new sinks::syslog()));
#endif
}

std::string log_file;

Regards,
Nazim Can.
Artyom Beilis
2017-02-22 06:42:53 UTC
Permalink
Ok, Thanks for the report!!!

Can you please open the ticket?

I'll fix it in trunk,

Artyom

On Tue, Feb 21, 2017 at 1:49 AM, Nazım Can Bedir
Post by Nazım Can Bedir
Hi Artyom,
For any reason, if user needs to specify custom syslog.id value; CppCMS is
calling 'openlog' function with id variable stored on the stack.
According to
man page at https://linux.die.net/man/3/openlog, and
this Debian bug report at
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=102350
'openlog' is free to use given 'ident' pointer as-is (without making a copy
of it). Even on Ubuntu 16.04 system, it's not copying given ident.
In the following code excerpt, the pointer given at the line colored with
red will point to invalid memory location at the moment code reach to end of
active if block.
service.cpp
if(settings.get("logging.syslog.enable",false)==true) {
#ifndef CPPCMS_POSIX
throw cppcms_error("Syslog is not availible on Windows");
#else
std::string id = settings.get("logging.syslog.id","");
std::vector<std::string> vops =
settings.get("logging.syslog.options",std::vector<std::string>());
std::string sfacility = settings.get("logging.syslog.options","");
int ops = 0;
for(unsigned i=0;i<vops.size();i++) {
std::string const &op=vops[i];
if(op=="LOG_CONS") ops|=LOG_CONS;
else if(op=="LOG_NDELAY") ops|=LOG_NDELAY;
else if(op=="LOG_NOWAIT") ops|=LOG_NOWAIT;
else if(op=="LOG_ODELAY") ops|=LOG_ODELAY;
#ifdef LOG_PERROR
else if(op=="LOG_PERROR") ops|=LOG_PERROR;
#endif
else if(op=="LOG_PID") ops|=LOG_PID;
}
if(id.empty())
::openlog(0,ops,0);
else
::openlog(id.c_str(),ops,0);
logger::instance().add_sink(booster::shared_ptr<sink>(new sinks::syslog()));
#endif
}
std::string log_file;
Regards,
Nazim Can.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Cppcms-users mailing list
https://lists.sourceforge.net/lists/listinfo/cppcms-users
Nazım Can Bedir
2017-02-24 01:00:40 UTC
Permalink
Hi,

For the bug report, please see #148 Custom 'syslog.id' and openlog
(https://sourceforge.net/p/cppcms/bugs/148).

And while you are looking at this, could you please look at this small
feature request:
#37 Custom syslog Facility Support
(https://sourceforge.net/p/cppcms/feature-requests/37)

Thanks in advance.

Regards,
Nazim Can.
Post by Artyom Beilis
Ok, Thanks for the report!!!
Can you please open the ticket?
I'll fix it in trunk,
Artyom
On Tue, Feb 21, 2017 at 1:49 AM, Nazım Can Bedir
Post by Nazım Can Bedir
Hi Artyom,
For any reason, if user needs to specify custom syslog.id value; CppCMS is
calling 'openlog' function with id variable stored on the stack.
According to
man page at https://linux.die.net/man/3/openlog, and
this Debian bug report at
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=102350
'openlog' is free to use given 'ident' pointer as-is (without making a copy
of it). Even on Ubuntu 16.04 system, it's not copying given ident.
In the following code excerpt, the pointer given at the line colored with
red will point to invalid memory location at the moment code reach to end of
active if block.
service.cpp
if(settings.get("logging.syslog.enable",false)==true) {
#ifndef CPPCMS_POSIX
throw cppcms_error("Syslog is not availible on Windows");
#else
std::string id = settings.get("logging.syslog.id","");
std::vector<std::string> vops =
settings.get("logging.syslog.options",std::vector<std::string>());
std::string sfacility = settings.get("logging.syslog.options","");
int ops = 0;
for(unsigned i=0;i<vops.size();i++) {
std::string const &op=vops[i];
if(op=="LOG_CONS") ops|=LOG_CONS;
else if(op=="LOG_NDELAY") ops|=LOG_NDELAY;
else if(op=="LOG_NOWAIT") ops|=LOG_NOWAIT;
else if(op=="LOG_ODELAY") ops|=LOG_ODELAY;
#ifdef LOG_PERROR
else if(op=="LOG_PERROR") ops|=LOG_PERROR;
#endif
else if(op=="LOG_PID") ops|=LOG_PID;
}
if(id.empty())
::openlog(0,ops,0);
else
::openlog(id.c_str(),ops,0);
logger::instance().add_sink(booster::shared_ptr<sink>(new sinks::syslog()));
#endif
}
std::string log_file;
Regards,
Nazim Can.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Cppcms-users mailing list
https://lists.sourceforge.net/lists/listinfo/cppcms-users
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Cppcms-users mailing list
https://lists.sourceforge.net/lists/listinfo/cppcms-users
Loading...