properly handle return codes
Signed-off-by: John Crispin <blogic@openwrt.org>
This commit is contained in:
parent
361b823e8d
commit
311c85e7d9
3 changed files with 15 additions and 6 deletions
2
file.c
2
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])
|
if (!tb[RPC_F_RW_PATH] || !tb[RPC_F_RW_DATA])
|
||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
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();
|
return rpc_errno_status();
|
||||||
|
|
||||||
if (write(fd, blobmsg_data(tb[RPC_F_RW_DATA]), blobmsg_data_len(tb[RPC_F_RW_DATA])) < 0)
|
if (write(fd, blobmsg_data(tb[RPC_F_RW_DATA]), blobmsg_data_len(tb[RPC_F_RW_DATA])) < 0)
|
||||||
|
|
4
plugin.c
4
plugin.c
|
@ -324,7 +324,9 @@ rpc_plugin_parse_exec(const char *name, int fd)
|
||||||
if (!obj_type)
|
if (!obj_type)
|
||||||
return NULL;
|
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->methods = methods;
|
||||||
obj_type->n_methods = n_method;
|
obj_type->n_methods = n_method;
|
||||||
|
|
||||||
|
|
15
session.c
15
session.c
|
@ -146,22 +146,28 @@ static const struct blobmsg_policy login_policy[__RPC_L_MAX] = {
|
||||||
!fnmatch((_acl)->object, (_obj), FNM_NOESCAPE) && \
|
!fnmatch((_acl)->object, (_obj), FNM_NOESCAPE) && \
|
||||||
!fnmatch((_acl)->function, (_func), FNM_NOESCAPE))
|
!fnmatch((_acl)->function, (_func), FNM_NOESCAPE))
|
||||||
|
|
||||||
static void
|
static int
|
||||||
rpc_random(char *dest)
|
rpc_random(char *dest)
|
||||||
{
|
{
|
||||||
unsigned char buf[16] = { 0 };
|
unsigned char buf[16] = { 0 };
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int i;
|
int i;
|
||||||
|
int ret;
|
||||||
|
|
||||||
f = fopen("/dev/urandom", "r");
|
f = fopen("/dev/urandom", "r");
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
fread(buf, 1, sizeof(buf), f);
|
ret = fread(buf, 1, sizeof(buf), f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(buf); i++)
|
for (i = 0; i < sizeof(buf); i++)
|
||||||
sprintf(dest + (i<<1), "%02x", buf[i]);
|
sprintf(dest + (i<<1), "%02x", buf[i]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -316,7 +322,8 @@ rpc_session_create(int timeout)
|
||||||
if (!ses)
|
if (!ses)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
rpc_random(ses->id);
|
if (rpc_random(ses->id))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
ses->timeout = timeout;
|
ses->timeout = timeout;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue