Avoid freeing uninitialized pointer. Add -r option to trpc.
authorJennifer Richards <jennifer@painless-security.com>
Sat, 25 Jun 2016 18:24:03 +0000 (14:24 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Sat, 25 Jun 2016 18:24:03 +0000 (14:24 -0400)
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
trp/trpc.c
trp/trps.c

index 330b11a..e9e0de6 100644 (file)
@@ -36,6 +36,7 @@
 #include <stdio.h>
 #include <talloc.h>
 #include <argp.h>
+#include <unistd.h>
 
 #include <gsscon.h>
 #include <tr_debug.h>
@@ -55,7 +56,8 @@ static const char arg_doc[]="<message> <server> [<port>]"; /* 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 */
index aab9e21..ef5af85 100644 (file)
@@ -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;
 }
index 2576f0e..ea31f86 100644 (file)
@@ -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");