test(registry): check bind body encoding and version-0 globals
- commit
- 048fbd6c132716e1d7a2d96656905aa797cfd674
- author
- brice · · 2026-10-01 05:55 UTC
- parent
- 328be2b
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +22 -4
M registry_test.go +22 -4
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | package wlturbo | |
| 4 | 4 | ||
| 5 | 5 | import ( | |
| 6 | + | "bytes" | |
| 6 | 7 | "encoding/binary" | |
| 7 | 8 | "errors" | |
| 8 | 9 | "io" | |
| @@ -82,6 +83,19 @@ func TestBindNegotiated(t *testing.T) { | |||
| 82 | 83 | t.Fatalf("supported zero: %d %v", v, err) | |
| 83 | 84 | } | |
| 84 | 85 | ||
| 86 | + | // A global announced at version 0 is unusable. | |
| 87 | + | sendMessageWithFDs(t, peer, globalEvent(reg.ID(), 29, iface, 0), nil) | |
| 88 | + | if err := d.Dispatch(); err != nil { | |
| 89 | + | t.Fatal(err) | |
| 90 | + | } | |
| 91 | + | if v, err := reg.BindNegotiated(iface, 6, &BaseProxy{}); v != 0 || !errors.Is(err, ErrGlobalNotFound) { | |
| 92 | + | t.Fatalf("announced version 0: %d %v", v, err) | |
| 93 | + | } | |
| 94 | + | sendMessageWithFDs(t, peer, message(reg.ID(), 1, u32Body(29)), nil) | |
| 95 | + | if err := d.Dispatch(); err != nil { | |
| 96 | + | t.Fatal(err) | |
| 97 | + | } | |
| 98 | + | ||
| 85 | 99 | for i, announced := range []uint32{2, 9} { | |
| 86 | 100 | name := uint32(30 + i) | |
| 87 | 101 | sendMessageWithFDs(t, peer, globalEvent(reg.ID(), name, iface, announced), nil) | |
| @@ -101,11 +115,15 @@ func TestBindNegotiated(t *testing.T) { | |||
| 101 | 115 | t.Fatalf("announced=%d negotiated=%d proxy version=%d, want %d", announced, negotiated, proxy.Version(), want) | |
| 102 | 116 | } | |
| 103 | 117 | obj, op, body := readRequest(t, peer) | |
| 104 | - | // bind: name, string interface, version, new_id. | |
| 105 | - | if obj != reg.ID() || op != 0 || | |
| 118 | + | // bind: name, string (length incl. NUL, NUL, padding), version, new_id. | |
| 119 | + | padded := (len(iface) + 1 + 3) &^ 3 | |
| 120 | + | if obj != reg.ID() || op != 0 || len(body) != 4+4+padded+4+4 || | |
| 106 | 121 | binary.LittleEndian.Uint32(body) != name || | |
| 107 | - | binary.LittleEndian.Uint32(body[len(body)-8:]) != want || | |
| 108 | - | binary.LittleEndian.Uint32(body[len(body)-4:]) != proxy.ID() { | |
| 122 | + | binary.LittleEndian.Uint32(body[4:]) != uint32(len(iface)+1) || | |
| 123 | + | string(body[8:8+len(iface)]) != iface || | |
| 124 | + | !bytes.Equal(body[8+len(iface):8+padded], make([]byte, padded-len(iface))) || | |
| 125 | + | binary.LittleEndian.Uint32(body[8+padded:]) != want || | |
| 126 | + | binary.LittleEndian.Uint32(body[8+padded+4:]) != proxy.ID() { | |
| 109 | 127 | t.Fatalf("bind object=%d opcode=%d body=%x", obj, op, body) | |
| 110 | 128 | } | |
| 111 | 129 | // Remove the global so the next iteration is the only match. | |
| @@ -3,6 +3,7 @@ | |||||
| 3 | package wlturbo | 3 | package wlturbo | ||
| 4 | 4 | ||||
| 5 | import ( | 5 | import ( | ||
| 6 | + | "bytes" | |||
| 6 | "encoding/binary" | 7 | "encoding/binary" | ||
| 7 | "errors" | 8 | "errors" | ||
| 8 | "io" | 9 | "io" | ||
| @@ -82,6 +83,19 @@ func TestBindNegotiated(t *testing.T) { | |||||
| 82 | t.Fatalf("supported zero: %d %v", v, err) | 83 | t.Fatalf("supported zero: %d %v", v, err) | ||
| 83 | } | 84 | } | ||
| 84 | 85 | ||||
| 86 | + | // A global announced at version 0 is unusable. | |||
| 87 | + | sendMessageWithFDs(t, peer, globalEvent(reg.ID(), 29, iface, 0), nil) | |||
| 88 | + | if err := d.Dispatch(); err != nil { | |||
| 89 | + | t.Fatal(err) | |||
| 90 | + | } | |||
| 91 | + | if v, err := reg.BindNegotiated(iface, 6, &BaseProxy{}); v != 0 || !errors.Is(err, ErrGlobalNotFound) { | |||
| 92 | + | t.Fatalf("announced version 0: %d %v", v, err) | |||
| 93 | + | } | |||
| 94 | + | sendMessageWithFDs(t, peer, message(reg.ID(), 1, u32Body(29)), nil) | |||
| 95 | + | if err := d.Dispatch(); err != nil { | |||
| 96 | + | t.Fatal(err) | |||
| 97 | + | } | |||
| 98 | + | ||||
| 85 | for i, announced := range []uint32{2, 9} { | 99 | for i, announced := range []uint32{2, 9} { | ||
| 86 | name := uint32(30 + i) | 100 | name := uint32(30 + i) | ||
| 87 | sendMessageWithFDs(t, peer, globalEvent(reg.ID(), name, iface, announced), nil) | 101 | sendMessageWithFDs(t, peer, globalEvent(reg.ID(), name, iface, announced), nil) | ||
| @@ -101,11 +115,15 @@ func TestBindNegotiated(t *testing.T) { | |||||
| 101 | t.Fatalf("announced=%d negotiated=%d proxy version=%d, want %d", announced, negotiated, proxy.Version(), want) | 115 | t.Fatalf("announced=%d negotiated=%d proxy version=%d, want %d", announced, negotiated, proxy.Version(), want) | ||
| 102 | } | 116 | } | ||
| 103 | obj, op, body := readRequest(t, peer) | 117 | obj, op, body := readRequest(t, peer) | ||
| 104 | - | // bind: name, string interface, version, new_id. | 118 | + | // bind: name, string (length incl. NUL, NUL, padding), version, new_id. |
| 105 | - | if obj != reg.ID() || op != 0 || | 119 | + | padded := (len(iface) + 1 + 3) &^ 3 |
| 120 | + | if obj != reg.ID() || op != 0 || len(body) != 4+4+padded+4+4 || | |||
| 106 | binary.LittleEndian.Uint32(body) != name || | 121 | binary.LittleEndian.Uint32(body) != name || | ||
| 107 | - | binary.LittleEndian.Uint32(body[len(body)-8:]) != want || | 122 | + | binary.LittleEndian.Uint32(body[4:]) != uint32(len(iface)+1) || |
| 108 | - | binary.LittleEndian.Uint32(body[len(body)-4:]) != proxy.ID() { | 123 | + | string(body[8:8+len(iface)]) != iface || |
| 124 | + | !bytes.Equal(body[8+len(iface):8+padded], make([]byte, padded-len(iface))) || | |||
| 125 | + | binary.LittleEndian.Uint32(body[8+padded:]) != want || | |||
| 126 | + | binary.LittleEndian.Uint32(body[8+padded+4:]) != proxy.ID() { | |||
| 109 | t.Fatalf("bind object=%d opcode=%d body=%x", obj, op, body) | 127 | t.Fatalf("bind object=%d opcode=%d body=%x", obj, op, body) | ||
| 110 | } | 128 | } | ||
| 111 | // Remove the global so the next iteration is the only match. | 129 | // Remove the global so the next iteration is the only match. | ||