mirror of
https://github.com/falcosecurity/falco.git
synced 2026-02-22 06:37:34 +00:00
fix: prevent NULL pointer crash in program_output on popen failure
Signed-off-by: Kevin Vu <vietcgi@gmail.com>
This commit is contained in:
@@ -16,12 +16,22 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
#include "outputs_program.h"
|
||||
#include "logger.h"
|
||||
#include <stdio.h>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
void falco::outputs::output_program::open_pfile() {
|
||||
if(m_pfile == nullptr) {
|
||||
m_pfile = popen(m_oc.options["program"].c_str(), "w");
|
||||
|
||||
if(m_pfile == nullptr) {
|
||||
falco_logger::log(falco_logger::level::ERR,
|
||||
"Failed to open program output: " + m_oc.options["program"] +
|
||||
" (error: " + std::string(std::strerror(errno)) + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!m_buffered) {
|
||||
setvbuf(m_pfile, NULL, _IONBF, 0);
|
||||
}
|
||||
@@ -31,7 +41,9 @@ void falco::outputs::output_program::open_pfile() {
|
||||
void falco::outputs::output_program::output(const message *msg) {
|
||||
open_pfile();
|
||||
|
||||
fprintf(m_pfile, "%s\n", msg->msg.c_str());
|
||||
if(m_pfile != nullptr) {
|
||||
fprintf(m_pfile, "%s\n", msg->msg.c_str());
|
||||
}
|
||||
|
||||
if(m_oc.options["keep_alive"] != "true") {
|
||||
cleanup();
|
||||
|
||||
@@ -32,7 +32,7 @@ class output_program : public abstract_output {
|
||||
private:
|
||||
void open_pfile();
|
||||
|
||||
FILE *m_pfile;
|
||||
FILE *m_pfile = nullptr;
|
||||
};
|
||||
|
||||
} // namespace outputs
|
||||
|
||||
Reference in New Issue
Block a user