session: Fix crash when the UCI option 'password' or 'username' is missing
[project/rpcd.git] / exec.c
diff --git a/exec.c b/exec.c
index f7bfcb2f5e16f550b03e2521c95c3931277e6b91..3cd7384999ad460f979c2ce96e534467d3ecadf2 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -131,13 +131,13 @@ rpc_exec_reply(struct rpc_exec_context *c, int rv)
                        rpc_ustream_to_blobmsg(&c->blob, &c->opipe.stream, "stdout");
                        rpc_ustream_to_blobmsg(&c->blob, &c->epipe.stream, "stderr");
                }
+       }
 
-               if (c->finish_cb)
-                       rv = c->finish_cb(&c->blob, c->stat, c->priv);
+       if (c->finish_cb)
+               rv = c->finish_cb(&c->blob, c->stat, c->priv);
 
-               if (rv == UBUS_STATUS_OK)
-                       ubus_send_reply(c->context, &c->request, c->blob.head);
-       }
+       if (rv == UBUS_STATUS_OK)
+               ubus_send_reply(c->context, &c->request, c->blob.head);
 
        ubus_complete_deferred_request(c->context, &c->request, rv);
 
@@ -313,7 +313,7 @@ rpc_exec(const char **args, rpc_exec_write_cb_t in,
        switch ((pid = fork()))
        {
        case -1:
-               return rpc_errno_status();
+               goto fail_fork;
 
        case 0:
                uloop_done();
@@ -350,7 +350,7 @@ rpc_exec(const char **args, rpc_exec_write_cb_t in,
                uloop_process_add(&c->process);
 
                c->timeout.cb = rpc_exec_timeout_cb;
-               uloop_timeout_set(&c->timeout, RPC_EXEC_MAX_RUNTIME);
+               uloop_timeout_set(&c->timeout, rpc_exec_timeout);
 
                if (c->stdin_cb)
                {
@@ -372,6 +372,10 @@ rpc_exec(const char **args, rpc_exec_write_cb_t in,
 
        return UBUS_STATUS_OK;
 
+fail_fork:
+       close(epipe[0]);
+       close(epipe[1]);
+
 fail_epipe:
        close(opipe[0]);
        close(opipe[1]);
@@ -381,5 +385,6 @@ fail_opipe:
        close(ipipe[1]);
 
 fail_ipipe:
+       free(c);
        return rpc_errno_status();
 }