Skip to content
Permalink
Browse files Browse the repository at this point in the history
yang parser BUGFIX double free
Fixes #742
  • Loading branch information
michalvasko committed Mar 29, 2019
1 parent a1f1769 commit d9feacc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
12 changes: 7 additions & 5 deletions src/parser_yang.c
Expand Up @@ -4763,7 +4763,7 @@ yang_check_sub_module(struct lys_module *module, struct unres_schema *unres, str

int
yang_read_extcomplex_str(struct lys_module *module, struct lys_ext_instance_complex *ext, const char *arg_name,
const char *parent_name, char *value, int parent_stmt, LY_STMT stmt)
const char *parent_name, char **value, int parent_stmt, LY_STMT stmt)
{
int c;
const char **str, ***p = NULL;
Expand All @@ -4782,7 +4782,8 @@ yang_read_extcomplex_str(struct lys_module *module, struct lys_ext_instance_comp
for (c = 0; p[0][c + 1]; c++);
str = p[1];
}
str[c] = lydict_insert_zc(module->ctx, value);
str[c] = lydict_insert_zc(module->ctx, *value);
*value = NULL;
} else {
str = lys_ext_complex_get_substmt(stmt, ext, &info);
if (!str) {
Expand Down Expand Up @@ -4819,8 +4820,8 @@ yang_read_extcomplex_str(struct lys_module *module, struct lys_ext_instance_comp
str = p[0];
}

str[c] = lydict_insert_zc(module->ctx, value);
value = NULL;
str[c] = lydict_insert_zc(module->ctx, *value);
*value = NULL;

if (c) {
/* enlarge the array(s) */
Expand Down Expand Up @@ -4862,7 +4863,8 @@ yang_read_extcomplex_str(struct lys_module *module, struct lys_ext_instance_comp
return EXIT_SUCCESS;

error:
free(value);
free(*value);
*value = NULL;
return EXIT_FAILURE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser_yang.h
Expand Up @@ -174,7 +174,7 @@ int yang_check_ext_instance(struct lys_module *module, struct lys_ext_instance *
void *parent, struct unres_schema *unres);

int yang_read_extcomplex_str(struct lys_module *module, struct lys_ext_instance_complex *ext, const char *arg_name,
const char *parent_name, char *value, int parent_stmt, LY_STMT stmt);
const char *parent_name, char **value, int parent_stmt, LY_STMT stmt);

void **yang_getplace_for_extcomplex_struct(struct lys_ext_instance_complex *ext, int *index,
char *parent_name, char *node_name, LY_STMT stmt);
Expand Down
36 changes: 18 additions & 18 deletions src/parser_yang_bis.c
Expand Up @@ -3435,7 +3435,7 @@ YYLTYPE yylloc = yyloc_default;

{ (yyval.token) = actual_type;
if (is_ext_instance) {
if (yang_read_extcomplex_str(trg, ext_instance, "belongs-to", ext_name, s,
if (yang_read_extcomplex_str(trg, ext_instance, "belongs-to", ext_name, &s,
0, LY_STMT_BELONGSTO)) {
YYABORT;
}
Expand All @@ -3461,7 +3461,7 @@ YYLTYPE yylloc = yyloc_default;
case 48:

{ if (is_ext_instance) {
if (yang_read_extcomplex_str(trg, ext_instance, "prefix", "belongs-to", s,
if (yang_read_extcomplex_str(trg, ext_instance, "prefix", "belongs-to", &s,
LY_STMT_BELONGSTO, LY_STMT_PREFIX)) {
YYABORT;
}
Expand Down Expand Up @@ -3802,7 +3802,7 @@ YYLTYPE yylloc = yyloc_default;

{ (yyval.token) = actual_type;
if (is_ext_instance) {
if (yang_read_extcomplex_str(trg, ext_instance, "argument", ext_name, s,
if (yang_read_extcomplex_str(trg, ext_instance, "argument", ext_name, &s,
0, LY_STMT_ARGUMENT)) {
YYABORT;
}
Expand Down Expand Up @@ -8442,7 +8442,7 @@ YYLTYPE yylloc = yyloc_default;

case 792:

{ if (yang_read_extcomplex_str(trg, ext_instance, "prefix", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "prefix", ext_name, &s,
0, LY_STMT_PREFIX)) {
YYABORT;
}
Expand All @@ -8452,7 +8452,7 @@ YYLTYPE yylloc = yyloc_default;

case 793:

{ if (yang_read_extcomplex_str(trg, ext_instance, "description", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "description", ext_name, &s,
0, LY_STMT_DESCRIPTION)) {
YYABORT;
}
Expand All @@ -8462,7 +8462,7 @@ YYLTYPE yylloc = yyloc_default;

case 794:

{ if (yang_read_extcomplex_str(trg, ext_instance, "reference", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "reference", ext_name, &s,
0, LY_STMT_REFERENCE)) {
YYABORT;
}
Expand All @@ -8472,7 +8472,7 @@ YYLTYPE yylloc = yyloc_default;

case 795:

{ if (yang_read_extcomplex_str(trg, ext_instance, "units", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "units", ext_name, &s,
0, LY_STMT_UNITS)) {
YYABORT;
}
Expand All @@ -8482,7 +8482,7 @@ YYLTYPE yylloc = yyloc_default;

case 796:

{ if (yang_read_extcomplex_str(trg, ext_instance, "base", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "base", ext_name, &s,
0, LY_STMT_BASE)) {
YYABORT;
}
Expand All @@ -8492,7 +8492,7 @@ YYLTYPE yylloc = yyloc_default;

case 797:

{ if (yang_read_extcomplex_str(trg, ext_instance, "contact", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "contact", ext_name, &s,
0, LY_STMT_CONTACT)) {
YYABORT;
}
Expand All @@ -8502,7 +8502,7 @@ YYLTYPE yylloc = yyloc_default;

case 798:

{ if (yang_read_extcomplex_str(trg, ext_instance, "default", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "default", ext_name, &s,
0, LY_STMT_DEFAULT)) {
YYABORT;
}
Expand All @@ -8512,7 +8512,7 @@ YYLTYPE yylloc = yyloc_default;

case 799:

{ if (yang_read_extcomplex_str(trg, ext_instance, "error-message", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "error-message", ext_name, &s,
0, LY_STMT_ERRMSG)) {
YYABORT;
}
Expand All @@ -8522,7 +8522,7 @@ YYLTYPE yylloc = yyloc_default;

case 800:

{ if (yang_read_extcomplex_str(trg, ext_instance, "error-app-tag", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "error-app-tag", ext_name, &s,
0, LY_STMT_ERRTAG)) {
YYABORT;
}
Expand All @@ -8532,7 +8532,7 @@ YYLTYPE yylloc = yyloc_default;

case 801:

{ if (yang_read_extcomplex_str(trg, ext_instance, "key", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "key", ext_name, &s,
0, LY_STMT_KEY)) {
YYABORT;
}
Expand All @@ -8542,7 +8542,7 @@ YYLTYPE yylloc = yyloc_default;

case 802:

{ if (yang_read_extcomplex_str(trg, ext_instance, "namespace", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "namespace", ext_name, &s,
0, LY_STMT_NAMESPACE)) {
YYABORT;
}
Expand All @@ -8552,7 +8552,7 @@ YYLTYPE yylloc = yyloc_default;

case 803:

{ if (yang_read_extcomplex_str(trg, ext_instance, "organization", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "organization", ext_name, &s,
0, LY_STMT_ORGANIZATION)) {
YYABORT;
}
Expand All @@ -8562,7 +8562,7 @@ YYLTYPE yylloc = yyloc_default;

case 804:

{ if (yang_read_extcomplex_str(trg, ext_instance, "path", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "path", ext_name, &s,
0, LY_STMT_PATH)) {
YYABORT;
}
Expand All @@ -8572,7 +8572,7 @@ YYLTYPE yylloc = yyloc_default;

case 805:

{ if (yang_read_extcomplex_str(trg, ext_instance, "presence", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "presence", ext_name, &s,
0, LY_STMT_PRESENCE)) {
YYABORT;
}
Expand All @@ -8582,7 +8582,7 @@ YYLTYPE yylloc = yyloc_default;

case 806:

{ if (yang_read_extcomplex_str(trg, ext_instance, "revision-date", ext_name, s,
{ if (yang_read_extcomplex_str(trg, ext_instance, "revision-date", ext_name, &s,
0, LY_STMT_REVISIONDATE)) {
YYABORT;
}
Expand Down
36 changes: 18 additions & 18 deletions src/yang.y.in
Expand Up @@ -613,7 +613,7 @@ revision_date_stmt: REVISION_DATE_KEYWORD sep revision_date_arg stmtend

belongs_to_arg_str: identifier_arg_str { $$ = actual_type;
if (is_ext_instance) {
if (yang_read_extcomplex_str(trg, ext_instance, "belongs-to", ext_name, s,
if (yang_read_extcomplex_str(trg, ext_instance, "belongs-to", ext_name, &s,
0, LY_STMT_BELONGSTO)) {
YYABORT;
}
Expand All @@ -638,7 +638,7 @@ belongs_to_stmt: BELONGS_TO_KEYWORD sep belongs_to_arg_str
'{' stmtsep
prefix_stmt
'}' { if (is_ext_instance) {
if (yang_read_extcomplex_str(trg, ext_instance, "prefix", "belongs-to", s,
if (yang_read_extcomplex_str(trg, ext_instance, "prefix", "belongs-to", &s,
LY_STMT_BELONGSTO, LY_STMT_PREFIX)) {
YYABORT;
}
Expand Down Expand Up @@ -909,7 +909,7 @@ extension_opt_stmt: @EMPTYDIR@

argument_str: identifier_arg_str { $$ = actual_type;
if (is_ext_instance) {
if (yang_read_extcomplex_str(trg, ext_instance, "argument", ext_name, s,
if (yang_read_extcomplex_str(trg, ext_instance, "argument", ext_name, &s,
0, LY_STMT_ARGUMENT)) {
YYABORT;
}
Expand Down Expand Up @@ -4545,77 +4545,77 @@ ext_substatements: @EMPTYDIR@ { actual_type = EXTENSION_INSTANCE;
$$ = 0;
}
| ext_substatements belongs_to_stmt stmtsep
| ext_substatements prefix_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "prefix", ext_name, s,
| ext_substatements prefix_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "prefix", ext_name, &s,
0, LY_STMT_PREFIX)) {
YYABORT;
}
}
| ext_substatements description_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "description", ext_name, s,
| ext_substatements description_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "description", ext_name, &s,
0, LY_STMT_DESCRIPTION)) {
YYABORT;
}
}
| ext_substatements reference_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "reference", ext_name, s,
| ext_substatements reference_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "reference", ext_name, &s,
0, LY_STMT_REFERENCE)) {
YYABORT;
}
}
| ext_substatements units_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "units", ext_name, s,
| ext_substatements units_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "units", ext_name, &s,
0, LY_STMT_UNITS)) {
YYABORT;
}
}
| ext_substatements base_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "base", ext_name, s,
| ext_substatements base_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "base", ext_name, &s,
0, LY_STMT_BASE)) {
YYABORT;
}
}
| ext_substatements contact_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "contact", ext_name, s,
| ext_substatements contact_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "contact", ext_name, &s,
0, LY_STMT_CONTACT)) {
YYABORT;
}
}
| ext_substatements default_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "default", ext_name, s,
| ext_substatements default_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "default", ext_name, &s,
0, LY_STMT_DEFAULT)) {
YYABORT;
}
}
| ext_substatements error_message_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "error-message", ext_name, s,
| ext_substatements error_message_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "error-message", ext_name, &s,
0, LY_STMT_ERRMSG)) {
YYABORT;
}
}
| ext_substatements error_app_tag_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "error-app-tag", ext_name, s,
| ext_substatements error_app_tag_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "error-app-tag", ext_name, &s,
0, LY_STMT_ERRTAG)) {
YYABORT;
}
}
| ext_substatements key_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "key", ext_name, s,
| ext_substatements key_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "key", ext_name, &s,
0, LY_STMT_KEY)) {
YYABORT;
}
}
| ext_substatements namespace_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "namespace", ext_name, s,
| ext_substatements namespace_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "namespace", ext_name, &s,
0, LY_STMT_NAMESPACE)) {
YYABORT;
}
}
| ext_substatements organization_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "organization", ext_name, s,
| ext_substatements organization_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "organization", ext_name, &s,
0, LY_STMT_ORGANIZATION)) {
YYABORT;
}
}
| ext_substatements path_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "path", ext_name, s,
| ext_substatements path_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "path", ext_name, &s,
0, LY_STMT_PATH)) {
YYABORT;
}
}
| ext_substatements presence_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "presence", ext_name, s,
| ext_substatements presence_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "presence", ext_name, &s,
0, LY_STMT_PRESENCE)) {
YYABORT;
}
}
| ext_substatements revision_date_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "revision-date", ext_name, s,
| ext_substatements revision_date_stmt { if (yang_read_extcomplex_str(trg, ext_instance, "revision-date", ext_name, &s,
0, LY_STMT_REVISIONDATE)) {
YYABORT;
}
Expand Down

0 comments on commit d9feacc

Please sign in to comment.