Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f2e7186
add _ to generated filename if it ends with _test.go
Apr 22, 2014
a6ed881
use tcxx instead of tr1 in test/cpp
Apr 22, 2014
d1848fa
Merge branch 'master' of https://github.com/apache/thrift into go_int…
Apr 23, 2014
04d22fe
additions:
Apr 25, 2014
ed88d57
Generate lowercase package name
Apr 25, 2014
498a910
Merge branch 'master' into go_test_service_name
Apr 25, 2014
25792d7
add _ to generated filename if it ends with _test.go
Apr 22, 2014
af994b4
additions:
Apr 25, 2014
f22a777
Merge branch 'go_integration' of github.com:apesternikov/thrift into …
Apr 25, 2014
49a33c8
Merge branch 'master' into test_cpp_on_mac
Apr 25, 2014
81b402e
operator < for ThriftTest
Apr 25, 2014
cde312d
minor formatting
Apr 25, 2014
0a69311
Merge branch 'test_cpp_on_mac' into go_integration
Apr 25, 2014
e06b5d2
Merge branch 'go_test_service_name' into go_integration
Apr 25, 2014
42d577c
imported THRIFT-2491
Apr 25, 2014
491ccf8
--noinsane flag for c++ TestClient. works with go server now for othe…
Apr 25, 2014
78db3c9
license
Apr 25, 2014
d3bd076
stress test for go
Apr 26, 2014
69bbf0e
struct should always be a pointer to avoid copying of potentially siz…
May 2, 2014
bfaa863
Merge branch 'master' into go_integration
May 2, 2014
6a4959b
Merge branch 'master' into junk_resilient_protos
May 2, 2014
2cbb79c
Merge branch 'go_integration' into junk_resilient_protos
May 2, 2014
1bb25c4
recover from panic in processor
May 2, 2014
8d1427a
some sanity checks in binary protocol
May 2, 2014
666cc87
some sanity checks in compact protocol
May 2, 2014
64121f4
Merge branch 'master' into junk_resilient_protos
May 10, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions lib/go/thrift/binary_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package thrift

import (
"encoding/binary"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -301,6 +302,8 @@ func (p *TBinaryProtocol) ReadFieldEnd() error {
return nil
}

var invalidDataLength = NewTProtocolExceptionWithType(INVALID_DATA, errors.New("Invalid data length"))

func (p *TBinaryProtocol) ReadMapBegin() (kType, vType TType, size int, err error) {
k, e := p.ReadByte()
if e != nil {
Expand All @@ -315,11 +318,15 @@ func (p *TBinaryProtocol) ReadMapBegin() (kType, vType TType, size int, err erro
}
vType = TType(v)
size32, e := p.ReadI32()
size = int(size32)
if e != nil {
err = NewTProtocolException(e)
return
}
if size32 < 0 {
err = invalidDataLength
return
}
size = int(size32)
return kType, vType, size, nil
}

Expand All @@ -335,12 +342,17 @@ func (p *TBinaryProtocol) ReadListBegin() (elemType TType, size int, err error)
}
elemType = TType(b)
size32, e := p.ReadI32()
size = int(size32)
if e != nil {
err = NewTProtocolException(e)
return
}
return elemType, size, nil
if size32 < 0 {
err = invalidDataLength
return
}
size = int(size32)

return
}

func (p *TBinaryProtocol) ReadListEnd() error {
Expand All @@ -355,11 +367,15 @@ func (p *TBinaryProtocol) ReadSetBegin() (elemType TType, size int, err error) {
}
elemType = TType(b)
size32, e := p.ReadI32()
size = int(size32)
if e != nil {
err = NewTProtocolException(e)
return
}
if size32 < 0 {
err = invalidDataLength
return
}
size = int(size32)
return elemType, size, nil
}

Expand Down Expand Up @@ -413,6 +429,11 @@ func (p *TBinaryProtocol) ReadString() (value string, err error) {
if e != nil {
return "", e
}
if size < 0 {
err = invalidDataLength
return
}

return p.readStringBody(int(size))
}

Expand All @@ -421,6 +442,10 @@ func (p *TBinaryProtocol) ReadBinary() ([]byte, error) {
if e != nil {
return nil, e
}
if size < 0 {
return nil, invalidDataLength
}

isize := int(size)
buf := make([]byte, isize)
_, err := io.ReadFull(p.trans, buf)
Expand Down
20 changes: 18 additions & 2 deletions lib/go/thrift/compact_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,16 @@ func (p *TCompactProtocol) ReadFieldEnd() error { return nil }
// "correct" types.
func (p *TCompactProtocol) ReadMapBegin() (keyType TType, valueType TType, size int, err error) {
size32, e := p.readVarint32()
size = int(size32)
if e != nil {
err = NewTProtocolException(e)
return
}
if size32 < 0 {
err = invalidDataLength
return
}
size = int(size32)

keyAndValueType := byte(STOP)
if size != 0 {
keyAndValueType, err = p.ReadByte()
Expand Down Expand Up @@ -456,6 +461,10 @@ func (p *TCompactProtocol) ReadListBegin() (elemType TType, size int, err error)
err = NewTProtocolException(e)
return
}
if size2 < 0 {
err = invalidDataLength
return
}
size = int(size2)
}
elemType, e := p.getTType(tCompactType(size_and_type))
Expand Down Expand Up @@ -541,6 +550,10 @@ func (p *TCompactProtocol) ReadString() (value string, err error) {
if e != nil {
return "", NewTProtocolException(e)
}
if length < 0 {
return "", invalidDataLength
}

if length == 0 {
return "", nil
}
Expand All @@ -561,7 +574,10 @@ func (p *TCompactProtocol) ReadBinary() (value []byte, err error) {
return nil, NewTProtocolException(e)
}
if length == 0 {
return nil, nil //nil == empty slice
return []byte{}, nil
}
if length < 0 {
return nil, invalidDataLength
}

buf := make([]byte, length)
Expand Down
11 changes: 9 additions & 2 deletions lib/go/thrift/simple_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package thrift

import (
"log"
"runtime/debug"
)

// Simple, non-concurrent server for testing.
Expand Down Expand Up @@ -131,7 +132,7 @@ func (p *TSimpleServer) AcceptLoop() error {
}
if client != nil {
go func() {
if err := p.processRequest(client); err != nil {
if err := p.processRequests(client); err != nil {
log.Println("error processing request:", err)
}
}()
Expand All @@ -154,12 +155,17 @@ func (p *TSimpleServer) Stop() error {
return nil
}

func (p *TSimpleServer) processRequest(client TTransport) error {
func (p *TSimpleServer) processRequests(client TTransport) error {
processor := p.processorFactory.GetProcessor(client)
inputTransport := p.inputTransportFactory.GetTransport(client)
outputTransport := p.outputTransportFactory.GetTransport(client)
inputProtocol := p.inputProtocolFactory.GetProtocol(inputTransport)
outputProtocol := p.outputProtocolFactory.GetProtocol(outputTransport)
defer func() {
if e := recover(); e != nil {
log.Printf("panic in processor: %s: %s", e, debug.Stack())
}
}()
if inputTransport != nil {
defer inputTransport.Close()
}
Expand All @@ -171,6 +177,7 @@ func (p *TSimpleServer) processRequest(client TTransport) error {
if err, ok := err.(TTransportException); ok && err.TypeId() == END_OF_FILE {
return nil
} else if err != nil {
log.Printf("error procesing request: %s", err)
return err
}
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion test/go/src/common/mock_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
package common

import (
thrifttest "gen/thrifttest"
gomock "code.google.com/p/gomock/gomock"
thrifttest "gen/thrifttest"
)

// Mock of ThriftTest interface
Expand Down