diff options
author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-08-25 15:43:09 +0200 |
---|---|---|
committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-08-25 15:43:09 +0200 |
commit | 4b05610fa5c88dccb1d49d74e2bb2896af4dac4b (patch) | |
tree | 7567ea50ec837a83d3dbb3d8e4340a145cd8d1f6 /lasso/xml | |
parent | fc9c2738c680370edba577689e341a0e7c87a182 (diff) | |
download | lasso-4b05610fa5c88dccb1d49d74e2bb2896af4dac4b.tar.gz lasso-4b05610fa5c88dccb1d49d74e2bb2896af4dac4b.tar.xz lasso-4b05610fa5c88dccb1d49d74e2bb2896af4dac4b.zip |
[XML] use strtol instead of atoi to parse XSchema integers
This commit also reject negative integers from being parsed (all integers
in SAMLv2 and ID-FFv1.2 schemas are positive integers).
Diffstat (limited to 'lasso/xml')
-rw-r--r-- | lasso/xml/xml.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c index f5339721..db20ac25 100644 --- a/lasso/xml/xml.c +++ b/lasso/xml/xml.c @@ -1295,7 +1295,15 @@ lasso_node_impl_init_from_xml(LassoNode *node, xmlNode *xmlnode) *(void**)value = tmp; tmp = NULL; } else if (snippet->type & SNIPPET_INTEGER) { - int val = atoi(tmp); + int val = strtol(tmp, NULL, 10); + if (((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE) + || errno == EINVAL || val < 0) { + if (snippet->type & SNIPPET_OPTIONAL_NEG) { + val = -1; + } else { + val = 0; + } + } (*(int*)value) = val; trace_snippet(" setting integer %i for ", val); xmlFree(tmp); @@ -1356,7 +1364,15 @@ lasso_node_impl_init_from_xml(LassoNode *node, xmlNode *xmlnode) continue; if (snippet->type & SNIPPET_INTEGER) { - int val = atoi(tmp); + int val = strtol(tmp, NULL, 10); + if (((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE) + || errno == EINVAL || val < 0) { + if (snippet->type & SNIPPET_OPTIONAL_NEG) { + val = -1; + } else { + val = 0; + } + } (*(int*)value) = val; } else if (snippet->type & SNIPPET_BOOLEAN) { int val = 0; |