[PATCH 7 of 7] chg: raise the length limit of socket path

Yuya Nishihara yuya at tcha.org
Mon Apr 4 09:35:54 EDT 2016


On Mon, 4 Apr 2016 03:30:54 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1459729375 -3600
> #      Mon Apr 04 01:22:55 2016 +0100
> # Node ID f280444a28189c58641751a01447af1b80978115
> # Parent  f7c6cfae4dba1c48a63bdea1b9aa816e7f634d02
> chg: raise the length limit of socket path
> 
> Previous patches made both the chg server and the client use relative paths
> for connect and bind. Now it's time to raise the length limit. This patch
> replace UNIX_PATH_MAX (usually 107) with PATH_MAX (usually 4096) so chg will
> work even with very long $CHGSOCKNAME as long as the basename is short.
> 
> diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
> --- a/contrib/chg/chg.c
> +++ b/contrib/chg/chg.c
> @@ -25,14 +25,14 @@
>  #include "hgclient.h"
>  #include "util.h"
>  
> -#ifndef UNIX_PATH_MAX
> -#define UNIX_PATH_MAX (sizeof(((struct sockaddr_un *)NULL)->sun_path))
> +#ifndef PATH_MAX
> +#define PATH_MAX 4096
>  #endif
>  
>  struct cmdserveropts {
> -	char sockname[UNIX_PATH_MAX];
> -	char redirectsockname[UNIX_PATH_MAX];
> -	char lockfile[UNIX_PATH_MAX];
> +	char sockname[PATH_MAX];
> +	char redirectsockname[PATH_MAX];
> +	char lockfile[PATH_MAX];

Somewhat related: perhaps, we should keep sockdir and file names separately,
and make the "validate" command return only file names. That will reduce a
possible bug of accessing unsafe socket.

I'm okay to drop CHGSOCKNAME and add CHGSOCKDIR instead, though it would
mean chg can no longer be a client for plain unix command server.


More information about the Mercurial-devel mailing list