Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/plugins_types/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ lyplg_type_store_date(const struct ly_ctx *ctx, const struct lysc_type *type, co
}

if (val) {
if (value_size < 10) {
/* not even a full date, the pattern was not checked with LYPLG_TYPE_STORE_ONLY */
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to parse %s value \"%.*s\".", type->name,
(int)value_size, (char *)value);
goto cleanup;
}

/* create date-and-time value */
if (asprintf(&str, "%.*sT00:00:00%.*s", 10, (char *)value, (int)(value_size - 10), (char *)value + 10) == -1) {
ret = ly_err_new_no_mem(err);
Expand Down
13 changes: 12 additions & 1 deletion tests/utests/types/yang_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
static void
test_data_xml(void **state)
{
const char *schema;
const char *schema, *data;
struct lyd_node *tree;

/* xml test */
schema = MODULE_CREATE_YANG("a",
Expand Down Expand Up @@ -151,6 +152,16 @@ test_data_xml(void **state)
"\"[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))?\".",
"/a:l2", 1);

/* date stored only, shorter than a date */
data = "<l2 xmlns=\"urn:tests:a\">2</l2><l2nz xmlns=\"urn:tests:a\">2005-05-31</l2nz>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STORE_ONLY, 0, LY_EVALID, tree);
assert_null(tree);
CHECK_LOG_CTX("Failed to parse date value \"2\".", "/a:l2", 1);
data = "<l2 xmlns=\"urn:tests:a\">&#50;</l2>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STORE_ONLY, 0, LY_EVALID, tree);
assert_null(tree);
CHECK_LOG_CTX("Failed to parse date value \"2\".", "/a:l2", 1);

/* date-no-zone */
TEST_SUCCESS_XML("a", "l2nz", "2005-05-31", STRING, "2005-05-31");
#ifndef _WIN32
Expand Down
Loading