Commit c79a38c6 authored by Olivier Dion's avatar Olivier Dion Committed by Adrien Béraud
Browse files

fuzzing: Add syslog() and srand() wrappers

Change-Id: Ie622946606226171da6244361d334ba023dfa655
parent 9be5f7d5
......@@ -7,5 +7,5 @@ check_PROGRAMS =
lib_LTLIBRARIES = libfuzz.la
libfuzz_la_SOURCES = lib/utils.cpp lib/supervisor.cpp lib/gnutls.cpp
libfuzz_la_SOURCES = lib/utils.cpp lib/supervisor.cpp lib/gnutls.cpp lib/rand.cpp lib/syslog.cpp
endif
/*
* Copyright (C) 2021 Savoir-faire Linux Inc.
*
* Author: Olivier Dion <olivier.dion>@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdlib.h>
/*
* No random!
*/
void
srand(unsigned int seed)
{
(void) seed;
}
/*
* Copyright (C) 2021 Savoir-faire Linux Inc.
*
* Author: Olivier Dion <olivier.dion>@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <syslog.h>
#include <stdio.h>
#include <cstdlib>
#include "lib/supervisor.h"
#include "lib/syslog.h"
/* Jami */
#include "logger.h"
__weak
bool
syslog_handler(int priority, const char *fmt, va_list ap)
{
(void)priority;
(void)fmt;
(void)ap;
fflush(NULL);
fprintf(stderr, "libfuzz: stop by supervisor log\n");
return false;
}
BEGIN_WRAPPER(void, vsyslog, int priority, const char* format, va_list ap)
{
static int priority_threshold = -2;
if (-2 == priority_threshold) {
const char* str_to_int[] = {
[LOG_EMERG] = "EMERG",
[LOG_ALERT] = "ALERT",
[LOG_CRIT] = "CRIT",
[LOG_ERR] = "ERR",
[LOG_WARNING] = "WARNING",
[LOG_NOTICE] = "NOTICE",
[LOG_INFO] = "INFO",
[LOG_DEBUG] = "DEBUG"
};
const char* supervisor_says = std::getenv(supervisor::env::log);
if (nullptr == supervisor_says) {
priority_threshold = 0;
goto no_threshold;
}
for (size_t i = 0; i < array_size(str_to_int); ++i) {
if (streq(str_to_int[i], supervisor_says)) {
priority_threshold = i;
break;
}
}
if (priority_threshold < 0) {
fprintf(stderr, "libfuzz: Invalid value of SUPERVISOR_LOG `%s`\n", supervisor_says);
priority_threshold = -1;
}
}
no_threshold:
this_func(priority, format, ap);
if (priority <= priority_threshold) {
if (not syslog_handler(priority, format, ap)) {
exit(supervisor::signal::exit::log);
}
}
}
END_WRAPPER();
/*
* Copyright (C) 2021 Savoir-faire Linux Inc.
*
* Author: Olivier Dion <olivier.dion>@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <stdarg.h>
extern "C" {
extern bool syslog_handler(int priority, const char *fmt, va_list ap);
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment