Skip to content

Commit 375c065

Browse files
authored
Merge pull request #165 from chris-4chain/fix/from-beef-nil-pointer-dereference
fix: tx.FromBEEF - nil pointer dereference
2 parents 289ac16 + 61dadc8 commit 375c065

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

transaction/beef.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ const ATOMIC_BEEF = uint32(0x01010101) // BRC-95
2727

2828
func (t *Transaction) FromBEEF(beef []byte) error {
2929
tx, err := NewTransactionFromBEEF(beef)
30+
if err != nil {
31+
return fmt.Errorf("failed to parse BEEF bytes: %w", err)
32+
}
3033
*t = *tx
31-
return err
34+
return nil
3235
}
3336

3437
func NewBeefV1() *Beef {

transaction/beef_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ func TestFromBEEF(t *testing.T) {
5757

5858
_, err = NewBeefFromTransaction(tx)
5959
require.NoError(t, err, "NewBeefFromTransaction method failed")
60+
}
6061

62+
func TestFromBeefErrorCase(t *testing.T) {
63+
tx := &Transaction{}
64+
err := tx.FromBEEF([]byte("invalid data"))
65+
require.Error(t, err, "FromBEEF method should fail with invalid data")
6166
}
6267

6368
func TestNewEmptyBEEF(t *testing.T) {

0 commit comments

Comments
 (0)