Skip to content

Commit

Permalink
fixed some fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Sep 16, 2015
1 parent 43ab7f0 commit e8b9b26
Show file tree
Hide file tree
Showing 53 changed files with 11,697 additions and 3,154 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ regenerate:
make -C test/issue34 regenerate
make -C test/empty-issue70 regenerate
make -C test/indeximport-issue72 regenerate
make -C test/fuzztests regenerate
make gofmt

tests:
Expand Down
35 changes: 22 additions & 13 deletions plugin/unmarshal/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ func (p *unmarshal) Init(g *generator.Generator) {
func (p *unmarshal) decodeVarint(varName string, typName string) {
p.P(`for shift := uint(0); ; shift += 7 {`)
p.In()
p.P(`if shift >= 64 {`)
p.In()
p.P(`return ErrIntOverflow` + p.localName)
p.Out()
p.P(`}`)
p.P(`if iNdEx >= l {`)
p.In()
p.P(`return `, p.ioPkg.Use(), `.ErrUnexpectedEOF`)
Expand Down Expand Up @@ -982,6 +987,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
p.P(`iNdEx := 0`)
p.P(`for iNdEx < l {`)
p.In()
p.P(`preIndex := iNdEx`)
p.P(`var wire uint64`)
p.decodeVarint("wire", "uint64")
p.P(`fieldNum := int32(wire >> 3)`)
Expand Down Expand Up @@ -1102,19 +1108,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
p.P(`} else {`)
p.In()
}
p.P(`var sizeOfWire int`)
p.P(`for {`)
p.In()
p.P(`sizeOfWire++`)
p.P(`wire >>= 7`)
p.P(`if wire == 0 {`)
p.In()
p.P(`break`)
p.Out()
p.P(`}`)
p.Out()
p.P(`}`)
p.P(`iNdEx-=sizeOfWire`)
p.P(`iNdEx=preIndex`)
p.P(`skippy, err := skip`, p.localName, `(data[iNdEx:])`)
p.P(`if err != nil {`)
p.In()
Expand Down Expand Up @@ -1166,6 +1160,11 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
p.P(`}`)
}
p.P()
p.P(`if iNdEx > l {`)
p.In()
p.P(`return ` + p.ioPkg.Use() + `.ErrUnexpectedEOF`)
p.Out()
p.P(`}`)
p.P(`return nil`)
p.Out()
p.P(`}`)
Expand All @@ -1180,6 +1179,9 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflow` + p.localName + `
}
if iNdEx >= l {
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
}
Expand Down Expand Up @@ -1209,6 +1211,9 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflow` + p.localName + `
}
if iNdEx >= l {
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
}
Expand All @@ -1229,6 +1234,9 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflow` + p.localName + `
}
if iNdEx >= l {
return 0, ` + p.ioPkg.Use() + `.ErrUnexpectedEOF
}
Expand Down Expand Up @@ -1264,6 +1272,7 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
var (
ErrInvalidLength` + p.localName + ` = ` + fmtPkg.Use() + `.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflow` + p.localName + ` = ` + fmtPkg.Use() + `.Errorf("proto: integer overflow")
)
`)
}
Expand Down
48 changes: 39 additions & 9 deletions test/casttype/combos/both/casttype.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 39 additions & 9 deletions test/casttype/combos/unmarshaler/casttype.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e8b9b26

Please sign in to comment.