diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-26 17:20:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-26 17:20:02 +0000 |
commit | 84b11c83de28c606157a210e679f3519a41921b9 (patch) | |
tree | a2893eee89ff2d3731cdcd13edb030f22b1c9fbc /src/util/strings.c | |
parent | 5272b27b9373a21884fde643a7d582df6b3b421b (diff) | |
download | gnunet-84b11c83de28c606157a210e679f3519a41921b9.tar.gz gnunet-84b11c83de28c606157a210e679f3519a41921b9.zip |
-improvements to parsers
Diffstat (limited to 'src/util/strings.c')
-rw-r--r-- | src/util/strings.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/util/strings.c b/src/util/strings.c index 2fc647f7b..60c667ca4 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -1354,6 +1354,7 @@ parse_port_policy (const char *port_policy, | |||
1354 | const char *pos; | 1354 | const char *pos; |
1355 | int s; | 1355 | int s; |
1356 | int e; | 1356 | int e; |
1357 | char eol[2]; | ||
1357 | 1358 | ||
1358 | pos = port_policy; | 1359 | pos = port_policy; |
1359 | if ('!' == *pos) | 1360 | if ('!' == *pos) |
@@ -1362,17 +1363,35 @@ parse_port_policy (const char *port_policy, | |||
1362 | pos++; | 1363 | pos++; |
1363 | } | 1364 | } |
1364 | if (2 == sscanf (pos, | 1365 | if (2 == sscanf (pos, |
1365 | "%u-%u", | 1366 | "%u-%u%1s", |
1366 | &s, &e)) | 1367 | &s, &e, eol)) |
1367 | { | 1368 | { |
1369 | if ( (0 == s) || | ||
1370 | (s > 0xFFFF) || | ||
1371 | (e < s) || | ||
1372 | (e > 0xFFFF) ) | ||
1373 | { | ||
1374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1375 | _("Port not in range\n")); | ||
1376 | return GNUNET_SYSERR; | ||
1377 | } | ||
1368 | pp->start_port = (uint16_t) s; | 1378 | pp->start_port = (uint16_t) s; |
1369 | pp->end_port = (uint16_t) e; | 1379 | pp->end_port = (uint16_t) e; |
1370 | return GNUNET_OK; | 1380 | return GNUNET_OK; |
1371 | } | 1381 | } |
1372 | if (1 == sscanf (pos, | 1382 | if (1 == sscanf (pos, |
1373 | "%u", | 1383 | "%u%1s", |
1374 | &s)) | 1384 | &s, |
1385 | eol)) | ||
1375 | { | 1386 | { |
1387 | if ( (0 == s) || | ||
1388 | (s > 0xFFFF) ) | ||
1389 | { | ||
1390 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1391 | _("Port not in range\n")); | ||
1392 | return GNUNET_SYSERR; | ||
1393 | } | ||
1394 | |||
1376 | pp->start_port = (uint16_t) s; | 1395 | pp->start_port = (uint16_t) s; |
1377 | pp->end_port = (uint16_t) s; | 1396 | pp->end_port = (uint16_t) s; |
1378 | return GNUNET_OK; | 1397 | return GNUNET_OK; |
@@ -1571,8 +1590,8 @@ GNUNET_STRINGS_parse_ipv4_policy (const char *routeListX) | |||
1571 | if (pos < strlen (routeList)) | 1590 | if (pos < strlen (routeList)) |
1572 | { | 1591 | { |
1573 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1592 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1574 | _("Invalid format for IP: `%s'\n"), | 1593 | _("Invalid format: `%s'\n"), |
1575 | &routeList[pos]); | 1594 | &routeListX[pos]); |
1576 | GNUNET_free (result); | 1595 | GNUNET_free (result); |
1577 | GNUNET_free (routeList); | 1596 | GNUNET_free (routeList); |
1578 | return NULL; /* oops */ | 1597 | return NULL; /* oops */ |