aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2014-11-19 18:37:52 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2014-11-19 18:37:52 +0100
commitf77dcb217261148de1c57c8b042873efbad81d20 (patch)
treebadea2bbb59ff2d7566f9a05833edf737fdab4cf
parent2c210483fab6b163a120894f07e4f10622be1f40 (diff)
Input validation for setters
-rw-r--r--api_test/main.c9
-rw-r--r--src/node.c12
2 files changed, 21 insertions, 0 deletions
diff --git a/api_test/main.c b/api_test/main.c
index 82a0dfb..f74dee2 100644
--- a/api_test/main.c
+++ b/api_test/main.c
@@ -201,6 +201,15 @@ accessors(test_batch_runner *runner)
OK(runner, !cmark_node_set_title(header, "title"),
"set_title error");
+ OK(runner, !cmark_node_set_header_level(header, 0),
+ "set_header_level too small");
+ OK(runner, !cmark_node_set_header_level(header, 7),
+ "set_header_level too large");
+ OK(runner, !cmark_node_set_list_type(bullet_list, CMARK_NO_LIST),
+ "set_list_type invalid");
+ OK(runner, !cmark_node_set_list_start(bullet_list, -1),
+ "set_list_start negative");
+
cmark_node_destroy(doc);
}
diff --git a/src/node.c b/src/node.c
index 190deb9..624baad 100644
--- a/src/node.c
+++ b/src/node.c
@@ -153,6 +153,10 @@ cmark_node_get_header_level(cmark_node *node) {
int
cmark_node_set_header_level(cmark_node *node, int level) {
+ if (level < 1 || level > 6) {
+ return 0;
+ }
+
switch (node->type) {
case CMARK_NODE_ATX_HEADER:
case CMARK_NODE_SETEXT_HEADER:
@@ -178,6 +182,10 @@ cmark_node_get_list_type(cmark_node *node) {
int
cmark_node_set_list_type(cmark_node *node, cmark_list_type type) {
+ if (!(type == CMARK_BULLET_LIST || type == CMARK_ORDERED_LIST)) {
+ return 0;
+ }
+
if (node->type == CMARK_NODE_LIST) {
node->as.list.list_type = type;
return 1;
@@ -199,6 +207,10 @@ cmark_node_get_list_start(cmark_node *node) {
int
cmark_node_set_list_start(cmark_node *node, int start) {
+ if (start < 0) {
+ return 0;
+ }
+
if (node->type == CMARK_NODE_LIST) {
node->as.list.start = start;
return 1;