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

syslog source: chunking metadata error #3858

Open
nabokihms opened this issue Jan 29, 2025 · 1 comment
Open

syslog source: chunking metadata error #3858

nabokihms opened this issue Jan 29, 2025 · 1 comment
Labels

Comments

@nabokihms
Copy link

Please review the Community Note before submitting

TruffleHog Version

v3.88.2

Trace Output

func (s *Source) monitorConnection(ctx context.Context, conn net.Conn, chunksChan chan *sources.Chunk) {
defer common.RecoverWithExit(ctx)
for {
if common.IsDone(ctx) {
return
}
err := conn.SetDeadline(time.Now().Add(time.Second))
if err != nil {
ctx.Logger().V(2).Info("could not set connection deadline", "error", err)
}
input := make([]byte, 8096)
remote := conn.RemoteAddr()
_, err = conn.Read(input)
if err != nil {
if errors.Is(err, io.EOF) {
return
}
continue
}
ctx.Logger().V(5).Info(string(input))
metadata, err := s.parseSyslogMetadata(input, remote.String())
if err != nil {
ctx.Logger().V(2).Info("failed to generate metadata", "error", err)
}
chunksChan <- &sources.Chunk{
SourceName: s.syslog.sourceName,
SourceID: s.syslog.sourceID,
SourceType: s.syslog.sourceType,
JobID: s.JobID(),
SourceMetadata: metadata,
Data: input,
Verify: s.verify,
}
}
}

Expected Behavior

Syslog works without error

Actual Behavior

Panic while sending long messages via syslog

Steps to Reproduce

The main issue is if the syslog message field is longer than the buffer (8096 bytes), it will be chunked.

Then there will be attempt to extract metadata from each chunk, which will end with the error for chunks with numbers 1+.

For all the following chunks of the long message the source metadata field will be nil, which will result in a panic.

Environment

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Additional Context

It seems like we need to read the full message from the connection before parsing its metadata. The current approach with the limited buffer is to fragile.

References

  • #0000
@nabokihms nabokihms added the bug label Jan 29, 2025
@nabokihms
Copy link
Author

nabokihms commented Feb 24, 2025

@trufflesecurity hello, folks. Do you need a fix for the problem? I'm currently living with a patched version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant