Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/conf: Add support for configurable maximum log & datasource message lengths #264

Merged
merged 5 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions .github/workflows/build-qa-arch-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ jobs:
fetch-depth: 0

# Work around the fix for CVE-2022-24765
- run: git config --global --add safe.directory $GITHUB_WORKSPACE || true
# (In this particular instance, git is not installed yet at this point.)
# (The repo "clone" here is that actions/checkout@v1 magic that kinda looks like a git clone.)
# (This command has been moved further down to where git is actually available [more or less accidentally, tbh].)
#- run: git config --global --add safe.directory $GITHUB_WORKSPACE || true



Expand All @@ -108,13 +111,15 @@ jobs:
### Build
#
- run: ./dev-tools/install-dev-software.sh

# Work around the fix for CVE-2022-24765
# (Should be done higher up, but see higher up for why it is down here.)
- run: git config --global --add safe.directory $GITHUB_WORKSPACE || true

- run: ./bootstrap.sh
- run: ./configure --enable-option-checking=fatal --enable-everything
- run: make -j4
- run: make -j4 check

- uses: actions/upload-artifact@v2
- run: cat tests/*/test-suite.log
if: failure()
with:
name: tests-directory
path: tests/
5 changes: 1 addition & 4 deletions .github/workflows/build-qa-config-matrix-large.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,5 @@ jobs:
- run: make -j4
- run: make -j4 check

- uses: actions/upload-artifact@v2
- run: cat tests/*/test-suite.log
if: failure()
with:
name: tests-directory
path: tests/
5 changes: 1 addition & 4 deletions .github/workflows/build-qa-config-matrix-small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,5 @@ jobs:
- run: make -j4
- run: make -j4 check

- uses: actions/upload-artifact@v2
- run: cat tests/*/test-suite.log
if: failure()
with:
name: tests-directory
path: tests/
5 changes: 1 addition & 4 deletions .github/workflows/build-qa-os-matrix-large.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,5 @@ jobs:
- run: make -j4
- run: make -j4 check

- uses: actions/upload-artifact@v2
- run: cat tests/*/test-suite.log
if: failure()
with:
name: tests-directory
path: tests/
5 changes: 1 addition & 4 deletions .github/workflows/build-qa-os-matrix-small.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,5 @@ jobs:
- run: make -j4
- run: make -j4 check

- uses: actions/upload-artifact@v2
- run: cat tests/*/test-suite.log
if: failure()
with:
name: tests-directory
path: tests/
5 changes: 1 addition & 4 deletions .github/workflows/build-qa-out-of-tree-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,5 @@ jobs:
- run: cd tmp/build1 && make -j4
- run: cd tmp/build1 && make -j4 check

- uses: actions/upload-artifact@v2
- run: cat tmp/build1/tests/*/test-suite.log
if: failure()
with:
name: tests-directory
path: tmp/build1/tests/
5 changes: 1 addition & 4 deletions .github/workflows/install-qa-os-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,8 @@ jobs:

### Report debugging info on failure
#
- uses: actions/upload-artifact@v2
- run: cat install-snoopy.log
if: failure()
with:
name: install-snoopy.log
path: install-snoopy.log



Expand Down
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
New features:
=============
o Add OpenSUSE 15.5 support.
o Configurable max log message length.
Ref: https://github.com/a2o/snoopy/issue/254
Ref: https://github.com/a2o/snoopy/pull/264

Deprecations:
=============
o Remove Ubuntu 18.04 support.
o Remove OpenSUSE 15.3 support.

Bugfixes:
=========
o Fix incorrectly placed free() call in `systemd_unit_name` datasource
Ref: https://github.com/a2o/snoopy/pull/264



2022-09-28 - Version 2.5.1
Expand Down
34 changes: 34 additions & 0 deletions etc/snoopy.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,37 @@
;
; Example:
;syslog_level = LOG_INFO



;;; Maximum individual data source's message length
;
; The length limit of a message emitted by an individual data source.
; WARNING: Memmory of this size is allocated on every Snoopy invocation.
; Increasing this setting beyond reasonable limits may impact your system's stability.
;
; Possible values:
; Between 255 and 1048575
;
; Default value:
; 2047
;
; Example:
;datasource_message_max_length = 2047



;;; Maximum formatted log message length
;
; The length limit of a final formatted log message.
; WARNING: Memmory of this size is allocated on every Snoopy invocation.
; Increasing this setting beyond reasonable limits may impact your system's stability.
;
; Possible values:
; Between 255 and 1048575
;
; Default value:
; 16383
;
; Example:
;log_message_max_length = 16383
4 changes: 2 additions & 2 deletions src/action/log-syscall-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ void snoopy_action_log_syscall_exec ()
#endif

/* Initialize empty log message */
logMessage = malloc(SNOOPY_LOG_MESSAGE_BUF_SIZE);
logMessage = malloc(CFG->log_message_max_length+1);
logMessage[0] = '\0';

/* Generate log message in specified format */
snoopy_message_generateFromFormat(logMessage, SNOOPY_LOG_MESSAGE_BUF_SIZE, CFG->message_format);
snoopy_message_generateFromFormat(logMessage, CFG->log_message_max_length+1, CFG->datasource_message_max_length+1, CFG->message_format);

/* Dispatch the message to configured output */
snoopy_action_log_message_dispatch(logMessage);
Expand Down
6 changes: 3 additions & 3 deletions src/cli/action-version.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

int snoopy_cli_action_version ()
{
int (* snoopy_ds_version_ptr) (char * const result, char const * const arg);
char ds_message_buf[SNOOPY_DATASOURCE_MESSAGE_MAX_SIZE] = "";
int (* snoopy_ds_version_ptr) (char * const resultBuf, size_t resultBufSize, char const * const arg);
char ds_message_buf[255] = "";
int ds_status;

// Load the library
Expand All @@ -48,7 +48,7 @@ int snoopy_cli_action_version ()
*(void **) (&snoopy_ds_version_ptr) = libsnoopySo_dlsym("snoopy_datasource_snoopy_version");

// Call the function
ds_status = snoopy_ds_version_ptr(ds_message_buf, "");
ds_status = snoopy_ds_version_ptr(ds_message_buf, 255, "");
if (SNOOPY_DATASOURCE_FAILED(ds_status)) {
fatalError("Snoopy version datasource failed");
}
Expand Down
6 changes: 6 additions & 0 deletions src/cli/cli-subroutines.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ void fatalErrorValue (const char * const message, const char * const value)
printErrorValue(message, value);
exit(127);
}
__attribute__((noreturn)) void fatalErrorValueFree (const char * const message, char * const value)
{
printErrorValue(message, value);
free(value);
exit(127);
}


char * libsnoopySo_getFilePath ()
Expand Down
1 change: 1 addition & 0 deletions src/cli/cli-subroutines.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void printError (const char * const message);
void printErrorValue (const char * const message, const char * const value);
void fatalError (const char * const message);
void fatalErrorValue (const char * const message, const char * const value);
void fatalErrorValueFree(const char * const message, char * const value);

char * libsnoopySo_getFilePath ();
char * libsnoopySo_getFilePathNoCheck ();
Expand Down
97 changes: 89 additions & 8 deletions src/configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "snoopy.h"
#include "configuration.h"
#include "outputregistry.h"
#include "util/parser-snoopy.h"
#include "util/string-snoopy.h"
#include "util/syslog-snoopy.h"

Expand Down Expand Up @@ -63,16 +64,18 @@
* Define supported config options
*/
snoopy_configfile_option_t snoopy_configfile_optionRegistry[] = {
{ "error_logging", { SNOOPY_CONFIGFILE_OPTION_TYPE_BOOL, &snoopy_configfile_parseValue_error_logging, &snoopy_configfile_getOptionValueAsString_error_logging } },
{ "error_logging", { SNOOPY_CONFIGFILE_OPTION_TYPE_BOOL, &snoopy_configfile_parseValue_error_logging, &snoopy_configfile_getOptionValueAsString_error_logging } },
#ifdef SNOOPY_FILTERING_ENABLED
{ "filter_chain", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_filter_chain, &snoopy_configfile_getOptionValueAsString_filter_chain } },
{ "filter_chain", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_filter_chain, &snoopy_configfile_getOptionValueAsString_filter_chain } },
#endif
{ "message_format", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_message_format, &snoopy_configfile_getOptionValueAsString_message_format } },
{ "output", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_output, &snoopy_configfile_getOptionValueAsString_output } },
{ "syslog_facility", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_facility, &snoopy_configfile_getOptionValueAsString_syslog_facility } },
{ "syslog_ident", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_ident, &snoopy_configfile_getOptionValueAsString_syslog_ident } },
{ "syslog_level", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_level, &snoopy_configfile_getOptionValueAsString_syslog_level } },
{ "", { SNOOPY_CONFIGFILE_OPTION_TYPE_NONE, NULL, NULL } },
{ "message_format", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_message_format, &snoopy_configfile_getOptionValueAsString_message_format } },
{ "output", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_output, &snoopy_configfile_getOptionValueAsString_output } },
{ "syslog_facility", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_facility, &snoopy_configfile_getOptionValueAsString_syslog_facility } },
{ "syslog_ident", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_ident, &snoopy_configfile_getOptionValueAsString_syslog_ident } },
{ "syslog_level", { SNOOPY_CONFIGFILE_OPTION_TYPE_STRING, &snoopy_configfile_parseValue_syslog_level, &snoopy_configfile_getOptionValueAsString_syslog_level } },
{ "datasource_message_max_length", { SNOOPY_CONFIGFILE_OPTION_TYPE_INT, &snoopy_configfile_parseValue_datasource_message_max_length, &snoopy_configfile_getOptionValueAsString_datasource_message_max_length } },
{ "log_message_max_length", { SNOOPY_CONFIGFILE_OPTION_TYPE_INT, &snoopy_configfile_parseValue_log_message_max_length, &snoopy_configfile_getOptionValueAsString_log_message_max_length } },
{ "", { SNOOPY_CONFIGFILE_OPTION_TYPE_NONE, NULL, NULL } },
};


Expand Down Expand Up @@ -591,6 +594,84 @@ int snoopy_configfile_getboolean (const char *c, int notfound)



/*
* Parse 'datasource_message_max_length' config option
*
* Params:
* confValString: Value from configuration file
* CFG: Snoopy configuration struct
*
* Return:
* int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or
* SNOOPY_CONFIGFILE_PARSEVALUE_ERROR
*/
int snoopy_configfile_parseValue_datasource_message_max_length (
const char *confValString,
snoopy_configuration_t* CFG
) {
CFG->datasource_message_max_length = snoopy_util_parser_strByteLength(
confValString,
SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_HARDMIN,
SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_HARDMAX,
SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_DEFAULT
);

return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS;
}



/*
* Parse 'log_message_max_length' config option
*
* Params:
* confValString: Value from configuration file
* CFG: Snoopy configuration struct
*
* Return:
* int SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS or
* SNOOPY_CONFIGFILE_PARSEVALUE_ERROR
*/
int snoopy_configfile_parseValue_log_message_max_length (
const char *confValString,
snoopy_configuration_t* CFG
) {
CFG->log_message_max_length = snoopy_util_parser_strByteLength(
confValString,
SNOOPY_LOG_MESSAGE_MAX_LENGTH_HARDMIN,
SNOOPY_LOG_MESSAGE_MAX_LENGTH_HARDMAX,
SNOOPY_LOG_MESSAGE_MAX_LENGTH_DEFAULT
);

return SNOOPY_CONFIGFILE_PARSEVALUE_SUCCESS;
}



char * snoopy_configfile_getOptionValueAsString_datasource_message_max_length ()
{
const snoopy_configuration_t * CFG = snoopy_configuration_get();

size_t strBufSize = sizeof(CFG->datasource_message_max_length)*8 + 1;
char * strBuf = malloc(strBufSize);
snprintf(strBuf, strBufSize, "%zu", CFG->datasource_message_max_length);
return strBuf;
}



char * snoopy_configfile_getOptionValueAsString_log_message_max_length ()
{
const snoopy_configuration_t * CFG = snoopy_configuration_get();

size_t strBufSize = sizeof(CFG->log_message_max_length)*8 + 1;
char * strBuf = malloc(strBufSize);
snprintf(strBuf, strBufSize, "%zu", CFG->log_message_max_length);
return strBuf;
}



/*
* optionRegistry :: getIdFromName()
*
Expand Down
5 changes: 5 additions & 0 deletions src/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#define SNOOPY_CONFIGFILE_OPTION_TYPE_BOOL 1
#define SNOOPY_CONFIGFILE_OPTION_TYPE_STRING 2
#define SNOOPY_CONFIGFILE_OPTION_TYPE_INT 3
#define SNOOPY_CONFIGFILE_OPTION_TYPE_NONE 0 // Reserved for internal use


Expand Down Expand Up @@ -65,6 +66,8 @@ int snoopy_configfile_parseValue_output (const char *confValSt
int snoopy_configfile_parseValue_syslog_facility (const char *confValString, snoopy_configuration_t* CFG);
int snoopy_configfile_parseValue_syslog_ident (const char *confValString, snoopy_configuration_t* CFG);
int snoopy_configfile_parseValue_syslog_level (const char *confValString, snoopy_configuration_t* CFG);
int snoopy_configfile_parseValue_datasource_message_max_length (const char *confValString, snoopy_configuration_t* CFG);
int snoopy_configfile_parseValue_log_message_max_length (const char *confValString, snoopy_configuration_t* CFG);

char * snoopy_configfile_getOptionValueAsString_error_logging ();
#ifdef SNOOPY_FILTERING_ENABLED
Expand All @@ -75,6 +78,8 @@ char * snoopy_configfile_getOptionValueAsString_output ();
char * snoopy_configfile_getOptionValueAsString_syslog_facility ();
char * snoopy_configfile_getOptionValueAsString_syslog_ident ();
char * snoopy_configfile_getOptionValueAsString_syslog_level ();
char * snoopy_configfile_getOptionValueAsString_datasource_message_max_length ();
char * snoopy_configfile_getOptionValueAsString_log_message_max_length ();



Expand Down
3 changes: 3 additions & 0 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ void snoopy_configuration_setDefaults
CFG->syslog_ident_format = SNOOPY_SYSLOG_IDENT_FORMAT;
CFG->syslog_ident_format_malloced = SNOOPY_FALSE;
CFG->syslog_level = SNOOPY_SYSLOG_LEVEL;

CFG->datasource_message_max_length = SNOOPY_DATASOURCE_MESSAGE_MAX_LENGTH_DEFAULT;
CFG->log_message_max_length = SNOOPY_LOG_MESSAGE_MAX_LENGTH_DEFAULT;
}


Expand Down
7 changes: 7 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@



#include <stddef.h>



/*
* START: Prevent cyclic inclusions
*/
Expand Down Expand Up @@ -59,6 +63,9 @@ typedef struct {
int syslog_level;
int syslog_ident_format_malloced;
char *syslog_ident_format;

size_t datasource_message_max_length;
size_t log_message_max_length;
} snoopy_configuration_t;


Expand Down
1 change: 1 addition & 0 deletions src/datasource/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ noinst_LTLIBRARIES = libsnoopy_datasources_all.la
# Please maintain alphabetical order, equal to what `ls` would do.
#
libsnoopy_datasources_all_la_SOURCES = \
datasource-common.h \
failure.c \
failure.h \
noop.c \
Expand Down
Loading
Loading