summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkeithp <keithp@kemper.freedesktop.org>2006-02-15 01:20:50 -0800
committerkeithp <keithp@kemper.freedesktop.org>2006-02-15 01:20:50 -0800
commit68ef6afb329ddbaf1823d278f6129d0f6e70b6b1 (patch)
tree48d1e155e0768442290b68bc7229e95fa7992e53
parent72eb6aa2d433ced0400a5165fc96f776438cd789 (diff)
Check argument for nasty chars. Add diagnostics when something goes wrong
-rw-r--r--ssh-bleach.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/ssh-bleach.c b/ssh-bleach.c
index 00ea33f..41c7bda 100644
--- a/ssh-bleach.c
+++ b/ssh-bleach.c
@@ -21,36 +21,53 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <stdarg.h>
+#include <errno.h>
int verbose = 0;
+void panic (char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ vfprintf (stderr, fmt, ap);
+ va_end (ap);
+ exit (1);
+}
+
int cvs_server (char *line) {
if (verbose)
printf ("cvs server\n");
- return execl ("/usr/bin/cvs", "cvs", "server", NULL);
+ (void) execl ("/usr/bin/cvs", "cvs", "server", NULL);
+ panic ("exec /usr/bin/cvs failed: \"%s\"\n", strerror (errno));
}
+const char bad_chars[] = "\"$%'*;<>?[\\]`|";
+
char *get_quoted_arg (char *line)
{
char *first = strchr (line, '\'');
char *old;
char *last;
char *new, *n;
+ char c;
if (!first)
- return NULL;
+ panic ("Expected quoted argument\n");
last = strrchr (line, '\'');
if (!last || last == first)
- return NULL;
+ panic ("Missing close quote\n");
first++;
new = malloc (last - first + 1);
if (!new)
- return NULL;
+ panic ("Out of memory\n");
n = new;
for (old = first; old < last; old++) {
- if (*old == '\\')
- continue;
- *n++ = *old;
+ c = *old;
+ if (strchr (bad_chars, c))
+ panic ("Invalid character in argument \"%c\"\n", c);
+ *n++ = c;
}
*n++ = '\0';
if (verbose)
@@ -61,27 +78,29 @@ char *get_quoted_arg (char *line)
int git_receive_pack (char *line) {
char *arg = get_quoted_arg (line);
if (! arg)
- return -1;
+ panic ("Missing argument to git-receive-pack\n");
if (verbose)
printf ("git-receive-pack '%s'\n", arg);
- return execl ("/usr/local/bin/git-receive-pack",
- "git-receive-pack",
- arg,
- NULL);
+ execl ("/usr/local/bin/git-receive-pack",
+ "git-receive-pack",
+ arg,
+ NULL);
+ panic ("exec /usr/local/bin/git-receive-pack failed: \"%s\"\n", strerror (errno));
}
int git_upload_pack (char *line) {
char *arg = get_quoted_arg (line);
if (! arg)
- return -1;
+ panic ("Missing argument to git-upload-pack\n");
if (verbose)
printf ("git-upload-pack '%s'\n", arg);
- return execl ("/usr/local/bin/git-upload-pack",
+ (void) execl ("/usr/local/bin/git-upload-pack",
"git-upload-pack",
arg,
NULL);
+ panic ("exec /usr/local/bin/git-receive-pack failed: \"%s\"\n", strerror (errno));
}
struct {
@@ -89,8 +108,8 @@ struct {
int (*command) (char *line);
} commands[] = {
{ "cvs server", cvs_server },
- { "git-receive-pack ", git_receive_pack },
- { "git-upload-pack ", git_upload_pack },
+ { "git-receive-pack", git_receive_pack },
+ { "git-upload-pack", git_upload_pack },
{ 0 }
};
@@ -102,10 +121,10 @@ int main (int argc, char **argv)
if (argv[1] && !strcmp (argv[1], "-v"))
verbose = 1;
if (!line)
- return 1;
+ panic ("Missing original command\n");
for (i = 0; commands[i].name; i++)
if (! strncmp (line, commands[i].name, strlen (commands[i].name)))
if ((*commands[i].command) (line) != 0)
break;
- return 1;
+ panic ("Unsupported command \"%s\"\n", line);
}