diff -rub aspell-0.61-20071019.orig/common/filter.cpp aspell-0.61-20071019/common/filter.cpp --- aspell-0.61-20071019.orig/common/filter.cpp 2005-05-02 22:08:19.000000000 -0700 +++ aspell-0.61-20071019/common/filter.cpp 2007-10-21 21:32:32.000000000 -0700 @@ -90,15 +90,17 @@ static PosibErr version_compare(const char * x, const char * y) { do { - int xn = 0, yn = 0; + long xn = 0, yn = 0, errval = 0; if (*x) { - if (!asc_isdigit(*x)) return make_err(bad_version_string); - xn = strtoi_c(x, &x);} + xn = strtoi_c(x, (char**)(&x), &errval); + if (errval) return make_err(bad_version_string); + } if (*y) { - if (!asc_isdigit(*y)) return make_err(bad_version_string); - yn = strtoi_c(y, &y);} - int diff = xn - yn; - if (diff != 0) return diff; + yn = strtoi_c(y, (char**)(&y), &errval); + if (errval) return make_err(bad_version_string); + } + long diff = xn - yn; + if (diff) return diff; if (*x) { if (*x != '.') return make_err(bad_version_string); ++x;} diff -rub aspell-0.61-20071019.orig/common/strtonum.cpp aspell-0.61-20071019/common/strtonum.cpp --- aspell-0.61-20071019.orig/common/strtonum.cpp 2005-05-02 22:08:19.000000000 -0700 +++ aspell-0.61-20071019/common/strtonum.cpp 2007-10-21 20:56:09.000000000 -0700 @@ -4,6 +4,8 @@ // copy of the LGPL license along with this library if you did not you // can find it at http://www.gnu.org/. +#include +#include #include #include "strtonum.hpp" @@ -71,25 +73,38 @@ return x; } - long strtoi_c(const char * npter, const char ** endptr) { + long strtoi_c(const char * npter, char ** endptr, long * errval) { char * str = (char*)npter; long num = 0; - long sign = 1; + char negative = 0; + //errno may already be set from a previous error - don't set to 0 - *endptr = str; - while (asc_isspace(*str)) { + while (asc_isspace(*str)) str++; + if (*str == '-') { + negative = -1; + str++; + } else if (*str == '+') + str++; + if (*str < '0' || *str > '9') { //error, no number found + *errval = EINVAL; + goto END_STRTOI_C; } - if (*str == '-' || *str == '+') { - sign = *(str++) == '-' ? -1 : 1; - } - while (*str >= '0' && *str <= '9' ) { + while (*str >= '0' && *str <= '9') { num = num * 10 + (long)(*str - '0'); + if (num < 0 //quick test first, then do extra overflow test + && (negative ? (num - 1 < 0):1)) { + *errval = ERANGE; + num = negative ? -LONG_MIN : LONG_MAX; + goto END_STRTOI_C; + } str++; } + END_STRTOI_C: + if (endptr) *endptr = str; - return num; + return negative ? -num : num; } } diff -rub aspell-0.61-20071019.orig/common/strtonum.hpp aspell-0.61-20071019/common/strtonum.hpp --- aspell-0.61-20071019.orig/common/strtonum.hpp 2005-05-02 22:08:19.000000000 -0700 +++ aspell-0.61-20071019/common/strtonum.hpp 2007-10-21 20:55:59.000000000 -0700 @@ -12,8 +12,7 @@ // Local independent numeric conversion. It is OK if // nptr == *endptr double strtod_c(const char * nptr, const char ** endptr); - long strtoi_c(const char * npter, const char ** endptr); - + long strtoi_c(const char * npter, char ** endptr, long * errval); } #endif diff -rub aspell-0.61-20071019.orig/lib/new_fmode.cpp aspell-0.61-20071019/lib/new_fmode.cpp --- aspell-0.61-20071019.orig/lib/new_fmode.cpp 2005-10-21 05:16:03.000000000 -0700 +++ aspell-0.61-20071019/lib/new_fmode.cpp 2007-10-21 21:36:28.000000000 -0700 @@ -1,5 +1,5 @@ // This file is part of The New Aspell -// Copyright (C) 2004 by Christoph Hintermüller (JEH) under the GNU LGPL +// Copyright (C) 2004 by Christoph Hinterm�ller (JEH) under the GNU LGPL // license version 2.0 or 2.1. You should have received a copy of the // LGPL license along with this library if you did not you can find it // at http://www.gnu.org/. @@ -336,10 +336,13 @@ const char * numEnd = num + number.size(); const char * endHere = numEnd; long position = 0; + long errval = 0; - if ( ( number.size() == 0 ) - || ( (position = strtoi_c(num,&numEnd)) < 0 ) - || ( numEnd != endHere ) ) { + if (number.size() == 0) + return make_err(file_magic_pos,"",magic.str()); + else { + position = strtoi_c(num, (char**)(&numEnd), &errval); + if (errval || position < 0 || numEnd != endHere) return make_err(file_magic_pos,"",magic.str()); } if ( ( magicFilePosition >= magic.size() ) @@ -375,13 +378,17 @@ num = (char*)number.str(); endHere = numEnd = num + number.size(); - if ( ( number.size() == 0 ) - || ( (position = strtoi_c(num,&numEnd)) < 0 ) - || ( numEnd != endHere ) ) { - if ( seekIn != NULL ) { + if (number.size() == 0) { + if ( seekIn != NULL ) rewind(seekIn); - } return make_err(file_magic_range,mode.str(),magic.str());//no magic range given + } else { + position = strtoi_c(num, (char**)(&numEnd), &errval); + if (errval || position < 0 || numEnd != endHere) { + if ( seekIn != NULL ) + rewind(seekIn); + return make_err(file_magic_range,mode.str(),magic.str());//no magic range given + } } regex_t seekMagic; Only in aspell-0.61-20071019.orig: .libs