Skip to content

Commit 469071b

Browse files
committed
ingress: fix crash when parsing from stdin
When injecting a single email or an mbox from stdin, ParseMail is invoked with the wrong context object which does not have a reference to the event bus. This results in a NULL pointer dereference on Queries.Commit(): for _, e := range q.pendingEvents { q.Events.Enqueue(&e) // q.Events is nil } Use the correct context object to fix the issue. Add a panic() to ensure that transactions can never be started with a nil event bus anymore. Fixes: 82a9d25 ("ingress: pass context with event bus to SMTP mail parser") Reported-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz> Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent 60bad79 commit 469071b

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎cmd/pw/ingress/main.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ func (c *CLI) Run(ctx *pw.Context) error {
6363
if err != nil {
6464
break
6565
}
66-
err = mail.ParseMail(ctx, ctx.DB, msg, c.ListID)
66+
err = mail.ParseMail(ctx.Context, ctx.DB, msg, c.ListID)
6767
if errors.As(err, &dupErr) {
6868
log.Debugf("ignoring %s", err)
6969
} else if err != nil {
7070
break
7171
}
7272
}
7373
} else {
74-
err = mail.ParseMail(ctx, ctx.DB, os.Stdin, c.ListID)
74+
err = mail.ParseMail(ctx.Context, ctx.DB, os.Stdin, c.ListID)
7575
}
7676
if errors.As(err, &dupErr) {
7777
log.Debugf("ignoring %s", err)

‎pkg/db/db.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ func WithBus(ctx context.Context, bus EventBus) context.Context {
124124
}
125125

126126
func GetBus(ctx context.Context) EventBus {
127-
if bus, ok := ctx.Value(busCtxKey{}).(EventBus); ok {
128-
return bus
127+
bus := ctx.Value(busCtxKey{}).(EventBus)
128+
if bus == nil {
129+
panic("Queries.Begin() context has no event bus value")
129130
}
130-
return nil
131+
return bus
131132
}
132133

133134
// Queries provides typed database access methods. It wraps a bun.IDB

0 commit comments

Comments
 (0)