]> andersk Git - moira.git/blobdiff - server/mr_scall.c
detect query with no args
[moira.git] / server / mr_scall.c
index a42f6df5c24d45897a287aaa783c71c257ca7c90..db9e9784dd58c84f067ff9454a16a403b18844c9 100644 (file)
@@ -29,6 +29,11 @@ extern int errno;
 
 extern void clist_delete(), do_auth(), do_shutdown();
 void do_call();
+extern int ingres_errno, mr_errcode;
+static int row_count;
+
+/* Put this in a variable so that we can patch it if necessary */
+int max_row_count = 2048;
 
 /*
  * Welcome to the (finite state) machine (highest level).
@@ -95,6 +100,7 @@ do_call(cl)
        client *cl;
 {
        int pn;
+       extern int ingres_errno;
        cl->reply.mr_argc = 0;
        cl->reply.mr_status = 0;
        cl->reply.mr_version_no = cl->args->mr_version_no;
@@ -118,6 +124,9 @@ do_call(cl)
            return;
        }
 
+       /* make sure this gets cleared before every operation */
+       ingres_errno = 0;
+
        switch(pn) {
        case MR_NOOP:
                cl->reply.mr_status = 0;
@@ -171,17 +180,26 @@ retr_callback(argc, argv, p_cp)
        char *p_cp;
 {
        register client *cp = (client *)p_cp;
+       mr_params *arg_tmp;
+       returned_tuples *tp;
+       OPERATION op_tmp;
+       register char **nargv;
+       register int i;
+
+       if (row_count++ >= max_row_count) {
+           ingres_errno = mr_errcode = MR_NO_MEM;
+           return;
+       }
+
        /*
         * This takes too much advantage of the fact that
         * serialization of the data happens during the queue operation.
         */
-       mr_params *arg_tmp = (mr_params *)db_alloc(sizeof(mr_params));
-       returned_tuples *tp = (returned_tuples *)
-               db_alloc(sizeof(returned_tuples));
-       register char **nargv = (char **)malloc(argc * sizeof(char *));
-       register int i;
+       arg_tmp = (mr_params *)db_alloc(sizeof(mr_params));
+       tp = (returned_tuples *)db_alloc(sizeof(returned_tuples));
+       nargv = (char **)malloc(argc * sizeof(char *));
        
-       OPERATION op_tmp = create_operation();
+       op_tmp = create_operation();
 
        if (mr_trim_args(argc, argv) == MR_NO_MEM) {
            com_err(whoami, MR_NO_MEM, "while trimming args");
@@ -258,7 +276,13 @@ do_retr(cl)
 
        cl->reply.mr_argc = 0;
        cl->reply.mr_status = 0;
+       row_count = 0;
 
+       if (cl->args->mr_argc < 1) {
+           cl->reply.mr_status = MR_ARGS;
+           com_err(whoami, MR_ARGS, "got nameless query");
+           return;
+       }
        queryname = cl->args->mr_argv[0];
        
        if (cl->args->mr_version_no == MR_VERSION_2)
@@ -271,12 +295,17 @@ do_retr(cl)
        else {
                cl->reply.mr_status = 
                        mr_process_query(cl,
-                                         cl->args->mr_argv[0],
+                                         queryname,
                                          cl->args->mr_argc-1,
                                          cl->args->mr_argv+1,
                                          retr_callback,
                                          (char *)cl);
        }
+       if (row_count >= max_row_count) {
+           critical_alert("moirad", "attempted query %s with %d rows\n",
+                          queryname, row_count);
+       }
+
        if (log_flags & LOG_RES)
                com_err(whoami, 0, "Query complete.");
 }
@@ -284,6 +313,11 @@ do_retr(cl)
 do_access(cl)
        client *cl;
 {
+       if (cl->args->mr_argc < 1) {
+           cl->reply.mr_status = MR_ARGS;
+           com_err(whoami, MR_ARGS, "got nameless access");
+           return;
+       }
        cl->reply.mr_argc = 0;
 
        cl->reply.mr_status = 
@@ -350,6 +384,7 @@ client *cl;
     len = read(motd, buffer, sizeof(buffer) - 1);
     close(motd);
     buffer[len] = 0;
+    row_count = 0;
     retr_callback(1, arg, cl);
     cl->reply.mr_status = 0;
 }
This page took 0.035428 seconds and 4 git commands to generate.