[Cppcms-users] [BUG] Custom 'syslog.id' and 'openlog'
Brought to you by:
artyom-beilis
From: Nazım C. B. <naz...@ne...> - 2017-02-20 23:49:36
|
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. |