Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-01-31 05:51:06 +0300
committerFelix Fietkau <nbd@openwrt.org>2011-01-31 05:51:06 +0300
commit7a0571a9ff9a9adfe7563db3067f7faf81c815a9 (patch)
treef1e30ad65faac262200df71aa28f4b8d1f1e1126 /blobmsg.c
parentcad5bea36d0271f291a88adbf58ef2ad50c6160a (diff)
blobmsg: constify and add more validation
Diffstat (limited to 'blobmsg.c')
-rw-r--r--blobmsg.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/blobmsg.c b/blobmsg.c
index 742a93b..3e9c774 100644
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -21,7 +21,7 @@ struct strbuf {
char *buf;
};
-static bool blobmsg_puts(struct strbuf *s, char *c, int len)
+static bool blobmsg_puts(struct strbuf *s, const char *c, int len)
{
if (len <= 0)
return true;
@@ -37,9 +37,9 @@ static bool blobmsg_puts(struct strbuf *s, char *c, int len)
return true;
}
-static void blobmsg_format_string(struct strbuf *s, char *str)
+static void blobmsg_format_string(struct strbuf *s, const char *str)
{
- char *p, *last = str, *end = str + strlen(str);
+ const char *p, *last = str, *end = str + strlen(str);
char buf[8] = "\\u00";
blobmsg_puts(s, "\"", 1);
@@ -175,9 +175,19 @@ char *blobmsg_format_json(struct blob_attr *attr, bool list)
return s.buf;
}
+static const int blob_type[__BLOBMSG_TYPE_LAST] = {
+ [BLOBMSG_TYPE_INT8] = BLOB_ATTR_INT8,
+ [BLOBMSG_TYPE_INT16] = BLOB_ATTR_INT16,
+ [BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32,
+ [BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64,
+ [BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING,
+};
+
bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
{
const struct blobmsg_hdr *hdr;
+ const char *data;
+ int id, len;
if (blob_len(attr) < sizeof(struct blobmsg_hdr))
return false;
@@ -192,7 +202,17 @@ bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
if (hdr->name[hdr->namelen] != 0)
return false;
- return true;
+ id = blob_id(attr);
+ len = blobmsg_data_len(attr);
+ data = blobmsg_data(attr);
+
+ if (!id || id > BLOBMSG_TYPE_LAST)
+ return false;
+
+ if (!blob_type[id])
+ return true;
+
+ return blob_check_type(data, len, blob_type[id]);
}
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,