plugins exts BUGFIX avoid var overflow
diff --git a/src/plugins_exts.c b/src/plugins_exts.c
index a82e009..9fde053 100644
--- a/src/plugins_exts.c
+++ b/src/plugins_exts.c
@@ -600,38 +600,65 @@
return LY_ENOT;
}
+static LY_ERR
+lyplg_ext_set_storage(const struct ly_ctx *ctx, const void **s, uint32_t storage_size, const void **storage)
+{
+ if (s) {
+ /* matters for little-endian */
+ switch (storage_size) {
+ case 1:
+ *(uint8_t *)storage = (uintptr_t)*s;
+ break;
+ case 2:
+ *(uint16_t *)storage = (uintptr_t)*s;
+ break;
+ case 4:
+ *(uint32_t *)storage = (uintptr_t)*s;
+ break;
+ case 8:
+ *(uint64_t *)storage = (uintptr_t)*s;
+ break;
+ default:
+ LOGERR(ctx, LY_EINVAL, "Invalid storage size %" PRIu32 ".", storage_size);
+ return LY_EINVAL;
+ }
+
+ return LY_SUCCESS;
+ } else {
+ /* zero */
+ switch (storage_size) {
+ case 1:
+ *(uint8_t *)storage = (uintptr_t)s;
+ break;
+ case 2:
+ *(uint16_t *)storage = (uintptr_t)s;
+ break;
+ case 4:
+ *(uint32_t *)storage = (uintptr_t)s;
+ break;
+ case 8:
+ *(uint64_t *)storage = (uintptr_t)s;
+ break;
+ default:
+ LOGERR(ctx, LY_EINVAL, "Invalid storage size %" PRIu32 ".", storage_size);
+ return LY_EINVAL;
+ }
+ return LY_ENOT;
+ }
+}
+
LIBYANG_API_DEF LY_ERR
lyplg_ext_get_storage(const struct lysc_ext_instance *ext, int stmt, uint32_t storage_size, const void **storage)
{
- LY_ERR r;
+ LY_ERR rc1, rc2;
const void **s;
- *storage = NULL;
+ /* get pointer to the storage, is set even on error */
+ rc1 = lyplg_ext_get_storage_p(ext, stmt, &s);
- if ((r = lyplg_ext_get_storage_p(ext, stmt, &s))) {
- return r;
- }
-
- /* matters for little-endian */
- switch (storage_size) {
- case 1:
- *(uint8_t *)storage = (uintptr_t)*s;
- break;
- case 2:
- *(uint16_t *)storage = (uintptr_t)*s;
- break;
- case 4:
- *(uint32_t *)storage = (uintptr_t)*s;
- break;
- case 8:
- *(uint64_t *)storage = (uintptr_t)*s;
- break;
- default:
- LOGERR(ext->module->ctx, LY_EINVAL, "Invalid storage size %" PRIu32 ".", storage_size);
- return LY_EINVAL;
- }
-
- return LY_SUCCESS;
+ /* assign */
+ rc2 = lyplg_ext_set_storage(ext->module->ctx, s, storage_size, storage);
+ return rc1 ? rc1 : rc2;
}
LIBYANG_API_DEF LY_ERR
@@ -642,8 +669,6 @@
enum ly_stmt match = 0;
const void **s = NULL;
- *storage = NULL;
-
/* find the parsed ext instance */
LY_ARRAY_FOR(ext->module->parsed->exts, u) {
extp = &ext->module->parsed->exts[u];
@@ -668,29 +693,8 @@
}
}
- if (s) {
- /* matters for little-endian */
- switch (storage_size) {
- case 1:
- *(uint8_t *)storage = (uintptr_t)*s;
- break;
- case 2:
- *(uint16_t *)storage = (uintptr_t)*s;
- break;
- case 4:
- *(uint32_t *)storage = (uintptr_t)*s;
- break;
- case 8:
- *(uint64_t *)storage = (uintptr_t)*s;
- break;
- default:
- LOGERR(ext->module->ctx, LY_EINVAL, "Invalid storage size %" PRIu32 ".", storage_size);
- return LY_EINVAL;
- }
-
- return LY_SUCCESS;
- }
- return LY_ENOT;
+ /* assign */
+ return lyplg_ext_set_storage(ext->module->ctx, s, storage_size, storage);
}
LIBYANG_API_DEF LY_ERR