[ptime] fix buffer overflow

Fixes #997
pull/1205/head
Tim Stack 9 months ago
parent 4ee3b91111
commit ce391166ee

@ -742,7 +742,7 @@ ptime_l(struct exttm* dst, const char* str, off_t& off_inout, ssize_t len)
dst->et_tm.tm_hour = 0;
if ((off_inout + 1) > len) {
if ((off_inout + 1) >= len) {
return false;
}
@ -751,7 +751,7 @@ ptime_l(struct exttm* dst, const char* str, off_t& off_inout, ssize_t len)
off_inout += 1;
}
if ((off_inout + 1) > len) {
if ((off_inout + 1) >= len) {
off_inout = orig_off;
return false;
}
@ -764,7 +764,13 @@ ptime_l(struct exttm* dst, const char* str, off_t& off_inout, ssize_t len)
dst->et_tm.tm_hour = str[off_inout] - '0';
off_inout += 1;
if (!consumed_space && (off_inout + 1) >= len) {
off_inout = orig_off;
return false;
}
if (consumed_space || str[off_inout] < '0' || str[off_inout] > '9') {
dst->et_flags |= ETF_HOUR_SET;
return true;
}
@ -773,11 +779,10 @@ ptime_l(struct exttm* dst, const char* str, off_t& off_inout, ssize_t len)
off_inout += 1;
if (dst->et_tm.tm_hour >= 0 && dst->et_tm.tm_hour <= 23) {
dst->et_flags |= ETF_HOUR_SET;
return true;
}
dst->et_flags |= ETF_HOUR_SET;
off_inout = orig_off;
return false;
}

@ -348,6 +348,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_logfile.sh_08d731a04c877a34819b35de185e30a74c9fd497.out \
$(srcdir)/%reldir%/test_logfile.sh_09bd16e044302f6b121092534708594bdad11b5a.err \
$(srcdir)/%reldir%/test_logfile.sh_09bd16e044302f6b121092534708594bdad11b5a.out \
$(srcdir)/%reldir%/test_logfile.sh_18d9a7beeb09041993d0d6da488fc8192d111bd9.err \
$(srcdir)/%reldir%/test_logfile.sh_18d9a7beeb09041993d0d6da488fc8192d111bd9.out \
$(srcdir)/%reldir%/test_logfile.sh_218ecb88b4753010c4264b3ac351260b4811612f.err \
$(srcdir)/%reldir%/test_logfile.sh_218ecb88b4753010c4264b3ac351260b4811612f.out \
$(srcdir)/%reldir%/test_logfile.sh_290a3c49e53c2229a7400c107338fa0bb38375e2.err \

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

Loading…
Cancel
Save