[w3c_log] handle an invalid log correctly

Fixes #988
This commit is contained in:
Timothy Stack 2022-06-04 15:31:48 -07:00
parent ef8c641e59
commit 60251dda84
12 changed files with 74 additions and 15 deletions

View File

@ -1,6 +1,6 @@
# aminclude_static.am generated automatically by Autoconf
# from AX_AM_MACROS_STATIC on Sat Jun 4 10:09:23 PDT 2022
# from AX_AM_MACROS_STATIC on Sat Jun 4 14:05:13 PDT 2022
# Code coverage

View File

@ -102,7 +102,7 @@ AC_SEARCH_LIBS(BZ2_bzopen, bz2,
AC_SUBST(BZIP2_SUPPORT)
AC_SEARCH_LIBS(dlopen, dl)
AC_SEARCH_LIBS(backtrace, execinfo)
LIBCURL_CHECK_CONFIG([], [7.23.0], [], [AC_MSG_ERROR([libz required to build])], [test x"${enable_static}" = x"yes"])
LIBCURL_CHECK_CONFIG([], [7.23.0], [], [AC_MSG_ERROR([libcurl required to build])], [test x"${enable_static}" = x"yes"])
# Sometimes, curses depends on these libraries being linked in...
AC_ARG_ENABLE([tinfo],

View File

@ -128,7 +128,14 @@ AC_DEFUN([LIBCURL_CHECK_CONFIG],
fi
if test x"$LIBCURL" = "x" ; then
if $5; then
LIBCURL=`$_libcurl_config --static-libs`
case "$host_os" in
darwin*)
LIBCURL=`$_libcurl_config --libs`
;;
*)
LIBCURL=`$_libcurl_config --static-libs`
;;
esac
else
LIBCURL=`$_libcurl_config --libs`
fi
@ -143,6 +150,23 @@ AC_DEFUN([LIBCURL_CHECK_CONFIG],
esac
fi
dnl If we are on OS X and we haven't picked up libcurl static or
dnl otherwise, then let's just go ahead and use the one present on
dnl the system. Since this compiled binary will only run on OS X
dnl which almost always has cURL installed, it's OK to add the
dnl static dependency.
AS_IF([test "x${LIBCURL}" = "x"],
[AS_CASE(["$host_os"],
[darwin*],
[AS_IF([test "x$_libcurl_config" != "x"],
AS_VAR_SET(LIBCURL, $($_libcurl_config --libs)),
[]
)],
[]
)],
[]
)
# All curl-config scripts support --feature
_libcurl_features=`$_libcurl_config --feature`

View File

@ -236,7 +236,10 @@ class generic_log_format : public log_format {
std::shared_ptr<log_format> specialized(int fmt_lock) override
{
return std::make_shared<generic_log_format>(*this);
auto retval = std::make_shared<generic_log_format>(*this);
retval->lf_specialized = true;
return retval;
}
};
@ -505,11 +508,15 @@ public:
}
if (found_ts) {
if (!this->lf_specialized) {
for (auto& ll : dst) {
ll.set_ignore(true);
}
}
dst.emplace_back(li.li_file_range.fr_offset, tv, level, 0, opid);
return SCAN_MATCH;
} else {
return SCAN_NO_MATCH;
}
return SCAN_NO_MATCH;
}
scan_result_t scan(logfile& lf,
@ -728,7 +735,10 @@ public:
std::shared_ptr<log_format> specialized(int fmt_lock = -1) override
{
return std::make_shared<bro_log_format>(*this);
auto retval = std::make_shared<bro_log_format>(*this);
retval->lf_specialized = true;
return retval;
}
class bro_log_table : public log_format_vtab_impl {
@ -1111,11 +1121,16 @@ public:
tv.tv_sec = tm2sec(&tm.et_tm);
tv.tv_usec = tm.et_nsec / 1000;
if (!this->lf_specialized) {
for (auto& ll : dst) {
ll.set_ignore(true);
}
}
dst.emplace_back(li.li_file_range.fr_offset, tv, level, 0);
return SCAN_MATCH;
} else {
return SCAN_NO_MATCH;
}
return SCAN_NO_MATCH;
}
scan_result_t scan(logfile& lf,
@ -1249,7 +1264,6 @@ public:
}
if (!this->wlf_format_name.empty() && !this->wlf_field_defs.empty()) {
dst.clear();
return this->scan_int(dst, li, sbr);
}
@ -1322,7 +1336,10 @@ public:
std::shared_ptr<log_format> specialized(int fmt_lock = -1) override
{
return std::make_shared<w3c_log_format>(*this);
auto retval = std::make_shared<w3c_log_format>(*this);
retval->lf_specialized = true;
return retval;
}
class w3c_log_table : public log_format_vtab_impl {
@ -1771,7 +1788,10 @@ public:
std::shared_ptr<log_format> specialized(int fmt_lock) override
{
return std::make_shared<logfmt_format>(*this);
auto retval = std::make_shared<logfmt_format>(*this);
retval->lf_specialized = true;
return retval;
}
};

View File

@ -260,6 +260,8 @@ logfile::process_prefix(shared_buffer_ref& sbr, const line_info& li)
}
}
log_debug("match found %d %d", found, li.li_file_range.fr_offset);
switch (found) {
case log_format::SCAN_MATCH:
if (!this->lf_index.empty()) {
@ -328,6 +330,8 @@ logfile::process_prefix(shared_buffer_ref& sbr, const line_info& li)
break;
}
log_debug("index size %d", this->lf_index.size());
return retval;
}

View File

@ -137,9 +137,6 @@ main(int argc, char* argv[])
lf->rebuild_index();
assert(!lf->is_closed());
assert(lf->get_activity().la_polls == 3);
if (lf->size() > 1) {
assert(lf->get_activity().la_reads == 2);
}
if (expected_format.empty()) {
assert(lf->get_format() == nullptr);
} else {

View File

@ -264,6 +264,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_logfile.sh_3fc6bfd8a6160817211f3e14fde957af75b9dbe7.out \
$(srcdir)/%reldir%/test_logfile.sh_4a2a907fcb069b8d6e65961a7b2e796d6c3a87b1.err \
$(srcdir)/%reldir%/test_logfile.sh_4a2a907fcb069b8d6e65961a7b2e796d6c3a87b1.out \
$(srcdir)/%reldir%/test_logfile.sh_7c2e11488bccc59458b5775db4b90de964858259.err \
$(srcdir)/%reldir%/test_logfile.sh_7c2e11488bccc59458b5775db4b90de964858259.out \
$(srcdir)/%reldir%/test_logfile.sh_a7037efd0c4bbf51940137a44e57d94e9307e83e.err \
$(srcdir)/%reldir%/test_logfile.sh_a7037efd0c4bbf51940137a44e57d94e9307e83e.out \
$(srcdir)/%reldir%/test_logfile.sh_c18e14a26d8261c9f72747118a469266121d5459.err \

View File

@ -1,2 +1,4 @@
#Fields: 0 cs-bytes
#Fields: 0
0 #
0

View File

@ -0,0 +1,6 @@
000
000
#Fields: 0
0
#Fields: 0
0

View File

@ -6,6 +6,9 @@ echo ${top_builddir}
printf '#Date:\t20\x800-2-02\n0\n' | run_cap_test \
env TEST_COMMENT="short timestamp" ${lnav_test} -n
printf '000\n000\n#Fields: 0\n0\n#Fields: 0\n0' | run_cap_test \
env TEST_COMMENT="invalid w3c log" ${lnav_test} -n
cat > rollover_in.0 <<EOF
2600/2 0 00:00:00 0:
00:2 0 00:00:00 0: