From 8a129e1463a8e30767c0e0de7d060976bb57a5f7 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Wed, 28 May 2008 17:12:01 +0000 Subject: Don't limit ourselfs when it comes to arguments on command line or arguments sent by client. ok joris --- usr.bin/cvs/cvs.c | 70 +++++++++++++++++++++++++++++++++++++--------------- usr.bin/cvs/cvs.h | 4 +-- usr.bin/cvs/server.c | 13 +++++----- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c index c5c4760896c..6e3d0b3729e 100644 --- a/usr.bin/cvs/cvs.c +++ b/usr.bin/cvs/cvs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.c,v 1.144 2008/03/08 20:52:36 tobias Exp $ */ +/* $OpenBSD: cvs.c,v 1.145 2008/05/28 17:12:00 tobias Exp $ */ /* * Copyright (c) 2006, 2007 Joris Vink * Copyright (c) 2004 Jean-Francois Brousseau @@ -123,10 +123,57 @@ usage(void) exit(1); } +int +cvs_build_cmd(char ***cmd_argv, char **argv, int argc) +{ + int cmd_argc, i, cur; + char *cp, *linebuf, *lp; + + if (cmdp->cmd_defargs == NULL) { + *cmd_argv = argv; + return argc; + } + + cur = argc + 2; + cmd_argc = 0; + *cmd_argv = xcalloc(cur, sizeof(char *)); + (*cmd_argv)[cmd_argc++] = argv[0]; + + linebuf = xstrdup(cmdp->cmd_defargs); + for (lp = linebuf; lp != NULL;) { + cp = strsep(&lp, " \t\b\f\n\r\t\v"); + if (cp == NULL) + break; + if (*cp == '\0') + continue; + + if (cmd_argc == cur) { + cur += 8; + *cmd_argv = xrealloc(*cmd_argv, cur, + sizeof(char *)); + } + + (*cmd_argv)[cmd_argc++] = cp; + } + + if (cmd_argc + argc > cur) { + cur = cmd_argc + argc + 1; + *cmd_argv = xrealloc(*cmd_argv, cur, + sizeof(char *)); + } + + for (i = 1; i < argc; i++) + (*cmd_argv)[cmd_argc++] = argv[i]; + + (*cmd_argv)[cmd_argc] = NULL; + + return cmd_argc; +} + int main(int argc, char **argv) { - char *envstr, *cmd_argv[CVS_CMD_MAXARG], **targv; + char *envstr, **cmd_argv, **targv; int i, ret, cmd_argc; struct passwd *pw; struct stat st; @@ -214,24 +261,7 @@ main(int argc, char **argv) cvs_cmdop = cmdp->cmd_op; - cmd_argc = 0; - memset(cmd_argv, 0, sizeof(cmd_argv)); - - cmd_argv[cmd_argc++] = argv[0]; - if (cmdp->cmd_defargs != NULL) { - /* transform into a new argument vector */ - ret = cvs_getargv(cmdp->cmd_defargs, cmd_argv + 1, - CVS_CMD_MAXARG - 1); - if (ret < 0) - fatal("main: cvs_getargv failed"); - - cmd_argc += ret; - } - - if (argc + cmd_argc >= CVS_CMD_MAXARG) - fatal("main: too many arguments for `%s'", cmd_argv[0]); - for (ret = 1; ret < argc; ret++) - cmd_argv[cmd_argc++] = argv[ret]; + cmd_argc = cvs_build_cmd(&cmd_argv, argv, argc); cvs_file_init(); diff --git a/usr.bin/cvs/cvs.h b/usr.bin/cvs/cvs.h index bab48b84acc..718aaeae763 100644 --- a/usr.bin/cvs/cvs.h +++ b/usr.bin/cvs/cvs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.h,v 1.164 2008/03/09 03:14:52 joris Exp $ */ +/* $OpenBSD: cvs.h,v 1.165 2008/05/28 17:12:00 tobias Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -100,7 +100,6 @@ #define CVS_CMD_MAXNAMELEN 16 #define CVS_CMD_MAXALIAS 2 #define CVS_CMD_MAXDESCRLEN 64 -#define CVS_CMD_MAXARG 128 /* flags */ #define CVS_USE_WDIR 0x01 @@ -366,6 +365,7 @@ extern struct cvs_cmd cvs_cmd_watchers; struct cvs_cmd *cvs_findcmd(const char *); /* cvs.c */ +int cvs_build_cmd(char ***, char **, int); int cvs_var_set(const char *, const char *); int cvs_var_unset(const char *); const char *cvs_var_get(const char *); diff --git a/usr.bin/cvs/server.c b/usr.bin/cvs/server.c index 2c1bfa12d99..1be77b4b549 100644 --- a/usr.bin/cvs/server.c +++ b/usr.bin/cvs/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.87 2008/05/06 10:37:30 tobias Exp $ */ +/* $OpenBSD: server.c,v 1.88 2008/05/28 17:12:00 tobias Exp $ */ /* * Copyright (c) 2006 Joris Vink * @@ -72,7 +72,7 @@ int cvs_server(int, char **); char *cvs_server_path = NULL; static char *server_currentdir = NULL; -static char *server_argv[CVS_CMD_MAXARG]; +static char **server_argv; static int server_argc = 1; struct cvs_cmd cvs_cmd_server = { @@ -102,6 +102,7 @@ cvs_server(int argc, char **argv) cvs_server_active = 1; + server_argv = xcalloc(server_argc + 1, sizeof(*server_argv)); server_argv[0] = xstrdup("server"); (void)xasprintf(&cvs_server_path, "%s/cvs-serv%d", cvs_tmpdir, @@ -465,13 +466,13 @@ cvs_server_questionable(char *data) void cvs_server_argument(char *data) { - if (server_argc >= CVS_CMD_MAXARG) - fatal("cvs_server_argument: too many arguments sent"); - if (data == NULL) fatal("Missing argument for Argument"); - server_argv[server_argc++] = xstrdup(data); + server_argv = xrealloc(server_argv, server_argc + 2, + sizeof(*server_argv)); + server_argv[server_argc] = xstrdup(data); + server_argv[++server_argc] = NULL; } void -- cgit v1.2.3