summaryrefslogtreecommitdiff
path: root/update-mime-database.c
diff options
context:
space:
mode:
authorChristophe Fergeau <teuf@gnome.org>2004-11-26 22:56:55 +0000
committerChristophe Fergeau <teuf@gnome.org>2004-11-26 22:56:55 +0000
commit09203a9f944196fc1fe1ee21a6664bef20ce879f (patch)
tree7326bb1a62ff84e16107ac7f0bef0ea3c999c86a /update-mime-database.c
parent68156f5d9c14669dcc240f98c45212e7c6ce1481 (diff)
2004-11-26 Christophe Fergeau <teuf@gnome.org>
* update-mime-database.c: (parse_int_value), (match_offset): use strtoul when reading an unsigned long, not strtol, fixes #1506
Diffstat (limited to 'update-mime-database.c')
-rw-r--r--update-mime-database.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/update-mime-database.c b/update-mime-database.c
index 373dd55..a4b207c 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -840,7 +840,14 @@ static void parse_int_value(int bytes, const char *in, const char *in_mask,
unsigned long value;
int b;
- value = strtol(in, &end, 0);
+ value = strtoul(in, &end, 0);
+ if (errno == ERANGE) {
+ g_set_error(error, MIME_ERROR, 0,
+ "Number out-of-range (%s should fit in %d bytes)",
+ in, bytes);
+ return;
+ }
+
if (*end != '\0')
{
g_set_error(error, MIME_ERROR, 0, "Value is not a number");
@@ -865,9 +872,17 @@ static void parse_int_value(int bytes, const char *in, const char *in_mask,
if (in_mask)
{
int b;
- long mask;
+ unsigned long mask;
- mask = strtol(in_mask, &end, 0);
+ mask = strtoul(in_mask, &end, 0);
+ if (errno == ERANGE) {
+ g_set_error(error, MIME_ERROR, 0,
+ "Mask out-of-range (%s should fit in %d bytes)",
+ in_mask, bytes);
+ return;
+ }
+
+
if (*end != '\0')
{
g_set_error(error, MIME_ERROR, 0,
@@ -1022,11 +1037,33 @@ static void match_offset(Match *match, xmlNode *node, GError **error)
}
match->range_start = strtol(offset, &end, 10);
+ if (errno == ERANGE) {
+ char *number;
+ number = g_strndup(offset, end-offset);
+ g_set_error(error, MIME_ERROR, 0,
+ "Number out-of-range (%s should fit in 4 bytes)",
+ number);
+ g_free(number);
+ return;
+ }
+
if (*end == ':' && end[1] && match->range_start >= 0)
{
int last;
+ char *begin;
+
+ begin = end + 1;
+ last = strtol(begin, &end, 10);
+ if (errno == ERANGE) {
+ char *number;
+ number = g_strndup(begin, end-begin);
+ g_set_error(error, MIME_ERROR, 0,
+ "Number out-of-range (%s should fit in 8 bytes)",
+ number);
+ g_free(number);
+ return;
+ }
- last = strtol(end + 1, &end, 10);
if (*end == '\0' && last >= match->range_start)
match->range_length = last - match->range_start + 1;
else