Skip to content

Commit

Permalink
Manually terminate grpc addr string to address Coverity hit (#118) (#120
Browse files Browse the repository at this point in the history
)

- Manually terminate grpc addr string to address Coverity hit
- Revise coverity fix (#119)

Signed-off-by: Sabeel Ansari <[email protected]>
Signed-off-by: Derek Foster <[email protected]>
Co-authored-by: Derek G Foster <[email protected]>
  • Loading branch information
5abeel and ffoulkes committed Jul 23, 2024
1 parent 81faec7 commit edd4944
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vswitchd/p4ovs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ char grpc_addr[32] = "localhost:9559";
static const char grpc_port[] = ":9559";

void ovs_set_grpc_addr(const char* optarg) {
if (strlen(optarg) + sizeof(grpc_port) >= sizeof(grpc_addr)) {
ovs_fatal(0, "--grpc_addr is too long (> %lu characters)",
sizeof(grpc_addr) - sizeof(grpc_port));
size_t maximum = sizeof(grpc_addr) - strlen(grpc_port) - 1;
size_t actual = strlen(optarg);

if (actual > maximum) {
ovs_fatal(0, "--grpc-addr (%lu chars) is too long (> %lu chars)",
actual, maximum);
}

strncpy(grpc_addr, optarg, sizeof(grpc_addr));
strcat(grpc_addr, grpc_port);
}
Expand Down

0 comments on commit edd4944

Please sign in to comment.