]> git.donarmstrong.com Git - unscd.git/blob - debian/patches/support_large_numbers_in_config
Support at least INT_MAX numbers in config (Closes: #676689)
[unscd.git] / debian / patches / support_large_numbers_in_config
1 From: Don Armstrong <don@debian.org>
2 Subject: Support at least INT_MAX numbers in config
3 Origin: debian
4 Bug-Debian: http://bugs.debian.org/676689
5 --- a/nscd.c
6 +++ b/nscd.c
7 @@ -438,7 +438,8 @@
8                 char *p;
9                 unsigned long l = strtoul(str, &p, 10);
10                 /* must not overflow int even after x1000 */
11 -               if (!*p && l <= INT_MAX / 1000)
12 +        /* This is not required with the changes to have a unsigned long ttl */
13 +               if (!*p && l <= INT_MAX)
14                         return l;
15         }
16         error_and_die("malformed or too big number '%s'", str);
17 @@ -510,8 +511,8 @@
18         const char *user;
19         smallint srv_enable[3];
20         smallint check_files[3];
21 -       unsigned pttl[3];
22 -       unsigned nttl[3];
23 +       unsigned long pttl[3];
24 +       unsigned long nttl[3];
25         unsigned size[3];
26  } config = {
27         /* We try to closely mimic glibc nscd */
28 @@ -746,11 +747,11 @@
29         return sizeof(user_req_header) + ureq->key_len;
30  }
31  
32 -static unsigned cache_age(const user_req *ureq)
33 +static unsigned long cache_age(const user_req *ureq)
34  {
35         if (!CACHED_ENTRY(ureq))
36                 return 0;
37 -       return (uint32_t) (g_now_ms - (ureq->timestamp24 << 8));
38 +       return (unsigned long) (g_now_ms - (ureq->timestamp24 << 8));
39  }
40  
41  static void set_cache_timestamp(user_req *ureq)
42 @@ -1271,9 +1272,9 @@
43         }
44  
45         unsigned oldest_idx = 0;
46 -       unsigned oldest_age = 0;
47 +       unsigned long oldest_age = 0;
48         for (i = 0; i < 8; i++) {
49 -               unsigned age = cache_age(cacheline[i]);
50 +               unsigned long age = cache_age(cacheline[i]);
51                 if (age > oldest_age) {
52                         oldest_age = age;
53                         oldest_idx = i;
54 @@ -1290,7 +1291,7 @@
55                 return NULL;
56         }
57         i = oldest_idx;
58 -       log(L_DEBUG, "not found, freeing and reusing cache[%u][%u] (age %u)", hash, i, oldest_age);
59 +       log(L_DEBUG, "not found, freeing and reusing cache[%u][%u] (age %ul)", hash, i, oldest_age);
60         free_refcounted_ureq(&cacheline[i]);
61  
62   ret:
63 @@ -1317,11 +1318,11 @@
64                                         cached_cnt--;
65                                         free_refcounted_ureq(cp);
66                                 } else {
67 -                                       unsigned age = cache_age(cached);
68 +                                       unsigned long age = cache_age(cached);
69                                         response_header *resp = ureq_response(cached);
70 -                                       unsigned ttl = (resp->found ? config.pttl : config.nttl)[csrv];
71 +                                       unsigned long ttl = (resp->found ? config.pttl : config.nttl)[csrv];
72                                         if (age >= ttl) {
73 -                                               log(L_DEBUG2, "freeing: age %u positive %d ttl %u", age, resp->found, ttl);
74 +                                               log(L_DEBUG2, "freeing: age %ul positive %d ttl %ul", age, resp->found, ttl);
75                                                 cached_cnt--;
76                                                 free_refcounted_ureq(cp);
77                                         } else if (srv == -1) {
78 @@ -2641,7 +2642,7 @@
79         }
80  
81         for (n = 0; n < 3; n++) {
82 -               log(L_DEBUG, "%s cache enabled:%u pttl:%u nttl:%u",
83 +               log(L_DEBUG, "%s cache enabled:%u pttl:%ul nttl:%ul",
84                                 srv_name[n],
85                                 config.srv_enable[n],
86                                 config.pttl[n],