lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8011ae39-d6ba-3dfa-07f1-1a548fd24560@iogearbox.net>
Date:   Fri, 16 Sep 2022 17:53:37 +0200
From:   Daniel Borkmann <daniel@...earbox.net>
To:     Wang Yufen <wangyufen@...wei.com>, andrii@...nel.org,
        ast@...nel.org, martin.lau@...ux.dev, song@...nel.org, yhs@...com,
        john.fastabend@...il.com, kpsingh@...nel.org, sdf@...gle.com,
        haoluo@...gle.com, jolsa@...nel.org, paul.walmsley@...ive.com,
        palmer@...belt.com, aou@...s.berkeley.edu, davem@...emloft.net,
        kuba@...nel.org, hawk@...nel.org, nathan@...nel.org,
        ndesaulniers@...gle.com, trix@...hat.com
Cc:     bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
        netdev@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [bpf-next v2 1/2] libbpf: Add pathname_concat() helper

On 9/16/22 9:36 AM, Wang Yufen wrote:
> Move snprintf and len check to common helper pathname_concat() to make the
> code simpler.
> 
> Signed-off-by: Wang Yufen <wangyufen@...wei.com>
> ---
>   tools/lib/bpf/libbpf.c | 76 +++++++++++++++++++-------------------------------
>   1 file changed, 29 insertions(+), 47 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 3ad1392..7ab977c 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -2096,19 +2096,30 @@ static bool get_map_field_int(const char *map_name, const struct btf *btf,
>   	return true;
>   }
>   
> +static int pathname_concat(const char *path, const char *name, char *buf)
> +{
> +	int len;
> +
> +	len = snprintf(buf, PATH_MAX, "%s/%s", path, name);
> +	if (len < 0)
> +		return -EINVAL;
> +	if (len >= PATH_MAX)
> +		return -ENAMETOOLONG;
> +
> +	return 0;
> +}
> +
>   static int build_map_pin_path(struct bpf_map *map, const char *path)
>   {
>   	char buf[PATH_MAX];
> -	int len;
> +	int err;
>   
>   	if (!path)
>   		path = "/sys/fs/bpf";
>   
> -	len = snprintf(buf, PATH_MAX, "%s/%s", path, bpf_map__name(map));
> -	if (len < 0)
> -		return -EINVAL;
> -	else if (len >= PATH_MAX)
> -		return -ENAMETOOLONG;
> +	err = pathname_concat(path, bpf_map__name(map), buf);

Small nit, but would be good to not make the assumption that buf is always
PATH_MAX so lets add size_t len to pathname_concat().

> +	if (err)
> +		return err;
>   
>   	return bpf_map__set_pin_path(map, buf);
>   }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ