linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org,
	Mariusz Skamra <mariusz.skamra@codecoup.pl>
Cc: Mariusz Skamra <mariusz.skamra@codecoup.pl>
Subject: Re: [PATCH v2] monitor: Fix truncated server socket path parameter
Date: Wed, 04 Aug 2021 16:53:41 +0200	[thread overview]
Message-ID: <2592179.mvXUDI8C0e@ix> (raw)
In-Reply-To: <20210804105446.556937-1-mariusz.skamra@codecoup.pl>

Hello Mariusz,

On Wednesday, 4 August 2021 12:54:46 CEST Mariusz Skamra wrote:
> This fixes the issue of --server <socket> parameter
> last character was dropped. There is no need to use
> strncpy, as the length is already checked, and it is
> known that the destination buffer is big enough
> ---
>  monitor/control.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/monitor/control.c b/monitor/control.c
> index d1ba97d37..266602a34 100644
> --- a/monitor/control.c
> +++ b/monitor/control.c
> @@ -1165,14 +1165,12 @@ static int server_fd = -1;
>  void control_server(const char *path)
>  {
>  	struct sockaddr_un addr;
> -	size_t len;
>  	int fd;
> 
>  	if (server_fd >= 0)
>  		return;
> 
> -	len = strlen(path);
> -	if (len > sizeof(addr.sun_path) - 1) {
> +	if (strlen(path) > sizeof(addr.sun_path) - 1) {
>  		fprintf(stderr, "Socket name too long\n");
>  		return;
>  	}
> @@ -1187,7 +1185,7 @@ void control_server(const char *path)
> 
>  	memset(&addr, 0, sizeof(addr));
>  	addr.sun_family = AF_UNIX;
> -	strncpy(addr.sun_path, path, len - 1);
> +	strcpy(addr.sun_path, path);
> 
>  	if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
>  		perror("Failed to bind server socket");

Patch applied, thanks.

-- 
pozdrawiam
Szymon Janc



      parent reply	other threads:[~2021-08-04 14:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-04  8:59 [PATCH] monitor: Fix truncated server socket path parameter Mariusz Skamra
2021-08-04  9:39 ` bluez.test.bot
2021-08-04 10:54 ` [PATCH v2] " Mariusz Skamra
2021-08-04 11:30   ` [v2] " bluez.test.bot
2021-08-04 14:53   ` Szymon Janc [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2592179.mvXUDI8C0e@ix \
    --to=szymon.janc@codecoup.pl \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mariusz.skamra@codecoup.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).