Skip to content

Commit

Permalink
fix string concat buffer overflow (#1806)
Browse files Browse the repository at this point in the history
* fix string concat buffer overflow

Signed-off-by: kpango <kpango@vdaas.org>

* fix

Signed-off-by: kpango <kpango@vdaas.org>

Signed-off-by: kpango <kpango@vdaas.org>
  • Loading branch information
kpango authored Oct 15, 2022
1 parent 667b2f4 commit 9bcddf0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
9 changes: 5 additions & 4 deletions internal/client/v1/client/discoverer/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,21 @@ func (c *client) discoverAddrs(ctx context.Context, nodes *payload.Info_Nodes, e
case <-ctx.Done():
return nil, ctx.Err()
default:
if node != nil && node.GetPods() != nil && len(node.GetPods().GetPods()) > i {
if node != nil &&
node.GetPods() != nil &&
len(node.GetPods().GetPods()) > i &&
len(node.GetPods().GetPods()[i].GetIp()) != 0 {
addr := net.JoinHostPort(node.GetPods().GetPods()[i].GetIp(), uint16(c.port))
if err = c.connect(ctx, addr); err != nil {
err = errors.ErrAddrCouldNotDiscover(err, addr)
select {
case <-ctx.Done():
return nil, ctx.Err()
case ech <- err:
case ech <- errors.ErrAddrCouldNotDiscover(err, addr):
}
err = nil
} else {
addrs = append(addrs, addr)
}
break
}
}
}
Expand Down
29 changes: 18 additions & 11 deletions internal/net/grpc/errdetails/errdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,29 @@ func AnyToErrorDetail(a *types.Any) proto.Message {

func DebugInfoFromInfoDetail(v *info.Detail) *DebugInfo {
debug := &DebugInfo{
Detail: "Version: " + v.Version + ", " +
"Name: " + v.ServerName + ", " +
"GitCommit: " + v.GitCommit + ", " +
"BuildTime: " + v.BuildTime + ", " +
"NGT_Version: " + v.NGTVersion + ", " +
"Go_Version: " + v.GoVersion + ", " +
"GOARCH: " + v.GoArch + ", " +
"GOOS: " + v.GoOS + ", " +
"CGO_Enabled: " + v.CGOEnabled + ", " +
"BuildCPUInfo: [" + strings.Join(v.BuildCPUInfoFlags, ", ") + "]",
Detail: strings.Join(append(append([]string{
"Version:", v.Version, ",",
"Name:", v.ServerName, ",",
"GitCommit:", v.GitCommit, ",",
"BuildTime:", v.BuildTime, ",",
"NGT_Version:", v.NGTVersion, ",",
"Go_Version:", v.GoVersion, ",",
"GOARCH:", v.GoArch, ",",
"GOOS:", v.GoOS, ",",
"CGO_Enabled:", v.CGOEnabled, ",",
"BuildCPUInfo: [",
}, v.BuildCPUInfoFlags...), "]"), " "),
}
if debug.GetStackEntries() == nil {
debug.StackEntries = make([]string, 0, len(v.StackTrace))
}
for i, stack := range v.StackTrace {
debug.StackEntries = append(debug.GetStackEntries(), "id: "+strconv.Itoa(i)+" stack_trace: "+stack.String())
debug.StackEntries = append(debug.GetStackEntries(), strings.Join([]string{
"id:",
strconv.Itoa(i),
"stack_trace:",
stack.String(),
}, " "))
}
return debug
}

0 comments on commit 9bcddf0

Please sign in to comment.