From 12569b46ee09f9635e5af74cba0ad2a92b36f9df Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Sat, 25 Jun 2016 14:24:03 -0400 Subject: [PATCH] Avoid freeing uninitialized pointer. Add -r option to trpc. The trust router can now accept multiple simultaneous connections from trpc programs. The messages are decoded from JSON and then printed to the screen. --- tr/trpc_main.c | 24 +++++++++++++++++++----- trp/trpc.c | 4 ---- trp/trps.c | 4 ++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tr/trpc_main.c b/tr/trpc_main.c index 330b11a..e9e0de6 100644 --- a/tr/trpc_main.c +++ b/tr/trpc_main.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,8 @@ static const char arg_doc[]=" []"; /* string describing /* define the options here. Fields are: * { long-name, short-name, variable name, options, help description } */ static const struct argp_option cmdline_options[] = { - { NULL } + { "repeat", 'r', "N", OPTION_ARG_OPTIONAL, "Repeat message until terminated, or N times." }, + {NULL} }; /* structure for communicating with option parser */ @@ -63,6 +65,7 @@ struct cmdline_args { char *msg; char *server; int port; /* optional */ + int repeat; /* how many times to repeat, or -1 for infinite */ }; /* parser for individual options - fills in a struct cmdline_args */ @@ -72,6 +75,13 @@ static error_t parse_option(int key, char *arg, struct argp_state *state) struct cmdline_args *arguments=state->input; switch (key) { + case 'r': + if (arg==NULL) + arguments->repeat=-1; + else + arguments->repeat=strtol(arg, NULL, 10); + break; + case ARGP_KEY_ARG: /* handle argument (not option) */ switch (state->arg_num) { case 0: @@ -124,6 +134,7 @@ int main (int argc, opts.msg=NULL; opts.server=NULL; opts.port=TRP_PORT; + opts.repeat=1; argp_parse(&argp, argc, argv, 0, 0, &opts); /* TBD -- validity checking, dealing with quotes, etc. */ @@ -153,10 +164,13 @@ int main (int argc, }; /* Send a TRP message */ - if (0 > (rc = trpc_send_msg(trpc, conn, gssctx, opts.msg, NULL, NULL))) { - /* Handle error */ - printf("Error in trpc_send_request, rc = %d.\n", rc); - return 1; + while ((opts.repeat==-1) || (opts.repeat-->0)) { + if (0 > (rc = trpc_send_msg(trpc, conn, gssctx, opts.msg, NULL, NULL))) { + /* Handle error */ + printf("Error in trpc_send_request, rc = %d.\n", rc); + return 1; + } + usleep(1000000); } /* Clean-up the TRP client instance, and exit */ diff --git a/trp/trpc.c b/trp/trpc.c index aab9e21..ef5af85 100644 --- a/trp/trpc.c +++ b/trp/trpc.c @@ -56,8 +56,6 @@ int trpc_send_msg (TRPC_INSTANCE *trpc, int *resp_handler(), void *cookie) { - char *resp_buf=NULL; - size_t resp_buflen=0; int err=0; int rc=0; @@ -75,7 +73,5 @@ int trpc_send_msg (TRPC_INSTANCE *trpc, error: rc = -1; cleanup: - if (resp_buf) - free(resp_buf); return rc; } diff --git a/trp/trps.c b/trp/trps.c index 2576f0e..ea31f86 100644 --- a/trp/trps.c +++ b/trp/trps.c @@ -137,8 +137,8 @@ int trps_auth_cb(gss_name_t clientName, gss_buffer_t displayName, void *data) static TRP_RC trps_read_message(TRPS_INSTANCE *trps, TRP_CONNECTION *conn, TR_MSG **msg) { - int err; - char *buf; + int err=0; + char *buf=NULL; size_t buflen = 0; tr_debug("trps_read_message: started"); -- 2.1.4