Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
High-impact security, correctness, performance, and maintainability improvements from a Go code review (strictly preserving
SPEC.mdwire conformance and existingdd.sqlschema):Security & Protocol Correctness
pkg/fmsg/fmsg.go,pkg/fmsg/deflate.go,cmd/fmsgd/host.go): Wrapzlib.Readerinio.LimitReader(zr, int64(expandedSize)+1), removeuint32truncation on written byte counts, checkzr.Close(), accumulate attachment sizes inuint64to preventuint32wrap bypassingMAX_SIZE/MAX_EXPANDED_SIZE, and useint64indeflate.go's compression ratio check.cmd/fmsgd/host.go,pkg/fmsg/prepare.go): Useio.ReadFullinto exact-sized buffers inhandleChallenge,ReadUInt8Slice,readHeaderpid, andchallenge; close connections on recovered panics inhandleConn; sendRejectCodeInvalidon duplicatetoand add-to attachment count mismatch; add cycle/depth bounds toisMessageRetrievable; deep-copyAddToFromandStoredWireinHeader.Clone().cmd/fmsgd/sender.go,cmd/fmsgd/store.go,cmd/fmsgd/host.go):msg_add_toupdates bybatch_id(preventing sibling batches from overwriting each other) and propagatetx.Execerrors.isLockedfor recipient entries matching the unit's table (msg_tovsmsg_add_to) so addresses in bothToandAddToaren't double-updated.localOutcomeintoattachAddToRecipientsand usestrings.EqualFoldfor local domain matching.h.Attachments[i].Filepathuntil all copies succeed, skippersistAttachmentPayloadsonskipData, deduplicate accepted local addresses before file copies and quota recording, and replace TOCTOUos.Stat+os.Createloops with atomicO_CREATE|O_EXCL.cmd/fmsgd/host.go,id.go,dns.go,sender.go): Add dial/IO deadlines anddefer conn2.Close()inchallenge; unwrap*tls.ConninabortConn; include attachment sizes in upload/download deadlines and set header write deadlines; use a dedicated pooledhttp.Clientwith timeout, non-200 rejection, and body draining inid.go; add resolver timeouts, reuse*dns.Client, and verify DNSSEC AD records directly indns.go; addSIGINT/SIGTERMgraceful shutdown and accept-error backoff inmain.Performance
*sql.DBpool (cmd/fmsgd/store.go,sender.go,indicators.go): Replace per-querysql.Open/defer db.Close()with a single shared connection pool.pkg/fmsg/prepare.go,pkg/message/store.go,cmd/fmsgd/sender.go,store.go,indicators.go): Exportfmsg.UnmarshalPreparedHeaderfor header-only reads, skip unused queries & double hashing inFinalizeBatch, track in-flightpendingTargetkeys inprocessPendingMessages, deferUnmarshalPreparedindeliverUnituntil pending rows are locked, compress directly to a temp file in destination dir inpreparePart, and poolzlib.Writerviasync.Poolinpkg/fmsg/deflate.go.cmd/fmsgd/indicators.go,pkg/fmsg/fmsg.go,cmd/fmsgd/host.go): GatesourceLimiterandipCachefull-map pruning at>= 1s, computeipCacheTTL after lookup, remove redundant 3rd DB query insubjectsOf, optimizeHeader.Encode()/Address.ToString()/GetCommonMediaTypeID/GetMessageHash, batch N+1 duplicate hash lookups, replacetime.Afterinselectloops with reusable timers, and deduplicatereadMediaType/addrEqualFold.Testing
uint32attachment size overflow, truncated challenge/slice reads, duplicateto/add-to attachment mismatch codes, cycle detection, atomicuniqueFilepath,id.go5xx handling,Header.Clone(),UnmarshalPreparedHeader,sourceLimiter/ipCachebehavior,deliverUnitTo ∩ AddTolocking, and DNSSEC validation.go vet ./...,go build ./..., andgo test -race -count=1 ./....