[PATCH 3 of 3 V2] chg: pass sensitive command line flags to server
Yuya Nishihara
yuya at tcha.org
Fri Feb 19 09:00:28 EST 2016
On Wed, 17 Feb 2016 15:08:59 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1455721247 0
> # Wed Feb 17 15:00:47 2016 +0000
> # Node ID f9a49a0f18b29248fb86f3b1b1693b77207ef4ac
> # Parent a87f14c869a38406eab0595b514b915e6b6391a6
> chg: pass sensitive command line flags to server
>
> We are going to make chgserver load repo config, remember what it is, and
> load repo config again to detect config change. This is the first step that
> passes config, repo, cwd options to server. Traceback is passed as well to
> cover errors before hitting chgserver.runcommand.
Pushed revised version to the clowncopter, thanks.
> char sockname[UNIX_PATH_MAX];
> char lockfile[UNIX_PATH_MAX];
> char pidfile[UNIX_PATH_MAX];
> + size_t argsize;
> + const char **args;
Since you've changed the type of argsize, I updated most of "int"s to size_t.
> + * Test if an argument is a sensitive flag that should be passed to the server.
> + * Return 0 if not, otherwise the number of arguments starting from the current
> + * one that should be passed to the server.
> + */
> +static int testsensetiveflag(const char *arg)
s/sensetive/sensitive/g :)
> +static void setcmdserverargs(struct cmdserveropts *opts,
> + int argc, const char *argv[])
> +{
> + int i, step;
> + opts->argsize = 0;
> + for (i = 0, step = 1; i < argc; i += step, step = 1) {
> + if (!argv[i]) continue; /* pass clang-analyse */
> + if (strcmp(argv[i], "--") == 0) break;
> + int n = testsensetiveflag(argv[i]);
> + if (n == 0 || i + n > argc) continue;
> + opts->args = reallocx(opts->args, (n + opts->argsize) * sizeof(char*));
> + memcpy(opts->args + opts->argsize, argv + i, sizeof(char*) * n);
> + opts->argsize += n;
> + step = n;
> + }
Hmm, it will actually reallocate 'args' buffer incrementally. Though glibc
malloc() seems to reuse old 'args' location as there are no other malloc/free,
I don't think it is a good design.
More information about the Mercurial-devel
mailing list