Skip to content

Commit 867b7fb

Browse files
committed
ip prefix BUGFIX validate type patterns
Fixes #2470
1 parent 21cf47d commit 867b7fb

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/plugins_types/ipv4_address_prefix.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ lyplg_type_store_ipv4_address_prefix(const struct ly_ctx *ctx, const struct lysc
128128
struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
129129
{
130130
LY_ERR ret = LY_SUCCESS;
131+
const struct lysc_type_str *type_str = (struct lysc_type_str *)type;
131132
struct lyd_value_ipv4_prefix *val;
132133
uint32_t value_size;
133134

@@ -166,6 +167,18 @@ lyplg_type_store_ipv4_address_prefix(const struct ly_ctx *ctx, const struct lysc
166167
ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
167168
LY_CHECK_GOTO(ret, cleanup);
168169

170+
if (!(options & LYPLG_TYPE_STORE_ONLY)) {
171+
/* length restriction of the string */
172+
if (type_str->length) {
173+
ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, value_size, value, value_size, err);
174+
LY_CHECK_GOTO(ret, cleanup);
175+
}
176+
177+
/* validate patterns */
178+
ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
179+
LY_CHECK_GOTO(ret, cleanup);
180+
}
181+
169182
/* get the mask in network-byte order */
170183
ret = ipv4prefix_str2ip(value, value_size, &val->addr, &val->prefix, err);
171184
LY_CHECK_GOTO(ret, cleanup);

src/plugins_types/ipv6_address_prefix.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ lyplg_type_store_ipv6_address_prefix(const struct ly_ctx *ctx, const struct lysc
130130
struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
131131
{
132132
LY_ERR ret = LY_SUCCESS;
133+
const struct lysc_type_str *type_str = (struct lysc_type_str *)type;
133134
struct lyd_value_ipv6_prefix *val;
134135
uint32_t value_size;
135136

@@ -180,6 +181,18 @@ lyplg_type_store_ipv6_address_prefix(const struct ly_ctx *ctx, const struct lysc
180181
ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
181182
LY_CHECK_GOTO(ret, cleanup);
182183

184+
if (!(options & LYPLG_TYPE_STORE_ONLY)) {
185+
/* length restriction of the string */
186+
if (type_str->length) {
187+
ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, value_size, value, value_size, err);
188+
LY_CHECK_GOTO(ret, cleanup);
189+
}
190+
191+
/* validate patterns */
192+
ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
193+
LY_CHECK_GOTO(ret, cleanup);
194+
}
195+
183196
/* get the mask in network-byte order */
184197
ret = ipv6prefix_str2ip(value, value_size, &val->addr, &val->prefix, err);
185198
LY_CHECK_GOTO(ret, cleanup);

0 commit comments

Comments
 (0)