Skip to content
Open
Changes from 3 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
27 changes: 23 additions & 4 deletions dissect/target/plugins/os/windows/log/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,38 @@ def errorlog(self) -> Iterator[MssqlErrorlogRecord]:
buf = ""

for line in fh:
if ts := RE_TIMESTAMP_PATTERN.match(line):
# If we have a buffer with a timestamp and
# our current line also has a timestamp,
# we should have a complete record in our buffer.
if previous_ts := RE_TIMESTAMP_PATTERN.match(buf):
Copy link
Contributor

@twiggler twiggler Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This potentially causes memory exhaustion if the log file does not start with a timestamp.
(And no entries will get returned)

I think the logic I posted here does not suffer from that problem

if current_ts := RE_TIMESTAMP_PATTERN.match(line):
yield MssqlErrorlogRecord(
ts=datetime.strptime(previous_ts.group(), "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=timezone.utc),
instance=instance,
# The process name is a fixed-width field and is always 12 characters long.
process=buf[23:35].strip(),
message=buf[35:].strip(),
path=errorlog,
_target=self.target,
)

buf = ""

buf += line

# For the last line
if buf:
if current_ts := RE_TIMESTAMP_PATTERN.match(line):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works if the last line is timestamped. If it is text, it will fail and the last record will be dropped.

The solution is to use current_ts

yield MssqlErrorlogRecord(
ts=datetime.strptime(ts.group(), "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=timezone.utc),
ts=datetime.strptime(current_ts.group(), "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=timezone.utc),
instance=instance,
# The process name is a fixed-width field and is always 12 characters long.
process=buf[23:35].strip(),
message=buf[35:].strip(),
path=errorlog,
_target=self.target,
)
buf = ""

buf += line

def _find_instances(self) -> set[str, TargetPath]:
return {
Expand Down