@@ -159,25 +159,39 @@ lyb_parse_union(const void *lyb_data, size_t lyb_data_len, uint32_t *type_idx, c
159159 * @param[in] type leafref type used to extract target path
160160 * @param[in] value value attempting to be stored
161161 * @param[in] value_len Length of value that was attempted to be stored.
162+ * @return LY_ERR value. Only possible errors are LY_SUCCESS and LY_EMEM.
162163 */
163- static void
164+ static LY_ERR
164165union_update_lref_err (struct ly_err_item * err , const struct lysc_type * type , const void * value , size_t value_len )
165166{
166167 const struct lysc_type_leafref * lref ;
167168 char * valstr = NULL ;
169+ int msg_len ;
168170
169171 if ((err == NULL ) || (type -> basetype != LY_TYPE_LEAFREF )) {
170- return ;
172+ return LY_SUCCESS ;
171173 }
172174
173175 lref = (const struct lysc_type_leafref * )type ;
174176 free (err -> apptag );
175177 err -> apptag = strdup ("instance-required" );
178+ if (err -> apptag == NULL ) {
179+ return LY_EMEM ;
180+ }
176181
177182 free (err -> msg );
183+ err -> msg = NULL ;
178184 valstr = strndup ((const char * )value , value_len );
179- asprintf (& err -> msg , LY_ERRMSG_NOLREF_VAL , valstr , lyxp_get_expr (lref -> path ));
185+ if (valstr == NULL ) {
186+ return LY_EMEM ;
187+ }
188+
189+ msg_len = asprintf (& err -> msg , LY_ERRMSG_NOLREF_VAL , valstr , lyxp_get_expr (lref -> path ));
180190 free (valstr );
191+ if (msg_len == -1 ) {
192+ return LY_EMEM ;
193+ }
194+ return LY_SUCCESS ;
181195}
182196
183197/**
@@ -200,7 +214,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
200214 uint32_t options , ly_bool validate , const struct lyd_node * ctx_node , const struct lyd_node * tree ,
201215 struct lys_glob_unres * unres , struct ly_err_item * * err )
202216{
203- LY_ERR rc = LY_SUCCESS ;
217+ LY_ERR urc , rc = LY_SUCCESS ;
204218 struct lysc_type * type = type_u -> types [type_idx ];
205219 const void * value = NULL ;
206220 size_t value_len = 0 ;
@@ -222,7 +236,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
222236 memset (& subvalue -> value , 0 , sizeof subvalue -> value );
223237
224238 /* if this is a leafref, lets make sure we propagate the appropriate error, and not a type validation failure */
225- union_update_lref_err (* err , type_u -> types [ti ], value , value_len );
239+ urc = union_update_lref_err (* err , type_u -> types [ti ], value , value_len );
240+ if (urc != LY_SUCCESS ) {
241+ rc = urc ;
242+ }
226243 goto cleanup ;
227244 }
228245
@@ -260,7 +277,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
260277 memset (& subvalue -> value , 0 , sizeof subvalue -> value );
261278
262279 /* if this is a leafref, lets make sure we propagate the appropriate error, and not a type validation failure */
263- union_update_lref_err (* err , type , value , value_len );
280+ urc = union_update_lref_err (* err , type , value , value_len );
281+ if (urc != LY_SUCCESS ) {
282+ rc = urc ;
283+ }
264284 goto cleanup ;
265285 }
266286
0 commit comments