Commit Graph

71 Commits (7dbae32eda0118fefccee25c53134242d0df8d76)

Author SHA1 Message Date
Jason Ish 22b77b0c56 conf: prefix conf API with SC 1 year ago
Zemeteri Kamimizu 87e6e9374f conf: init parser after check with stat()
Commit changes are made to avoid possible memory leaks. If the parser
is initialized before configuration file checking, there was no deinit
call before function return. Do check config file existance and type
before YAML parser initialization, so we don't need to deinit parser
before exiting the function.

Bug: #7302
2 years ago
Alexey Simakov c72404e554 yaml: Add check of allocation for node object
Fix potential dereference of nullptr in case
of unsuccessful allocation of memory for
list node

Bug: #7270
2 years ago
Philippe Antoine 20423fdd38 style: remove some useless return
and remove empty line before end of function
2 years ago
Philippe Antoine 240e068b81 conf: avoid quadratic complexity
Ticket: 6878

Follow up on 15649424a7

When adding many sequence nodes, either from start or scalar event

We add "sequence nodes" whose name is an integer cf sequence_node_name
and then run ConfNodeLookupChild to see if it had been already set
(from the command line cf comment in the code)
And ConfNodeLookupChild iterates the whole linked list...

1. We add node 1
2. To add node 2, we check if node 1 equals this new node
3. To add node 3, we check if nodes 1, or 2 equals this new node's name
And so on...

This commits avoids these checks ig the list is empty at the beginning
2 years ago
Victor Julien f53c4ab149 yaml: remove newline from error message 2 years ago
Jason Ish 252e8dbb32 conf: fix include handling from arrays
Includes from an "include" array were being loaded into the wrong
parent as the logic for array handing in include context was not
updated.

If we are descending into an array in include context, pass through
the current parent so the included configuration is included where it
is expected.

Bug: #6300
3 years ago
Victor Julien 29ac7b366b yaml: fix dead store
conf-yaml-loader.c:391:17: warning: Value stored to 'retval' is never read [deadcode.DeadStores]
                retval = -1;
                ^        ~~
1 warning generated.
3 years ago
Jason Ish 6ebb643b83 conf: deprecate multiple "include" statements at same level
The YAML spec considers duplicate keys to be an error, as do some YAML
implementations, most notably Rust's serde_yaml which would be nice to
use in the future.

Multiple include lines at the same level will still work, but a warning
will be emitted.

These can be fixed by moving to an "include" array:

include:
  - file1.yaml
  - file2.yaml

Ticket: #5939
3 years ago
Jason Ish 6e1cd7bbea conf: fatal error if "include" is a mapping
If a field named "include" is mapping it is not processed correctly.
Instead return a fatal error.

In our YAML, "include" has always been a reserved word, so this should
not break any known configuration.

Ticket: #5939
3 years ago
Jason Ish 67ce33a97e conf: allow "include" to be a list of files
In preparation for deprecating multiple "include" fields at the same
level, allow "include" to be a list of filenames.

Ticket: #5939
3 years ago
Jason Ish 84d1ed58bb config: check return value of dotted override
Fixes commit fbb0d2b0f4.
3 years ago
Jason Ish dcfa6a6002 suricata: allow additional include files on command line
Add a new command line option, --include. This will merge additional
configuration files into the configuration specified in the main
suricata.yaml.  It can be provided multiple times and the files will be
included in the order they appear on the command line.

Ticket: 3912
3 years ago
Jason Ish cb1ae92a1b yaml-loader: add test for fully qualified override
Also set the parent node for regular nodes on creation as this is
useful in unit-tests to verify the parent of a node.
3 years ago
Jason Ish fbb0d2b0f4 config: allow fully qualified overrides
Allow configuration parameters to be overrided usually a fully
qualified name such as:

vars.address-groups.HOME_NET: "7.1.2.0/24"

In configuration files (including "include" files).  This allows the
overriding of a specific value deeply nested in the configuration
without having to redefine the complete top-layer object.

Ticket: 4783
3 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 3 years ago
Philippe Antoine 15649424a7 conf: avoid quadratic complexity
Ticket: 4812

When adding many sequence nodes
4 years ago
Jason Ish 587c326d73 yaml: treat some unquoted values as null (per spec)
Per the YAML spec, the following values when present unquoted
should be equivalent to null:
- ~
- NULL
- Null
- null
5 years ago
Shivani Bhardwaj 7eef4e83e5 confyaml: convert to FAIL/PASS API 5 years ago
Shivani Bhardwaj 6f7d8e50c8 src: use FatalError whenever possible
Replaces all patterns of SCLogError() followed by exit() with
FatalError(). Cocci script to do this:

@@
constant C;
constant char[] msg;
@@

- SCLogError(C,
+ FatalError(SC_ERR_FATAL,
  msg);
- exit(EXIT_FAILURE);

Closes redmine ticket 3188.
6 years ago
Philippe Antoine fe1d36ec7e conf: returns instead of exiting in ConfYamlParse
So that we can keep on fuzzing even on too much recursion
6 years ago
Victor Julien 61c9e01f87 conf/yaml: include yaml.h after suricata-common.h 6 years ago
Jason Ish 4dc80a6e6f conf/yaml: limit recursion depth while paring YAML
A deeply nested YAML file can cause a stack-overflow while
reading in the configuration to do the recursive parser. Limit
the recursion level to something sane (128) to prevent this
from happening.

The default Suricata configuration has a recursion level of 128
so there is still lots of room to grow (not that we should).

Redmine ticket:
https://redmine.openinfosecfoundation.org/issues/3630
6 years ago
Philippe Antoine c1e41632c1 config: use logging instead of stderr 7 years ago
Victor Julien 9d54a8361d yaml: fix potential memleak and suppress coverity issue 8 years ago
Jason Ish 7d5f8295bc yaml-loader: fix memory leak on fail include
Redmine issue:
https://redmine.openinfosecfoundation.org/issues/1929

If an include failed to load, either by the file not existing or
a parse error, the file pointer and yaml parser instance were
leaked.
8 years ago
Jason Ish 8b74ac6ba0 conf/yaml: don't allow empty key values
When loading an empty file, libyaml will fire a single scalar
event causing us to create a key that contains an empty string.
We're not interested in this, so skip an empty scalar value
when expecting a key.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2418
8 years ago
Victor Julien ab1200fbd7 compiler: more strict compiler warnings
Set flags by default:

    -Wmissing-prototypes
    -Wmissing-declarations
    -Wstrict-prototypes
    -Wwrite-strings
    -Wcast-align
    -Wbad-function-cast
    -Wformat-security
    -Wno-format-nonliteral
    -Wmissing-format-attribute
    -funsigned-char

Fix minor compiler warnings for these new flags on gcc and clang.
9 years ago
Victor Julien edcc8e7ec9 stat: suppress CID 1293508 and 1312013 10 years ago
Victor Julien e13f956100 yaml: minor cleanup 10 years ago
Victor Julien 542492d6c2 yaml: initialize var to prevent uninitialized read 10 years ago
Jason Ish 796dd5223b tests: no longer necessary to provide successful return code
1 pass, 0 is fail.
10 years ago
Jason Ish 9fdae82815 conf - process includes even if not at root node. 11 years ago
Victor Julien 97d77e3540 conf: add ConfYamlLoadFileWithPrefix
Add function to load a yaml file and insert it into the conf tree at
a specific prefix.

Example YAML:
somefile: myfile.txt

If loaded using ConfYamlLoadFileWithPrefix with prefix "myprefix", it
can be retrieved by the name of "myprefix.somefile".
11 years ago
Jason Ish ee7e813256 Bug 1417 - Record sequence nodes as sequences.
Nodes that are sequences weren't being recorded as such, causing
rules to fail to load.

Change sequence test name to reflect better what it tests, and
test that the sequence node is detected as a sequence.
11 years ago
Jason Ish 33e4cc065f Promote nodes set with --set to sequence nodes as needed.
A node isn't known to be a sequence node until the YAML is parsed.
If a node sequence node was set on the command line, promote
it to a sequence node when it is discovered by YAML to be
a sequence node.

Fixes comment #18 in issue 921.
12 years ago
Jason Ish e8626509cc When setting a sequence value, check for an existing node.
This makes --set af-packet.0.threads=X do what you expect by
looking for the sequence node before setting.
12 years ago
Eric Leblond 28c5c68192 error checking: add missing alloc error treatment
The return of some malloc like functions was not treated in some
places of the code.
13 years ago
Jason Ish b033acfb0c Subsequent configuration keys now override previous ones
instead of merging.

The exception is final values, for example, values like
default-log-dir that may be set on the command line.
13 years ago
Jason Ish b8e13d4bd6 More concise API for setting config values that
can be overrided or not (final values).
13 years ago
Jason Ish 06f4fe8e0c Remove the single line if statements. 13 years ago
Jason Ish 8625c9eba8 Support for configuration include files. 13 years ago
Victor Julien 164d60e8cd Yaml: give a more detailed error if the user supplies a directory instead of a yaml file. Bug #803. 13 years ago
Victor Julien 4b2d94a841 Add line number to warning about mangled yaml parameters. Limit number of warnings to 10. 14 years ago
Nikolay Denev 32e898f2e3 Convert config entries using underscores to dashes and emit deprecation warnings. 14 years ago
Victor Julien 47abd0ef19 Fix compiler warning. 15 years ago
Victor Julien 55da9787a4 Win32 compile fixes. 15 years ago
Gerardo Iglesias Galvan 9f4fae5b1a Fix inconsistent use of dynamic memory allocation 16 years ago
William Metcalf ce01927515 Import of GPLv2 Header 050410 16 years ago
Victor Julien fe55d996c1 Improve yaml loaded debug output formatting. 16 years ago