Skip to content

Commit 1817c72

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
No comment
1 parent a3a89bb commit 1817c72

91 files changed

Lines changed: 2497 additions & 1230 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
*.prof
99
/build/
1010
*.exe
11+
/.lake
12+
proofs/.lake

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: specs generate cli readme test e2e e2e-bindercli vet build lint clean \
2-
bindercli list-commands check-generated release
2+
bindercli list-commands check-generated release proofs difftest
33

44
# Generated top-level directories.
55
GENERATED_DIRS := android com fuzztest libgui_test_server parcelables src
@@ -31,6 +31,16 @@ cli: specs
3131
readme: specs
3232
go run ./tools/cmd/spec2readme -specs specs/ -output README.md
3333

34+
# --- Proofs ---
35+
36+
# Build Lean 4 proofs (requires elan/lake toolchain).
37+
proofs:
38+
cd proofs && lake build
39+
40+
# Run differential tests comparing Go against Lean oracle.
41+
difftest: proofs
42+
go test -v ./tests/differential/
43+
3444
# --- Testing ---
3545

3646
# Run unit tests.

binder/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package binder
2+
3+
// Config holds Transport configuration.
4+
type Config struct {
5+
MaxThreads uint32
6+
MapSize uint32
7+
}
8+
9+
// DefaultConfig returns the default transport configuration.
10+
func DefaultConfig() Config {
11+
return Config{
12+
MaxThreads: 0,
13+
MapSize: 1024*1024 - 2*4096, // 1MB - 2*PAGE_SIZE
14+
}
15+
}

binder/option.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ type Option interface {
55
apply(*Config)
66
}
77

8-
// Config holds Transport configuration.
9-
type Config struct {
10-
MaxThreads uint32
11-
MapSize uint32
12-
}
13-
14-
// DefaultConfig returns the default transport configuration.
15-
func DefaultConfig() Config {
16-
return Config{
17-
MaxThreads: 0,
18-
MapSize: 1024*1024 - 2*4096, // 1MB - 2*PAGE_SIZE
19-
}
20-
}
21-
228
// Options is a slice of Option.
239
type Options []Option
2410

binder/proxy_binder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func (b *ProxyBinder) LinkToDeath(
6161
ctx context.Context,
6262
recipient DeathRecipient,
6363
) (_err error) {
64+
logger.Tracef(ctx, "LinkToDeath(handle=%d)", b.handle)
65+
defer func() { logger.Tracef(ctx, "/LinkToDeath: %v", _err) }()
66+
6467
return b.transport.RequestDeathNotification(ctx, b.handle, recipient)
6568
}
6669

@@ -69,6 +72,9 @@ func (b *ProxyBinder) UnlinkToDeath(
6972
ctx context.Context,
7073
recipient DeathRecipient,
7174
) (_err error) {
75+
logger.Tracef(ctx, "UnlinkToDeath(handle=%d)", b.handle)
76+
defer func() { logger.Tracef(ctx, "/UnlinkToDeath: %v", _err) }()
77+
7278
return b.transport.ClearDeathNotification(ctx, b.handle, recipient)
7379
}
7480

binder/status.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ func ReadStatus(p *parcel.Parcel) error {
3737

3838
if traceSize > 0 {
3939
// Skip the remote stack trace string.
40-
_, _ = p.ReadString16()
40+
// Propagate the error: a truncated trace corrupts the read
41+
// position, causing subsequent fields to read garbage.
42+
if _, err := p.ReadString16(); err != nil {
43+
return fmt.Errorf("binder: reading status trace string: %w", err)
44+
}
4145
}
4246

4347
statusErr := &aidlerrors.StatusError{

binder/status_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package binder
22

33
import (
4+
"errors"
45
"fmt"
56
"testing"
67

@@ -84,3 +85,27 @@ func TestWriteStatusGenericError_ReadStatus(t *testing.T) {
8485
assert.Equal(t, aidlerrors.ExceptionTransactionFailed, statusErr.Exception)
8586
assert.Equal(t, "something went wrong", statusErr.Message)
8687
}
88+
89+
func TestReadStatus_TruncatedTraceString(t *testing.T) {
90+
// Build a parcel that claims traceSize > 0 but contains no trace
91+
// string data. Before the fix, ReadString16 error was silently
92+
// discarded, corrupting the read position so that the subsequent
93+
// ReadInt32 for ServiceSpecificCode would read garbage instead of
94+
// returning an error.
95+
p := parcel.New()
96+
p.WriteInt32(int32(aidlerrors.ExceptionServiceSpecific)) // exception code
97+
p.WriteString16("service error") // message
98+
p.WriteInt32(1) // traceSize > 0 (claims a trace exists)
99+
// Deliberately omit the trace string data — parcel is truncated here.
100+
101+
p.SetPosition(0)
102+
103+
err := ReadStatus(p)
104+
require.Error(t, err)
105+
assert.Contains(t, err.Error(), "reading status trace string")
106+
107+
// Must NOT be a StatusError with garbage ServiceSpecificCode.
108+
var statusErr *aidlerrors.StatusError
109+
assert.False(t, errors.As(err, &statusErr),
110+
"truncated parcel must not produce a StatusError with garbage fields")
111+
}

binder/stub_binder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func (s *StubBinder) BinderPtr() uintptr {
103103
return uintptr(unsafe.Pointer(s.weakRef))
104104
}
105105

106-
// Transport returns nil for unregistered stubs; after
107-
// RegisterWithTransport it returns the transport that was used.
106+
// Transport returns nil — StubBinder does not implement VersionAwareTransport
107+
// lookup. Use the transport directly instead.
108108
func (s *StubBinder) Transport() VersionAwareTransport {
109109
return nil
110110
}

binder/transaction.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,3 @@ const (
1616
InterfaceTransaction TransactionCode = ('_' << 24) | ('N' << 16) | ('T' << 8) | 'F'
1717
SyspropsTransaction TransactionCode = ('_' << 24) | ('S' << 16) | ('P' << 8) | 'R'
1818
)
19-
20-
// TransactionFlags control transaction behavior.
21-
type TransactionFlags uint32
22-
23-
const (
24-
FlagOneway TransactionFlags = 0x00000001
25-
FlagCollectNotedAppOps TransactionFlags = 0x00000002
26-
// FlagAcceptFDs tells the binder kernel that this process can receive
27-
// file descriptors in the reply. Without this flag, the kernel rejects
28-
// replies containing FDs with BR_FAILED_REPLY. Android's
29-
// IPCThreadState::transact() always sets this flag.
30-
FlagAcceptFDs TransactionFlags = 0x00000010
31-
FlagClearBuf TransactionFlags = 0x00000020
32-
FlagPrivateVendor TransactionFlags = 0x10000000
33-
)

binder/transaction_flags.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package binder
2+
3+
// TransactionFlags control transaction behavior.
4+
type TransactionFlags uint32
5+
6+
const (
7+
FlagOneway TransactionFlags = 0x00000001
8+
FlagCollectNotedAppOps TransactionFlags = 0x00000002
9+
// FlagAcceptFDs tells the binder kernel that this process can receive
10+
// file descriptors in the reply. Without this flag, the kernel rejects
11+
// replies containing FDs with BR_FAILED_REPLY. Android's
12+
// IPCThreadState::transact() always sets this flag.
13+
FlagAcceptFDs TransactionFlags = 0x00000010
14+
FlagClearBuf TransactionFlags = 0x00000020
15+
FlagPrivateVendor TransactionFlags = 0x10000000
16+
)

0 commit comments

Comments
 (0)