On Fri, Apr 08, 2016 at 11:43:52AM +0100, David CARLIER wrote:
> Subject: [PATCH 4/4] CLEANUP: proto_uxst: initialize socket before setting.
>
> Initializes the socket before usage. However, there might
> be then a slight impact performance hit.
> ---
> src/proto_uxst.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/proto_uxst.c b/src/proto_uxst.c
> index b2a7fe2..3fa9504 100644
> --- a/src/proto_uxst.c
> +++ b/src/proto_uxst.c
> @@ -131,6 +131,7 @@ static void destroy_uxst_socket(const char *path)
> if (sock < 0)
> return;
>
> + memset(&addr, 0, sizeof(addr));
> addr.sun_family = AF_UNIX;
> strncpy(addr.sun_path, path, sizeof(addr.sun_path));
> addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
This first one is useless, it's already done by strncpy() which fills the
rest of the path with zeroes.
> @@ -191,6 +192,7 @@ static int uxst_bind_listener(struct listener *listener,
> char *errmsg, int errle
> if (ext)
> goto fd_ready;
>
> + memset(&addr, 0, sizeof(addr));
> if (path[0]) {
> ret = snprintf(tempname, MAXPATHLEN, "%s.%d.tmp", path, pid);
> if (ret < 0 || ret >= MAXPATHLEN) {
And this one is only used for real unix sockets (not abstract ones) so it
stops at the trailing zero, thus it is not needed.
Or maybe I missed something regarding the purpose of this fix ?
Thanks,
Willy