Skip to content

Commit ab84d04

Browse files
committed
ndr64: fix trailing gap / fix int3264 alignment
1 parent 1881846 commit ab84d04

File tree

58 files changed

+2819
-29
lines changed

Some content is hidden

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

58 files changed

+2819
-29
lines changed

codegen/gen/gen.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ func (p *Generator) GenType(ctx context.Context, t *midl.Type) {
288288
}
289289
}
290290

291+
func (p *Generator) GenDoTrailingGapMarshalNDR(ctx context.Context, gap int) {
292+
if gap > 1 {
293+
p.CheckErr(p.B("w.WriteTrailingGap", gap))
294+
}
295+
}
296+
291297
func (p *Generator) GenDoAlignmentMarshalNDR(ctx context.Context, alignment int) {
292298
if alignment > 1 {
293299
p.CheckErr(p.B("w.WriteAlign", alignment))
@@ -300,6 +306,12 @@ func (p *Generator) GenDoUnionAlignemntMarshalNDR(ctx context.Context, alignment
300306
}
301307
}
302308

309+
func (p *Generator) GenDoTrailingGapUnmarshalNDR(ctx context.Context, gap int) {
310+
if gap > 1 {
311+
p.CheckErr(p.B("w.ReadTrailingGap", gap))
312+
}
313+
}
314+
303315
func (p *Generator) GenDoAlignmentUnmarshalNDR(ctx context.Context, alignment int) {
304316
if alignment > 1 {
305317
p.CheckErr(p.B("w.ReadAlign", alignment))

codegen/gen/scopes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func (i *Scopes) Alignment() int {
227227
if a != 5 {
228228
return a
229229
}
230+
230231
return a + i.alignment(true)
231232
}
232233

codegen/gen/type.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@ func (p *TypeGenerator) GenStructMarshalNDRSizePreamble(ctx context.Context, fie
495495

496496
func (p *TypeGenerator) GenStructMarshalNDR(ctx context.Context) {
497497

498+
trailingField := len(p.Struct().Fields) - 1
499+
if p.IsConformant() || p.IsVarying() {
500+
trailingField--
501+
}
502+
498503
p.Block("func", "(o *"+p.GoTypeName+")", "MarshalNDR(ctx context.Context, w ndr.Writer)", "error", func() {
499504
// prepare payload.
500505
p.CheckErr("o." + p.XXX() + "PreparePayload(ctx)")
@@ -503,9 +508,15 @@ func (p *TypeGenerator) GenStructMarshalNDR(ctx context.Context) {
503508
// align the structure.
504509
p.GenDoAlignmentMarshalNDR(ctx, p.Alignment())
505510
// marshal fields.
506-
for _, field := range p.Struct().Fields {
511+
for i, field := range p.Struct().Fields {
507512
// marshal field.
508513
p.GenFieldMarshalNDR(ctx, field, NewScopes(field.Scopes()))
514+
// add trailing gap.
515+
if i == trailingField {
516+
if f := NewScopes(field.Scopes()); f.alignment(false) != p.alignment(false) {
517+
p.GenDoTrailingGapMarshalNDR(ctx, p.Alignment())
518+
}
519+
}
509520
}
510521
if p.Scope().Pad != 0 {
511522
p.P("//", "pad", p.Scope().Pad)

codegen/gen/type_unmarshal.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ import (
88

99
func (p *TypeGenerator) GenStructUnmarshalNDR(ctx context.Context) {
1010

11+
trailingField := len(p.Struct().Fields) - 1
12+
if p.IsConformant() || p.IsVarying() {
13+
trailingField--
14+
}
15+
1116
p.Block("func", "(o *"+p.GoTypeName+")", "UnmarshalNDR(ctx context.Context, w ndr.Reader)", "error", func() {
1217
// write size information.
1318
p.GenStructUnmarshalNDRSizePreamble(ctx, p.StructLastField())
1419
// align the structure.
1520
p.GenDoAlignmentUnmarshalNDR(ctx, p.Alignment())
1621
// unmarshal fields.
17-
for _, field := range p.Struct().Fields {
22+
for i, field := range p.Struct().Fields {
1823
p.GenFieldUnmarshalNDR(ctx, field, NewScopes(field.Scopes()))
24+
if i == trailingField {
25+
if f := NewScopes(field.Scopes()); f.alignment(false) != p.alignment(false) {
26+
p.GenDoTrailingGapUnmarshalNDR(ctx, p.Alignment())
27+
}
28+
}
1929
}
2030
if p.Scope().Pad != 0 {
2131
p.P("//", "pad", p.Scope().Pad)

midl/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ func PrimitiveTypeSize(kind Kind) int {
781781
case TypeFloat64, TypeUint64, TypeInt64:
782782
ret = 8
783783
case TypeInt32_64, TypeUint32_64:
784-
return 5
784+
return 4
785785
}
786786

787787
return ret

msrpc/adts/adts.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ func (o *PACCredentialInfo) MarshalNDR(ctx context.Context, w ndr.Writer) error
275275
return err
276276
}
277277
}
278+
if err := w.WriteTrailingGap(4); err != nil {
279+
return err
280+
}
278281
return nil
279282
}
280283
func (o *PACCredentialInfo) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -294,6 +297,9 @@ func (o *PACCredentialInfo) UnmarshalNDR(ctx context.Context, w ndr.Reader) erro
294297
return err
295298
}
296299
}
300+
if err := w.ReadTrailingGap(4); err != nil {
301+
return err
302+
}
297303
return nil
298304
}
299305

@@ -458,6 +464,9 @@ func (o *PACCredentialData) MarshalNDR(ctx context.Context, w ndr.Writer) error
458464
if err := w.WriteData(o.CredentialCount); err != nil {
459465
return err
460466
}
467+
if err := w.WriteTrailingGap(9); err != nil {
468+
return err
469+
}
461470
for i1 := range o.Credentials {
462471
i1 := i1
463472
if uint64(i1) >= sizeInfo[0] {
@@ -497,6 +506,9 @@ func (o *PACCredentialData) UnmarshalNDR(ctx context.Context, w ndr.Reader) erro
497506
if err := w.ReadData(&o.CredentialCount); err != nil {
498507
return err
499508
}
509+
if err := w.ReadTrailingGap(9); err != nil {
510+
return err
511+
}
500512
// XXX: for opaque unmarshaling
501513
if o.CredentialCount > 0 && sizeInfo[0] == 0 {
502514
sizeInfo[0] = uint64(o.CredentialCount)
@@ -565,6 +577,9 @@ func (o *PACClientInfo) MarshalNDR(ctx context.Context, w ndr.Writer) error {
565577
return err
566578
}
567579
}
580+
if err := w.WriteTrailingGap(4); err != nil {
581+
return err
582+
}
568583
return nil
569584
}
570585
func (o *PACClientInfo) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -587,6 +602,9 @@ func (o *PACClientInfo) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
587602
return err
588603
}
589604
}
605+
if err := w.ReadTrailingGap(4); err != nil {
606+
return err
607+
}
590608
return nil
591609
}
592610

@@ -647,6 +665,9 @@ func (o *NTLMSupplementalCredential) MarshalNDR(ctx context.Context, w ndr.Write
647665
return err
648666
}
649667
}
668+
if err := w.WriteTrailingGap(4); err != nil {
669+
return err
670+
}
650671
return nil
651672
}
652673
func (o *NTLMSupplementalCredential) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -673,6 +694,9 @@ func (o *NTLMSupplementalCredential) UnmarshalNDR(ctx context.Context, w ndr.Rea
673694
return err
674695
}
675696
}
697+
if err := w.ReadTrailingGap(4); err != nil {
698+
return err
699+
}
676700
return nil
677701
}
678702

@@ -818,6 +842,9 @@ func (o *KerberosSIDAndAttributes) MarshalNDR(ctx context.Context, w ndr.Writer)
818842
if err := w.WriteData(o.Attributes); err != nil {
819843
return err
820844
}
845+
if err := w.WriteTrailingGap(9); err != nil {
846+
return err
847+
}
821848
return nil
822849
}
823850
func (o *KerberosSIDAndAttributes) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -840,6 +867,9 @@ func (o *KerberosSIDAndAttributes) UnmarshalNDR(ctx context.Context, w ndr.Reade
840867
if err := w.ReadData(&o.Attributes); err != nil {
841868
return err
842869
}
870+
if err := w.ReadTrailingGap(9); err != nil {
871+
return err
872+
}
843873
return nil
844874
}
845875

msrpc/cmrp/clusapi2/v2/v2.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,9 @@ func (o *SecurityDescriptor) MarshalNDR(ctx context.Context, w ndr.Writer) error
865865
if err := w.WriteData(o.OutSecurityDescriptorLength); err != nil {
866866
return err
867867
}
868+
if err := w.WriteTrailingGap(9); err != nil {
869+
return err
870+
}
868871
return nil
869872
}
870873
func (o *SecurityDescriptor) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -910,6 +913,9 @@ func (o *SecurityDescriptor) UnmarshalNDR(ctx context.Context, w ndr.Reader) err
910913
if err := w.ReadData(&o.OutSecurityDescriptorLength); err != nil {
911914
return err
912915
}
916+
if err := w.ReadTrailingGap(9); err != nil {
917+
return err
918+
}
913919
return nil
914920
}
915921

@@ -963,6 +969,9 @@ func (o *SecurityAttributes) MarshalNDR(ctx context.Context, w ndr.Writer) error
963969
if err := w.WriteData(o.InheritHandle); err != nil {
964970
return err
965971
}
972+
if err := w.WriteTrailingGap(9); err != nil {
973+
return err
974+
}
966975
return nil
967976
}
968977
func (o *SecurityAttributes) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -981,6 +990,9 @@ func (o *SecurityAttributes) UnmarshalNDR(ctx context.Context, w ndr.Reader) err
981990
if err := w.ReadData(&o.InheritHandle); err != nil {
982991
return err
983992
}
993+
if err := w.ReadTrailingGap(9); err != nil {
994+
return err
995+
}
984996
return nil
985997
}
986998

@@ -1450,6 +1462,9 @@ func (o *EnumList) MarshalNDR(ctx context.Context, w ndr.Writer) error {
14501462
if err := w.WriteData(o.EntryCount); err != nil {
14511463
return err
14521464
}
1465+
if err := w.WriteTrailingGap(9); err != nil {
1466+
return err
1467+
}
14531468
for i1 := range o.Entry {
14541469
i1 := i1
14551470
if uint64(i1) >= sizeInfo[0] {
@@ -1489,6 +1504,9 @@ func (o *EnumList) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
14891504
if err := w.ReadData(&o.EntryCount); err != nil {
14901505
return err
14911506
}
1507+
if err := w.ReadTrailingGap(9); err != nil {
1508+
return err
1509+
}
14921510
// XXX: for opaque unmarshaling
14931511
if o.EntryCount > 0 && sizeInfo[0] == 0 {
14941512
sizeInfo[0] = uint64(o.EntryCount)

msrpc/cmrp/clusapi3/v3/v3.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,9 @@ func (o *SecurityDescriptor) MarshalNDR(ctx context.Context, w ndr.Writer) error
19351935
if err := w.WriteData(o.OutSecurityDescriptorLength); err != nil {
19361936
return err
19371937
}
1938+
if err := w.WriteTrailingGap(9); err != nil {
1939+
return err
1940+
}
19381941
return nil
19391942
}
19401943
func (o *SecurityDescriptor) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -1980,6 +1983,9 @@ func (o *SecurityDescriptor) UnmarshalNDR(ctx context.Context, w ndr.Reader) err
19801983
if err := w.ReadData(&o.OutSecurityDescriptorLength); err != nil {
19811984
return err
19821985
}
1986+
if err := w.ReadTrailingGap(9); err != nil {
1987+
return err
1988+
}
19831989
return nil
19841990
}
19851991

@@ -2033,6 +2039,9 @@ func (o *SecurityAttributes) MarshalNDR(ctx context.Context, w ndr.Writer) error
20332039
if err := w.WriteData(o.InheritHandle); err != nil {
20342040
return err
20352041
}
2042+
if err := w.WriteTrailingGap(9); err != nil {
2043+
return err
2044+
}
20362045
return nil
20372046
}
20382047
func (o *SecurityAttributes) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -2051,6 +2060,9 @@ func (o *SecurityAttributes) UnmarshalNDR(ctx context.Context, w ndr.Reader) err
20512060
if err := w.ReadData(&o.InheritHandle); err != nil {
20522061
return err
20532062
}
2063+
if err := w.ReadTrailingGap(9); err != nil {
2064+
return err
2065+
}
20542066
return nil
20552067
}
20562068

@@ -2647,6 +2659,9 @@ func (o *EnumList) MarshalNDR(ctx context.Context, w ndr.Writer) error {
26472659
if err := w.WriteData(o.EntryCount); err != nil {
26482660
return err
26492661
}
2662+
if err := w.WriteTrailingGap(9); err != nil {
2663+
return err
2664+
}
26502665
for i1 := range o.Entry {
26512666
i1 := i1
26522667
if uint64(i1) >= sizeInfo[0] {
@@ -2686,6 +2701,9 @@ func (o *EnumList) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
26862701
if err := w.ReadData(&o.EntryCount); err != nil {
26872702
return err
26882703
}
2704+
if err := w.ReadTrailingGap(9); err != nil {
2705+
return err
2706+
}
26892707
// XXX: for opaque unmarshaling
26902708
if o.EntryCount > 0 && sizeInfo[0] == 0 {
26912709
sizeInfo[0] = uint64(o.EntryCount)
@@ -3327,6 +3345,9 @@ func (o *GroupEnumList) MarshalNDR(ctx context.Context, w ndr.Writer) error {
33273345
if err := w.WriteData(o.EntryCount); err != nil {
33283346
return err
33293347
}
3348+
if err := w.WriteTrailingGap(9); err != nil {
3349+
return err
3350+
}
33303351
for i1 := range o.Entry {
33313352
i1 := i1
33323353
if uint64(i1) >= sizeInfo[0] {
@@ -3366,6 +3387,9 @@ func (o *GroupEnumList) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
33663387
if err := w.ReadData(&o.EntryCount); err != nil {
33673388
return err
33683389
}
3390+
if err := w.ReadTrailingGap(9); err != nil {
3391+
return err
3392+
}
33693393
// XXX: for opaque unmarshaling
33703394
if o.EntryCount > 0 && sizeInfo[0] == 0 {
33713395
sizeInfo[0] = uint64(o.EntryCount)
@@ -3437,6 +3461,9 @@ func (o *ResourceEnumList) MarshalNDR(ctx context.Context, w ndr.Writer) error {
34373461
if err := w.WriteData(o.EntryCount); err != nil {
34383462
return err
34393463
}
3464+
if err := w.WriteTrailingGap(9); err != nil {
3465+
return err
3466+
}
34403467
for i1 := range o.Entry {
34413468
i1 := i1
34423469
if uint64(i1) >= sizeInfo[0] {
@@ -3476,6 +3503,9 @@ func (o *ResourceEnumList) UnmarshalNDR(ctx context.Context, w ndr.Reader) error
34763503
if err := w.ReadData(&o.EntryCount); err != nil {
34773504
return err
34783505
}
3506+
if err := w.ReadTrailingGap(9); err != nil {
3507+
return err
3508+
}
34793509
// XXX: for opaque unmarshaling
34803510
if o.EntryCount > 0 && sizeInfo[0] == 0 {
34813511
sizeInfo[0] = uint64(o.EntryCount)
@@ -3752,6 +3782,9 @@ func (o *NotificationDataRPC) MarshalNDR(ctx context.Context, w ndr.Writer) erro
37523782
return err
37533783
}
37543784
}
3785+
if err := w.WriteTrailingGap(8); err != nil {
3786+
return err
3787+
}
37553788
return nil
37563789
}
37573790
func (o *NotificationDataRPC) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
@@ -3836,6 +3869,9 @@ func (o *NotificationDataRPC) UnmarshalNDR(ctx context.Context, w ndr.Reader) er
38363869
if err := w.ReadPointer(&o.Type, _s_Type, _ptr_Type); err != nil {
38373870
return err
38383871
}
3872+
if err := w.ReadTrailingGap(8); err != nil {
3873+
return err
3874+
}
38393875
return nil
38403876
}
38413877

0 commit comments

Comments
 (0)