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
AgeCommit message (Collapse)Author
2023-01-03blobmsg: add blobmsg_parse_array_attrFelix Fietkau
Wrapper around blobmsg_parse_array, similar to blobmsg_parse_attr Signed-off-by: Felix Fietkau <nbd@nbd.name>
2022-11-23blobmsg: add blobmsg_parse_attr functionFelix Fietkau
This allows turning the common pattern of: blobmsg_parse(policy, ARRAY_SIZE(policy), tb, blobmsg_data(data), blobmsg_len(data)); into: blobmsg_parse_attr(policy, ARRAY_SIZE(policy), tb, data); Signed-off-by: Felix Fietkau <nbd@nbd.name>
2022-05-15blobmsg: work around false positive gcc -Warray-bounds warningsFelix Fietkau
Using the return value of blobmsg_name as input argument to strcpy can lead to warnings like these: error: 'strcpy' offset 6 from the object at 'cur' is out of the bounds of referenced subobject 'name' with type 'uint8_t[]' {aka 'unsigned char[]'} at offset 6 [-Werror=array-bounds] Fix this by replacing hdr->name with the equivalent hdr + 1 Signed-off-by: Felix Fietkau <nbd@nbd.name>
2021-03-02libubox: fix BLOBMSG_CAST_INT64 (do not override BLOBMSG_TYPE_DOUBLE)Peter Seiderer
Commit 9e52171 ('blobmsg: introduce BLOBMSG_CAST_INT64') broke blobmsg_parse() for BLOBMSG_TYPE_DOUBLE. This is because the enum definition leads to the following double define for BLOBMSG_CAST_INT64/BLOBMSG_TYPE_DOUBLE as value 8. Tested with: $ cat test-enum-001.c #include <stdio.h> enum blobmsg_type { BLOBMSG_TYPE_UNSPEC, BLOBMSG_TYPE_ARRAY, BLOBMSG_TYPE_TABLE, BLOBMSG_TYPE_STRING, BLOBMSG_TYPE_INT64, BLOBMSG_TYPE_INT32, BLOBMSG_TYPE_INT16, BLOBMSG_TYPE_INT8, BLOBMSG_TYPE_DOUBLE, __BLOBMSG_TYPE_LAST, BLOBMSG_TYPE_LAST = __BLOBMSG_TYPE_LAST - 1, BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8, BLOBMSG_CAST_INT64, }; int main(int artc, char* argv[]) { printf("BLOBMSG_TYPE_UNSPEC: %d\n", BLOBMSG_TYPE_UNSPEC); printf("BLOBMSG_TYPE_ARRAY: %d\n", BLOBMSG_TYPE_ARRAY); printf("BLOBMSG_TYPE_TABLE: %d\n", BLOBMSG_TYPE_TABLE); printf("BLOBMSG_TYPE_STRING: %d\n", BLOBMSG_TYPE_STRING); printf("BLOBMSG_TYPE_INT64: %d\n", BLOBMSG_TYPE_INT64); printf("BLOBMSG_TYPE_INT32: %d\n", BLOBMSG_TYPE_INT32); printf("BLOBMSG_TYPE_INT16: %d\n", BLOBMSG_TYPE_INT16); printf("BLOBMSG_TYPE_INT8: %d\n", BLOBMSG_TYPE_INT8); printf("BLOBMSG_TYPE_DOUBLE: %d\n", BLOBMSG_TYPE_DOUBLE); printf("__BLOBMSG_TYPE_LAST: %d\n", __BLOBMSG_TYPE_LAST); printf("BLOBMSG_TYPE_LAST: %d\n", BLOBMSG_TYPE_LAST); printf("BLOBMSG_TYPE_BOOL: %d\n", BLOBMSG_TYPE_BOOL); printf("BLOBMSG_CAST_INT64: %d\n", BLOBMSG_CAST_INT64); return 0; } $ gcc test-enum-001.c $ ./a.out BLOBMSG_TYPE_UNSPEC: 0 BLOBMSG_TYPE_ARRAY: 1 BLOBMSG_TYPE_TABLE: 2 BLOBMSG_TYPE_STRING: 3 BLOBMSG_TYPE_INT64: 4 BLOBMSG_TYPE_INT32: 5 BLOBMSG_TYPE_INT16: 6 BLOBMSG_TYPE_INT8: 7 BLOBMSG_TYPE_DOUBLE: 8 __BLOBMSG_TYPE_LAST: 9 BLOBMSG_TYPE_LAST: 8 BLOBMSG_TYPE_BOOL: 7 BLOBMSG_CAST_INT64: 8 Fix this by changing the enum defintion to assign BLOBMSG_CAST_INT64 to the unique value 9. Signed-off-by: Peter Seiderer <ps.report@gmx.net>
2020-08-06blobmsg: introduce BLOBMSG_CAST_INT64Daniel Golle
When dealing with 64-bit integers in JSON documents, blobmsg_parse becomes useless as blobmsg-json only uses BLOBMSG_TYPE_INT64 if the value exceeds the range of a 32-bit integer, otherwise BLOBMSG_TYPE_INT32 is used. This is because blobmsg-json parses the JSON document ad-hoc without knowing the schema in advance and hence a result of the design of blobmsg-json (and the absence of JSON schema definitions). In practise, this made code less readable as instead of using blobmsg_parse() one had to to deal with *all* attributes manually just to catch fields which can be both, BLOBMSG_TYPE_INT32 or BLOBMSG_TYPE_INT64, but are always dealt with as uint64_t in code as they potentially could exceed the 32-bit range. To resolve this issue, introduce as special wildcard attribute type BLOBMSG_CAST_INT64 which should only be used in policies used by blobmsg_parse(). If used for an attribute in the policy, blobmsg_parse shall accept all integer types and allow the user to retrieve the value using the uint64_t blobmsg_cast_u64() and int64_t blobmsg_cast_s64() functions which is also introduced by this commit. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2020-05-26blobmsg: drop old comment about json formatting functionsRafał Miłecki
Those functions were moved out of blobmsg.h. Fixes: 0918243e90e6 ("move json formatting to the blobmsg_json library") Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2019-12-25blobmsg: reuse blobmsg_namelen in blobmsg_dataPetr Štetiar
Move blobmsg_namelen into header file so it's possible to reuse it in blobmsg_data. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-25blobmsg: add _len variants for all attribute checking methodsTobias Schramm
Introduce _len variants of blobmsg attribute checking functions which aims to provide safer implementation as those functions should limit all memory accesses performed on the blob to the range [attr, attr + len] (upper bound non inclusive) and thus should be suited for checking of untrusted blob attributes. While at it add some comments in order to make it clear. Signed-off-by: Tobias Schramm <tobleminer@gmail.com> [_safe -> _len, blobmsg_check_array_len fix, commit subject/desc facelift] Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-25Replace use of blobmsg_check_attr by blobmsg_check_attr_lenTobias Schramm
blobmsg_check_attr_len adds a length limit specifying the max offset from attr that can be read safely. Signed-off-by: Tobias Schramm <tobleminer@gmail.com> [rebased and reworked, line wrapped commit message, _safe -> _len] Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-25Ensure blob_attr length check does not perform out of bounds readsTobias Schramm
Before there might have been as little as one single byte left which would result in 3 bytes of blob_attr->id_len being out of bounds. Acked-by: Yousong Zhou <yszhou4tech@gmail.com> Signed-off-by: Tobias Schramm <tobleminer@gmail.com> [line wrapped < 72 chars] Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-25blobmsg: make blobmsg_len and blobmsg_data_len return unsigned valuePetr Štetiar
One usually doesn't guard against negative length values in the code. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2018-07-25fix segfault when passed blobmsg attr is NULLJohn Crispin
Signed-off-by: John Crispin <john@phrozen.org>
2017-01-04blobmsg: add support for doubleAndré Gaul
This adds support for double floating point type to make it more JSON compatible. For type checking it also adds a stub BLOB_ATTR_DOUBLE type. If necessary, the accessor functions for blob can be added later Signed-off-by: André Gaul <andre@gaul.io> Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-11-29blob/blobmsg: add explicit typecasts for attribute iteratorsFelix Fietkau
Fixes C++ compatibility. Reported in https://forum.lede-project.org/t/blobmsg-for-each-attr-from-c/389 Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-06-26Fix various memory management issuesMatthias Schiffer
Consistently handle allocation failures. Some functions are changed to return bool or int instead of void to allow returning an error. Also fix a buffer size miscalculation in lua/uloop and use _exit() instead of exit() on errors after forking. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
2014-08-03blobmsg: accept NULL attr in blobmsg_get_string()Felix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-21blobmsg: add a helper function to reset the name of a blobmsg attributeFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-15blobmsg: add blobmsg_check_array, which returns the size of the arrayFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-05-09blob/blobmsg: Perform explicit casts from void* to avoid compilation errors ↵Jacob Siverskog
when using libubox from C++. Signed-off by: Jacob Siverskog <jacob@teenageengineering.com>
2014-04-27blobmsg: make length variables unsignedFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-03-12blobmsg: allow data/length iterator/accessor functions to work on ↵Felix Fietkau
non-blobmsg elements This primarily helps with simplifying the ubus APIs. blobmsg header presence is indicated by the BLOB_ATTR_EXTENDED bit in the id_len field. This changes the format ABI, but not the API. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-20blobmsg: add blobmsg_len() for consistency (similar to blob_len)Felix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-07-29blob/blobmsg: add null pointer checks to the *_for_each_attr functions, fix ↵Felix Fietkau
formatting Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-02-17blobmsg: implement blobmsg_printf and blobmsg_vprintfFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-02-10blobmsg: add blobmsg_realloc_string_buffer()Felix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-23blob/blobmsg: use 32 bit load/store for 64 bit access, unaligned attributes ↵Felix Fietkau
cause data corruption on ARM Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-13blobmsg: add blobmsg_get_stringFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-08blobmsg: add blobmsg_parse_array()Felix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-06-24blobmsg: remove the unnecessary name argument from blobmsg_check_attr_list, ↵Felix Fietkau
infer it from the list type
2012-06-24blobmsg: add blobmsg_check_attr_list() to validate element types of arrays ↵Felix Fietkau
and tables
2012-05-26switch blobmsg over to permissive licenseFelix Fietkau
2012-05-08add blobmsg_add_blob() to copy over an existing blobmsg attributeFelix Fietkau
2011-11-17blobmsg: add missing endian conversionsFelix Fietkau
2011-10-27make casts from void * explicit to avoid C++ warnings (patch by Arthur Davis)Felix Fietkau
2011-10-06make the blobmsg format endian agnostic (stick to big-endian)Felix Fietkau
2011-10-03fix reads beyond the end of the buffer when iterating over blob attributesFelix Fietkau
2011-09-12add a blobmsg_type() inline functionFelix Fietkau
2011-09-07add blobmsg_get_boolFelix Fietkau
2011-07-29add BLOBMSG_TYPE_BOOL as an alias for BLOBMSG_TYPE_INT8Felix Fietkau
2011-02-06move json formatting to the blobmsg_json libraryFelix Fietkau
2011-02-06add a callback to the blobmsg-to-json function to override the formatting of ↵Felix Fietkau
specific attributes
2011-02-05blomsg: add integer attribute accessor functionsFelix Fietkau
2011-02-04add functions for allocating and adding a string buffer fieldFelix Fietkau
2011-01-31blobmsg: constify and add more validationFelix Fietkau
2011-01-30add support for json-formatting blobmsg elementsFelix Fietkau
2011-01-30fix json list parsingFelix Fietkau
2011-01-29add blobmsg_for_each_attrFelix Fietkau
2011-01-29blobmsg: make arrays structually the same as tables - simplifies library ↵Felix Fietkau
user code
2011-01-24add a blobmsg-to-json functionFelix Fietkau
2011-01-23add blobmsg_name()Felix Fietkau