Skip to content

Commit c081b5f

Browse files
affan-archmichalvasko
authored andcommitted
plugins types BUGFIX leaked value on pattern mismatch
1 parent 2664f2f commit c081b5f

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎src/plugins_types/date.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ lyplg_type_store_date(const struct ly_ctx *ctx, const struct lysc_type *type, co
127127
if (!(options & LYPLG_TYPE_STORE_ONLY)) {
128128
/* validate value */
129129
ret = lyplg_type_validate_patterns(ctx, ((struct lysc_type_str *)type)->patterns, value, value_size, err);
130-
LY_CHECK_RET(ret);
130+
LY_CHECK_GOTO(ret, cleanup);
131131
}
132132

133133
if (val) {

‎src/plugins_types/date_and_time.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type
109109
if (!(options & LYPLG_TYPE_STORE_ONLY)) {
110110
/* validate value */
111111
ret = lyplg_type_validate_patterns(ctx, ((struct lysc_type_str *)type)->patterns, value, value_size, err);
112-
LY_CHECK_RET(ret);
112+
LY_CHECK_GOTO(ret, cleanup);
113113
}
114114

115115
/* convert to UNIX time and fractions of second */

‎src/plugins_types/time.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ lyplg_type_store_time(const struct ly_ctx *ctx, const struct lysc_type *type, co
133133
if (!(options & LYPLG_TYPE_STORE_ONLY)) {
134134
/* validate value */
135135
ret = lyplg_type_validate_patterns(ctx, ((struct lysc_type_str *)type)->patterns, value, value_size, err);
136-
LY_CHECK_RET(ret);
136+
LY_CHECK_GOTO(ret, cleanup);
137137
}
138138

139139
if (val) {

‎tests/utests/types/yang_types.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,22 @@ test_data_xml(void **state)
134134
"(\\.[0-9]+)?(Z|[\\+\\-]((1[0-3]|0[0-9]):([0-5][0-9])|14:00))?\".",
135135
"/a:l", 1);
136136

137+
/* invalid value in a dynamic buffer (entity reference) */
138+
TEST_ERROR_XML("a", "l", "2005-05-31T23:15:15&", LY_EVALID);
139+
CHECK_LOG_CTX("Unsatisfied pattern - \"2005-05-31T23:15:15&\" does not match "
140+
"\"[0-9]{4}-(1[0-2]|0[1-9])-(0[1-9]|[1-2][0-9]|3[0-1])T(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)"
141+
"(\\.[0-9]+)?(Z|[\\+\\-]((1[0-3]|0[0-9]):([0-5][0-9])|14:00))?\".",
142+
"/a:l", 1);
143+
137144
/* date */
138145
TEST_SUCCESS_XML("a", "l2", "2005-05-31-01:00", STRING, "2005-05-30-02:00");
139146
#ifndef _WIN32
140147
TEST_SUCCESS_XML("a", "l2", "1950-01-01-02:00", STRING, "1950-01-01-02:00");
141148
#endif
149+
TEST_ERROR_XML("a", "l2", "2005-05-31&", LY_EVALID);
150+
CHECK_LOG_CTX("Unsatisfied pattern - \"2005-05-31&\" does not match "
151+
"\"[0-9]{4}-(1[0-2]|0[1-9])-(0[1-9]|[1-2][0-9]|3[0-1])(Z|[\\+\\-]((1[0-3]|0[0-9]):([0-5][0-9])|14:00))?\".",
152+
"/a:l2", 1);
142153

143154
/* date-no-zone */
144155
TEST_SUCCESS_XML("a", "l2nz", "2005-05-31", STRING, "2005-05-31");
@@ -149,6 +160,10 @@ test_data_xml(void **state)
149160
/* time */
150161
TEST_SUCCESS_XML("a", "l4", "23:15:15-01:00", STRING, "22:15:15-02:00");
151162
TEST_SUCCESS_XML("a", "l4", "00:59:59.001-02:00", STRING, "00:59:59.001-02:00");
163+
TEST_ERROR_XML("a", "l4", "23:15:15&", LY_EVALID);
164+
CHECK_LOG_CTX("Unsatisfied pattern - \"23:15:15&\" does not match "
165+
"\"(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]+)?(Z|[\\+\\-]((1[0-3]|0[0-9]):([0-5][0-9])|14:00))?\".",
166+
"/a:l4", 1);
152167

153168
/* time-no-zone */
154169
TEST_SUCCESS_XML("a", "l4nz", "23:15:15", STRING, "23:15:15");

0 commit comments

Comments
 (0)