63 |
63 |
64 |
64 |
65 |
65 |
66 #include <stdlib.h> |
66 #include <stdlib.h> |
67 #include <string.h> |
67 #include <string.h> |
|
68 #include <limits.h> |
68 //define PERM_MALLOC malloc |
69 //define PERM_MALLOC malloc |
69 //define PERM_FREE free |
70 //define PERM_FREE free |
70 //define PERM_REALLOC realloc |
71 //define PERM_REALLOC realloc |
71 //define PERM_CALLOC calloc |
72 //define PERM_CALLOC calloc |
72 //define PERM_STRDUP strdup |
73 //define PERM_STRDUP strdup |
89 } |
90 } |
90 |
91 |
91 return 0; |
92 return 0; |
92 } |
93 } |
93 |
94 |
|
95 #define POOL_MIN_BLOCKSIZE 128 |
|
96 |
94 NSAPI_PUBLIC int |
97 NSAPI_PUBLIC int |
95 pool_init(pblock *pb, Session *sn, Request *rq) |
98 pool_init(pblock *pb, Session *sn, Request *rq) |
96 { |
99 { |
97 //char *str_block_size = pblock_findval("block-size", pb); |
100 //char *str_block_size = pblock_findval("block-size", pb); |
98 //char *str_pool_disable = pblock_findval("disable", pb); |
101 //char *str_pool_disable = pblock_findval("disable", pb); |
99 char *str_block_size = "16384"; |
102 char *str_block_size = "16384"; |
100 char *str_pool_disable = "false"; |
103 char *str_pool_disable = "false"; |
101 int n; |
104 int n; |
102 |
105 |
103 //printf("standard block size: %d\n", pool_config.block_size); |
106 //printf("standard block size: %d\n", pool_config.block_size); |
104 |
107 |
105 if (str_block_size != NULL) { |
108 if (str_block_size != NULL) { |
106 n = atoi(str_block_size); |
109 int64_t value; |
107 if (n > 0) |
110 if(!util_strtoint(str_block_size, &value)) { |
108 pool_config.block_size = n; |
111 log_ereport(LOG_MISCONFIG, "pool-init: param 'block-size' is not an integer"); |
|
112 return REQ_ABORTED; |
|
113 } |
|
114 if(value > INT_MAX) { |
|
115 log_ereport(LOG_MISCONFIG, "pool-init: block-size is too big"); |
|
116 return REQ_ABORTED; |
|
117 } |
|
118 if(value < POOL_MIN_BLOCKSIZE) { |
|
119 log_ereport(LOG_MISCONFIG, "pool-init: block-size is too small"); |
|
120 return REQ_ABORTED; |
|
121 } |
|
122 pool_config.block_size = value; |
109 } |
123 } |
110 |
124 |
111 if (str_pool_disable && util_getboolean(str_pool_disable, PR_TRUE)) { |
125 if (str_pool_disable && util_getboolean(str_pool_disable, PR_TRUE)) { |
112 /* We'll call PERM_MALLOC() on each pool_malloc() call */ |
126 /* We'll call PERM_MALLOC() on each pool_malloc() call */ |
113 pool_config.block_size = 0; |
127 pool_config.block_size = 0; |