properly handle return codes
authorJohn Crispin <blogic@openwrt.org>
Sat, 28 Mar 2015 16:05:56 +0000 (17:05 +0100)
committerJohn Crispin <blogic@openwrt.org>
Sat, 28 Mar 2015 17:36:40 +0000 (18:36 +0100)
Signed-off-by: John Crispin <blogic@openwrt.org>
file.c
plugin.c
session.c

diff --git a/file.c b/file.c
index 31a937dec0dc975104c471a18e3c91e48f3e421b..3831c547db8dced04c6f6e623c9c47ea060729dd 100644 (file)
--- a/file.c
+++ b/file.c
@@ -221,7 +221,7 @@ rpc_file_write(struct ubus_context *ctx, struct ubus_object *obj,
        if (!tb[RPC_F_RW_PATH] || !tb[RPC_F_RW_DATA])
                return UBUS_STATUS_INVALID_ARGUMENT;
 
-       if ((fd = open(blobmsg_data(tb[RPC_F_RW_PATH]), O_CREAT | O_TRUNC | O_WRONLY)) < 0)
+       if ((fd = open(blobmsg_data(tb[RPC_F_RW_PATH]), O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0)
                return rpc_errno_status();
 
        if (write(fd, blobmsg_data(tb[RPC_F_RW_DATA]), blobmsg_data_len(tb[RPC_F_RW_DATA])) < 0)
index b75241aae1f82ce0a84b5d40c1c74b2e8c0577ed..70d2c563ba3f12329b138481be12f825efd2f2ea 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -324,7 +324,9 @@ rpc_plugin_parse_exec(const char *name, int fd)
        if (!obj_type)
                return NULL;
 
-       asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name);
+       if (asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name) < 0)
+               return NULL;
+
        obj_type->methods = methods;
        obj_type->n_methods = n_method;
 
index b45d9feef6e9a1e733bcf05ec3675a245352c0da..951201bf00f592cb43b30298cb7507278438e307 100644 (file)
--- a/session.c
+++ b/session.c
@@ -146,22 +146,28 @@ static const struct blobmsg_policy login_policy[__RPC_L_MAX] = {
                    !fnmatch((_acl)->object, (_obj), FNM_NOESCAPE) &&           \
                    !fnmatch((_acl)->function, (_func), FNM_NOESCAPE))
 
-static void
+static int
 rpc_random(char *dest)
 {
        unsigned char buf[16] = { 0 };
        FILE *f;
        int i;
+       int ret;
 
        f = fopen("/dev/urandom", "r");
        if (!f)
-               return;
+               return -1;
 
-       fread(buf, 1, sizeof(buf), f);
+       ret = fread(buf, 1, sizeof(buf), f);
        fclose(f);
 
+       if (ret < 0)
+               return ret;
+
        for (i = 0; i < sizeof(buf); i++)
                sprintf(dest + (i<<1), "%02x", buf[i]);
+
+       return 0;
 }
 
 static void
@@ -316,7 +322,8 @@ rpc_session_create(int timeout)
        if (!ses)
                return NULL;
 
-       rpc_random(ses->id);
+       if (rpc_random(ses->id))
+               return NULL;
 
        ses->timeout = timeout;