summaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-17 00:30:29 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-17 00:30:29 +0000
commit06a1bb335e0971a7b986d7726c48d1502e2517c4 (patch)
treeaa94b127d353d41105e7ae3a5cb6321702489826 /src/helper
parenta830197f59d61b2734ecc872fd7c7905ac36af37 (diff)
downloadopenocd_libswd-06a1bb335e0971a7b986d7726c48d1502e2517c4.tar.gz
openocd_libswd-06a1bb335e0971a7b986d7726c48d1502e2517c4.tar.bz2
openocd_libswd-06a1bb335e0971a7b986d7726c48d1502e2517c4.tar.xz
openocd_libswd-06a1bb335e0971a7b986d7726c48d1502e2517c4.zip
Convert core parse_type implementations to check for underflow errors.
git-svn-id: svn://svn.berlios.de/openocd/trunk@2256 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/command.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 30c5b121..9a8907d6 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -863,16 +863,20 @@ long jim_global_long(const char *variable)
return 0;
}
-#define DEFINE_PARSE_NUM_TYPE(name, type, func, max) \
+#define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \
int parse##name(const char *str, type *ul) \
{ \
+ if (!*str) \
+ return ERROR_COMMAND_SYNTAX_ERROR; \
char *end; \
*ul = func(str, &end, 0); \
- bool is_okay = *str && !*end && (max != *ul); \
- return is_okay ? ERROR_OK : ERROR_COMMAND_SYNTAX_ERROR; \
+ if (*end) \
+ return ERROR_COMMAND_SYNTAX_ERROR; \
+ if (*ul == max || (min && min == *ul)) \
+ return ERROR_COMMAND_SYNTAX_ERROR; \
+ return ERROR_OK; \
}
-DEFINE_PARSE_NUM_TYPE(_ulong, unsigned long , strtoul, ULONG_MAX)
-DEFINE_PARSE_NUM_TYPE(_ullong, unsigned long long, strtoull, ULLONG_MAX)
-DEFINE_PARSE_NUM_TYPE(_long, long , strtol, LONG_MAX)
-DEFINE_PARSE_NUM_TYPE(_llong, long long, strtoll, LLONG_MAX)
-
+DEFINE_PARSE_NUM_TYPE(_ulong, unsigned long , strtoul, 0, ULONG_MAX)
+DEFINE_PARSE_NUM_TYPE(_ullong, unsigned long long, strtoull, 0, ULLONG_MAX)
+DEFINE_PARSE_NUM_TYPE(_long, long , strtol, LONG_MIN, LONG_MAX)
+DEFINE_PARSE_NUM_TYPE(_llong, long long, strtoll, LLONG_MIN, LLONG_MAX)