-
Notifications
You must be signed in to change notification settings - Fork 499
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
services/horizon: Pass through nil ExtraSigners to avoid nil pointer deref #4349
Changes from all commits
17a88bd
4096c08
0124da9
19d0e04
ad77366
b0f6471
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,26 +55,23 @@ func PopulateTransaction( | |
} | ||
dest.Signatures = row.Signatures | ||
|
||
if row.HasPreconditions() { | ||
dest.Preconditions = &protocol.TransactionPreconditions{} | ||
} | ||
// If we never use this, we'll remove it later. This just defends us against | ||
// nil dereferences. | ||
dest.Preconditions = &protocol.TransactionPreconditions{} | ||
|
||
if !row.TimeBounds.Null { | ||
// Action needed in release: horizon-v3.0.0: remove ValidBefore and ValidAfter | ||
dest.ValidBefore = timeString(row.TimeBounds.Upper) | ||
dest.ValidAfter = timeString(row.TimeBounds.Lower) | ||
|
||
if dest.Preconditions.TimeBounds == nil { | ||
dest.Preconditions.TimeBounds = &protocol.TransactionPreconditionsTimebounds{} | ||
dest.Preconditions.TimeBounds = &protocol.TransactionPreconditionsTimebounds{ | ||
MaxTime: timeString(row.TimeBounds.Upper), | ||
MinTime: timeString(row.TimeBounds.Lower), | ||
} | ||
dest.Preconditions.TimeBounds.MaxTime = timeString(row.TimeBounds.Upper) | ||
dest.Preconditions.TimeBounds.MinTime = timeString(row.TimeBounds.Lower) | ||
} | ||
|
||
if !row.LedgerBounds.Null { | ||
if dest.Preconditions.LedgerBounds == nil { | ||
dest.Preconditions.LedgerBounds = &protocol.TransactionPreconditionsLedgerbounds{} | ||
} | ||
dest.Preconditions.LedgerBounds = &protocol.TransactionPreconditionsLedgerbounds{} | ||
if row.LedgerBounds.MinLedger.Valid { | ||
dest.Preconditions.LedgerBounds.MinLedger = uint32(row.LedgerBounds.MinLedger.Int64) | ||
} | ||
|
@@ -95,7 +92,7 @@ func PopulateTransaction( | |
dest.Preconditions.MinAccountSequenceLedgerGap = uint32(row.MinAccountSequenceLedgerGap.Int64) | ||
} | ||
|
||
if row.ExtraSigners != nil { | ||
if len(row.ExtraSigners) > 0 { | ||
dest.Preconditions.ExtraSigners = row.ExtraSigners | ||
} | ||
|
||
|
@@ -136,6 +133,11 @@ func PopulateTransaction( | |
dest.Links.Succeeds = lb.Linkf("/transactions?order=desc&cursor=%s", dest.PT) | ||
dest.Links.Precedes = lb.Linkf("/transactions?order=asc&cursor=%s", dest.PT) | ||
|
||
// If we didn't need the structure, drop it. | ||
if !row.HasPreconditions() { | ||
dest.Preconditions = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this necessary, is it because an empty Preconditions is considered not valid json/resource view? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more like: if we never used it, get rid of it. But only get rid of it after the fact, just in case some weird bug sneaks that would've caused a nil deref. |
||
} | ||
|
||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this should have no material effect on the XDR because a nil var length array in XDR is a zero length array. There is no distinction between them, unless we've optionalized the array with a pointer in the XDR, which we didn't for extraSigners.