On 3/17/26 7:55 PM, Mike Pattrick via dev wrote:
> In jsonrpc_session_recv() use nullable_string_is_equal() instead of
> strcmp() in cases where we haven't already checked that the pointer
> isn't NULL.

I'm not sure this is correct, as the code does actually check the
presence of all the required fields in jsonrpc_msg_is_valid().
It checks that any request has a method and that every reply has
an ID and the JSON string can't be NULL.  So the checks below must
be redundant.  Or am I missing something?

Best regards, Ilya Maximets.

> 
> Found with clang analyze.
> 
> Fixes: 4931f33ad9e2 ("ovsdb-server: Factor out complication by using 
> jsonrpc_session.")
> Signed-off-by: Mike Pattrick <[email protected]>
> ---
>  lib/jsonrpc.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
> index f01a2e56f..4a6748a45 100644
> --- a/lib/jsonrpc.c
> +++ b/lib/jsonrpc.c
> @@ -1196,7 +1196,8 @@ jsonrpc_session_recv(struct jsonrpc_session *s)
>          }
>  
>          if (msg) {
> -            if (msg->type == JSONRPC_REQUEST && !strcmp(msg->method, 
> "echo")) {
> +            if (msg->type == JSONRPC_REQUEST &&
> +                nullable_string_is_equal(msg->method, "echo")) {
>                  /* Echo request.  Send reply. */
>                  struct jsonrpc_msg *reply;
>  
> @@ -1204,7 +1205,8 @@ jsonrpc_session_recv(struct jsonrpc_session *s)
>                  jsonrpc_session_send(s, reply);
>              } else if (msg->type == JSONRPC_REPLY
>                         && msg->id && msg->id->type == JSON_STRING
> -                       && !strcmp(json_string(msg->id), "echo")) {
> +                       && nullable_string_is_equal(json_string(msg->id),
> +                                                   "echo")) {
>                  /* It's a reply to our echo request.  Suppress it. */
>              } else {
>                  return msg;

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to