[PATCH] libubox: add missing NULL check
Hauke Mehrtens
hauke at hauke-m.de
Sat Aug 20 09:21:51 PDT 2022
On 6/22/22 20:58, Rosen Penev wrote:
> strlen takes non NULL parameters. Found with GCC's -fanalyzer.
>
> Signed-off-by: Rosen Penev <rosenp at gmail.com>
> ---
> blobmsg.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/blobmsg.c b/blobmsg.c
> index d87d607..bb6c469 100644
> --- a/blobmsg.c
> +++ b/blobmsg.c
> @@ -364,6 +364,8 @@ blobmsg_add_string_buffer(struct blob_buf *buf)
> int len, attrlen;
>
> attr = blob_next(buf->head);
> + if (!attr)
> + return;
> len = strlen(blobmsg_data(attr)) + 1;
>
> attrlen = blob_raw_len(attr) + len;
This NULL check does not make much sense. The blob_next() function looks
like this:
static inline struct blob_attr *
blob_next(const struct blob_attr *attr)
{
return (struct blob_attr *) ((char *) attr + blob_pad_len(attr));
}
It is very unlikely that this value gets NULL, we might check if
buf->head is NULL, but I haven't looked into the rest of the code.
Hauke
More information about the openwrt-devel
mailing list