file: remove unused members from struct rpc_file_exec_context
[project/rpcd.git] / file.c
diff --git a/file.c b/file.c
index a09e9de7a44e846c0e3d0bcabf89ba56ce7a1f92..09b4afd6e97cc5125bfca9beed2f66bc2193119a 100644 (file)
--- a/file.c
+++ b/file.c
@@ -20,6 +20,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
@@ -39,7 +40,6 @@
 
 /* limit of regular files and command output data */
 #define RPC_FILE_MAX_SIZE              (4096 * 64)
-#define RPC_FILE_MAX_RUNTIME   (3 * 1000)
 
 #define ustream_for_each_read_buffer(stream, ptr, len) \
        for (ptr = ustream_get_read_buf(stream, &len);     \
@@ -54,6 +54,8 @@
        us.stream.notify_state  = rpc_file_##name##_state_cb; \
        ustream_fd_init(&us, fd);
 
+static const struct rpc_daemon_ops *ops;
+
 struct rpc_file_exec_context {
        struct ubus_context *context;
        struct ubus_request_data request;
@@ -61,10 +63,6 @@ struct rpc_file_exec_context {
        struct uloop_process process;
        struct ustream_fd opipe;
        struct ustream_fd epipe;
-       int outlen;
-       char *out;
-       int errlen;
-       char *err;
        int stat;
 };
 
@@ -325,7 +323,7 @@ static int
 rpc_file_md5(struct ubus_context *ctx, struct ubus_object *obj,
              struct ubus_request_data *req, const char *method,
              struct blob_attr *msg)
-{ 
+{
        int rv, i;
        char *path;
        struct stat s;
@@ -605,8 +603,8 @@ rpc_file_exec_run(const char *cmd,
        int rem;
        struct blob_attr *cur;
 
-       char arglen;
-       char **args;
+       uint8_t arglen;
+       char **args, **tmp;
 
        struct rpc_file_exec_context *c;
 
@@ -656,11 +654,22 @@ rpc_file_exec_run(const char *cmd,
                                if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
                                        continue;
 
+                               if (arglen == 255)
+                               {
+                                       free(args);
+                                       return UBUS_STATUS_INVALID_ARGUMENT;
+                               }
+
                                arglen++;
+                               tmp = realloc(args, sizeof(char *) * arglen);
 
-                               if (!(args = realloc(args, sizeof(char *) * arglen)))
+                               if (!tmp)
+                               {
+                                       free(args);
                                        return UBUS_STATUS_UNKNOWN_ERROR;
+                               }
 
+                               args = tmp;
                                args[arglen-2] = blobmsg_data(cur);
                                args[arglen-1] = NULL;
                        }
@@ -691,7 +700,7 @@ rpc_file_exec_run(const char *cmd,
                uloop_process_add(&c->process);
 
                c->timeout.cb = rpc_file_exec_timeout_cb;
-               uloop_timeout_set(&c->timeout, RPC_FILE_MAX_RUNTIME);
+               uloop_timeout_set(&c->timeout, *ops->exec_timeout);
 
                close(opipe[1]);
                close(epipe[1]);
@@ -743,6 +752,8 @@ rpc_file_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx)
                .n_methods = ARRAY_SIZE(file_methods),
        };
 
+       ops = o;
+
        return ubus_add_object(ctx, &obj);
 }