Open 2lambda123 opened 2 months ago
Thanks @2lambda123 for opening this issue!
For COLLABORATOR only :
To add labels, comment on the issue
/label add label1,label2,label3
To remove labels, comment on the issue
/label remove label1,label2,label3
First issue by @2lambda123
Issues Details of @2lambda123 in waku-org-go-waku : | OPEN | CLOSED | TOTAL |
---|---|---|---|
1 | 0 | 1 |
The plan to solve the bug involves ensuring that all integer type conversions are safe and appropriate. This includes validating values before conversion, handling potential overflows, and ensuring consistent use of integer types across the codebase. The reasoning behind this solution is to prevent issues such as data loss, overflow, and underflow, which can occur when converting between different integer types, especially between signed and unsigned integers or different integer sizes.
The bug is caused by incorrect conversions between integer types in various parts of the codebase. These conversions can lead to issues such as data loss, overflow, and underflow. Specifically, the following areas are of concern:
float64
, int64
, and int
.options.ClusterID
to uint16
without validation.uint
without validation.Here are the implementation details and code snippets to address the identified issues:
Scaling Resource Limits: Ensure that the conversions are safe and handle potential overflows or precision loss.
memLimit := int64(float64(memory.TotalMemory()) * memPerc / 100)
fdLimit := int(float64(getNumFDs()) * fdPerc / 100)
scaledLimits := limits.Scale(memLimit, fdLimit)
Cluster ID Conversion:
Validate options.ClusterID
before converting it to uint16
.
if options.ClusterID > math.MaxUint16 {
return fmt.Errorf("ClusterID exceeds the maximum value for uint16")
}
node.WithClusterID(uint16(options.ClusterID))
REST Server Port and Cache Capacities:
Validate the values before converting them to uint
.
if options.RESTServer.Port < 0 || options.RESTServer.RelayCacheCapacity < 0 || options.RESTServer.FilterCacheCapacity < 0 {
return fmt.Errorf("REST server port and cache capacities must be non-negative")
}
restConfig := rest.RestConfig{
Address: options.RESTServer.Address,
Port: uint(options.RESTServer.Port),
RelayCacheCapacity: uint(options.RESTServer.RelayCacheCapacity),
FilterCacheCapacity: uint(options.RESTServer.FilterCacheCapacity),
}
Message Size Parsing:
Ensure that the parsed message size does not exceed the maximum value for int
.
msgSize, err := humanize.ParseBytes(msgSizeConfig)
if err != nil {
msgSize = 0
}
if msgSize > math.MaxInt {
return math.MaxInt
}
return int(msgSize)
To replicate the bug, follow these steps:
gowaku
application with the current codebase.ClusterID
to a value greater than 65535
.int
.By following these steps, you should be able to observe the issues caused by incorrect integer type conversions and validate that the proposed solution addresses these issues.
File: cmd/waku/node.go
setupNode
memLimit
, fdLimit
, scaledLimits
, options.ClusterID
, restConfig
, msgSize
File: cmd/waku/options.go
NodeOptions
, RESTServerOptions
File: cmd/waku/flags.go
TcpPort
, MaxPeerConnections
, ClusterID
, Discv5UDPPort
, MinRelayPeersToPublish
, WebsocketPort
, WebsocketSecurePort
, RESTPort
, MetricsServerPort
By implementing the proposed changes, we ensure that all integer type conversions are handled safely and appropriately, preventing potential bugs and vulnerabilities in the gowaku
application.
Click here to create a Pull Request with the proposed solution
Files used for this task:
Not Found
Tracking issue for: