diff -up authd-1.4.3/authd.c.jiffies64 authd-1.4.3/authd.c
--- authd-1.4.3/authd.c.jiffies64 2008-04-29 12:25:05.000000000 +0200
+++ authd-1.4.3/authd.c 2008-04-29 13:33:18.000000000 +0200
@@ -169,8 +169,13 @@ static bool is_rfc1413_token(const char
return is_in_range((size_t) 1, strlen(s), (size_t) 64);
}
-static bool is_bad_strto(const char *s, const char *endptr) {
- if (errno == ERANGE || errno == EINVAL) return true;
+static bool is_bad_strtoul(unsigned long ul, const char *s, const char *endptr) {
+ if ((ul == ULONG_MAX && errno == ERANGE) || errno == EINVAL) return true;
+ return endptr == s || (*endptr != '\0' && !isspace(*endptr));
+}
+
+static bool is_bad_strtoull(unsigned long long ull, const char *s, const char *endptr) {
+ if ((ull == ULLONG_MAX && errno == ERANGE) || errno == EINVAL) return true;
return endptr == s || (*endptr != '\0' && !isspace(*endptr));
}
@@ -253,7 +258,7 @@ static void create_opt(int argc, char *a
case 'l':
if (optarg != NULL) {
lu = strtoul(optarg, &endptr, 0);
- if (lu > UINT_MAX || is_bad_strto(optarg, endptr))
+ if (lu > UINT_MAX || is_bad_strtoul(lu, optarg, endptr))
handle_error(C_FMT, *argv, c, optarg);
else opt.log_mask = (int) lu;
setlogmask(opt.log_mask);
@@ -263,7 +268,7 @@ static void create_opt(int argc, char *a
case 'm':
if (optarg != NULL) {
opt.multiquery = strtoull(optarg, &endptr, 10);
- if (is_bad_strto(optarg, endptr))
+ if (is_bad_strtoull(opt.multiquery, optarg, endptr))
handle_error(C_FMT, *argv, c, optarg);
}
else opt.multiquery = ULLONG_MAX;
@@ -275,7 +280,7 @@ static void create_opt(int argc, char *a
case 'o': opt.other = true; break;
case 't':
lu = optarg == NULL ? DFL_T_O : strtoul(optarg, &endptr, 10);
- if (lu > UINT_MAX || is_bad_strto(optarg, endptr))
+ if (lu > UINT_MAX || is_bad_strtoul(lu, optarg, endptr))
handle_error(C_FMT, *argv, c, optarg);
else if (lu < 30) {
log_notice(_("Timeout's too low; Raising to 30.\n"));
@@ -294,7 +299,7 @@ static void create_opt(int argc, char *a
case FN_LONGOPT:
if (optarg != NULL) {
lu = strtoul(optarg, &endptr, 10);
- if (lu > UINT_MAX || is_bad_strto(optarg, endptr))
+ if (lu > UINT_MAX || is_bad_strtoul(lu, optarg, endptr))
handle_error(S_FMT, *argv, LONG_OPTS[i].name, optarg);
else opt.fn = (unsigned) lu;
}
@@ -347,7 +352,7 @@ static void create_opt(int argc, char *a
static const char *const DELIM = ",: \t\r\n\v\f";
-static unsigned long get_tok_uint(char *s, unsigned base) {
+static unsigned long get_tok_ulong(char *s, unsigned base) {
unsigned long ul = ULONG_MAX;
assert(base <= 36);
@@ -355,13 +360,21 @@ static unsigned long get_tok_uint(char *
char *endptr;
ul = strtoul(s, &endptr, (int) base);
- if (ul > UINT_MAX || is_bad_strto(s, endptr))
+ if (ul > UINT_MAX || is_bad_strtoul(ul, s, endptr))
errno = EINVAL;
}
else errno = EINVAL;
return ul;
}
+static unsigned int get_tok_uint(char *s, unsigned base) {
+ unsigned long ul = get_tok_ulong(s, base);
+ if (ul > UINT_MAX)
+ errno = EINVAL;
+ return ul;
+}
+
+
static void destroy_opt(void) {
free(opt.codeset); free(opt.Encrypt); free(opt.ident); free(opt.lang);
free(opt.Noident); free(opt.os); free(opt.passwd); free(opt.mapped);
@@ -510,7 +523,7 @@ static char *get_created_tok_addr(const
addr_hex[z] = '\0'; z -= HEX_DIG;
ul = strtoul(addr_hex + z, &endptr, 16);
- if (is_bad_strto(addr_hex + z, endptr)) {
+ if (is_bad_strtoul(ul, addr_hex + z, endptr)) {
errno = EINVAL; return NULL;
}
if ((!IS_IPV4 || 6 == z) && is_16_bits)
@@ -654,9 +667,17 @@ static bool get_info(reply_t *out, reque
(void) get_tok_uint(NULL, 16); // tx_queue
(void) get_tok_uint(NULL, 16); // rx_queue
(void) get_tok_uint(NULL, 16); // tr (boolean)
- (void) get_tok_uint(NULL, 16); // tm->when (unit: jiffies)
+ /* as of 2.4.18 this is sa long in the kernel thus it is 32b on 32b
+ platforms and 64b on 64b platforms. 32b platforms also have a
+ jiffies_64 but that is not what is exported so we don't have to use
+ a long long on 32b platforms.
+ Ref: net/ipv4/tcp_ipv4.c:get_tcp_sock()
+ */
+ (void) get_tok_ulong(NULL, 16); // tm->when (unit: jiffies)
strtok(NULL, DELIM); // retrnsmt
uid = get_tok_uint(NULL, 10); // uid (base 10 uint)
+
+ // beware using timeout. It is a long and may be 64b.
strtok(NULL, DELIM); // timeout
inode = get_tok_uint(NULL, 10); // inode (base 10 uint)
if (errno == EINVAL) {