provider = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
if (provider) {
balancer->lbmethod = provider;
- PROXY_STRNCPY(balancer->s->lbpname, val);
- return NULL;
+ if (PROXY_STRNCPY(balancer->s->lbpname, val) == APR_SUCCESS) {
+ return NULL;
+ }
+ else {
+ return "lbmethod name too large";
+ }
}
return "unknown lbmethod";
}
*balancer->s->nonce = '\0';
}
else {
- if (strlen(val) > sizeof(balancer->s->nonce)-1) {
+ if (PROXY_STRNCPY(balancer->s->nonce, val) != APR_SUCCESS) {
return "Provided nonce is too large";
}
- else {
- PROXY_STRNCPY(balancer->s->nonce, val);
- }
}
}
else if (!strcasecmp(key, "growth")) {
#define PROXY_WORKER_DEFAULT_RETRY 60
/* Some max char string sizes, for shm fields */
-#ifndef PROXY_WORKER_MAX_SCHEME_SIZE
#define PROXY_WORKER_MAX_SCHEME_SIZE 16
-#endif
-#ifndef PROXY_WORKER_MAX_ROUTE_SIZE
#define PROXY_WORKER_MAX_ROUTE_SIZE 64
-#endif
-#ifndef PROXY_WORKER_MAX_NAME_SIZE
#define PROXY_WORKER_MAX_NAME_SIZE 96
#define PROXY_BALANCER_MAX_NAME_SIZE PROXY_WORKER_MAX_NAME_SIZE
-#endif
-#ifndef PROXY_WORKER_MAX_HOSTNAME_SIZE
#define PROXY_WORKER_MAX_HOSTNAME_SIZE 64
#define PROXY_BALANCER_MAX_HOSTNAME_SIZE PROXY_WORKER_MAX_HOSTNAME_SIZE
-#endif
-#ifndef PROXY_BALANCER_MAX_STICKY_SIZE
#define PROXY_BALANCER_MAX_STICKY_SIZE 64
-#endif
-#ifndef PROXY_MAX_PROVIDER_NAME_SIZE
#define PROXY_MAX_PROVIDER_NAME_SIZE 16
-#endif
-#define PROXY_STRNCPY(dst, src) apr_cpystrn((dst), (src), sizeof(dst))
+#define PROXY_STRNCPY(dst, src) ap_proxy_strncpy((dst), (src), (sizeof(dst)))
#define PROXY_COPY_CONF_PARAMS(w, c) \
do { \
/* proxy_util.c */
-PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
+PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src, size_t dlen);
+PROXY_DECLARE(request_rec *) ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
(request_rec *r, request_rec *pr), (r, pr),
OK, DECLINED)
+PROXY_DECLARE(apr_status_t) ap_proxy_strncpy(char *dst, const char *src, size_t dlen)
+{
+ if ((strlen(src)+1) > dlen) {
+ /* APR_ENOSPACE would be better */
+ return APR_EGENERAL;
+ }
+ else {
+ apr_cpystrn(dst, src, dlen);
+ }
+ return APR_SUCCESS;
+}
+
/* already called in the knowledge that the characters are hex digits */
PROXY_DECLARE(int) ap_proxy_hex2c(const char *x)
{
bshared->was_malloced = (do_malloc != 0);
PROXY_STRNCPY(bshared->lbpname, "byrequests");
- PROXY_STRNCPY(bshared->name, uri);
+ if (PROXY_STRNCPY(bshared->name, uri) != APR_SUCCESS) {
+ return apr_psprintf(p, "balancer name (%s) too long", uri);
+ }
ap_pstr2_alnum(p, bshared->name + sizeof(BALANCER_PREFIX) - 1,
&sname);
sname = apr_pstrcat(p, conf->id, "_", sname, NULL);
- PROXY_STRNCPY(bshared->sname, sname);
- PROXY_STRNCPY(bshared->alias, alias);
+ if (PROXY_STRNCPY(bshared->sname, sname) != APR_SUCCESS) {
+ return apr_psprintf(p, "balancer safe-name (%s) too long", sname);
+ }
+ if (PROXY_STRNCPY(bshared->alias, alias) != APR_SUCCESS) {
+ return apr_psprintf(p, "balancer front-end url (%s) too long", alias);
+ }
bshared->hash = ap_proxy_hashfunc(bshared->name, PROXY_HASHFUNC_DEFAULT);
(*balancer)->hash = bshared->hash;
* the process. */
apr_uuid_get(&uuid);
apr_uuid_format(nonce, &uuid);
- PROXY_STRNCPY(bshared->nonce, nonce);
+ if (PROXY_STRNCPY(bshared->nonce, nonce) != APR_SUCCESS) {
+ return apr_psprintf(p, "balancer nonce (%s) too long", nonce);
+ }
(*balancer)->s = bshared;
int rv;
apr_uri_t uri;
proxy_worker_shared *wshared;
+ char *ptr;
rv = apr_uri_parse(p, url, &uri);
memset(wshared, 0, sizeof(proxy_worker_shared));
- PROXY_STRNCPY(wshared->name, apr_uri_unparse(p, &uri, APR_URI_UNP_REVEALPASSWORD));
- PROXY_STRNCPY(wshared->scheme, uri.scheme);
- PROXY_STRNCPY(wshared->hostname, uri.hostname);
+ ptr = apr_uri_unparse(p, &uri, APR_URI_UNP_REVEALPASSWORD);
+ if (PROXY_STRNCPY(wshared->name, ptr) != APR_SUCCESS) {
+ return apr_psprintf(p, "worker name (%s) too long", ptr);
+ }
+ if (PROXY_STRNCPY(wshared->scheme, uri.scheme) != APR_SUCCESS) {
+ return apr_psprintf(p, "worker scheme (%s) too long", uri.scheme);
+ }
+ if (PROXY_STRNCPY(wshared->hostname, uri.hostname) != APR_SUCCESS) {
+ return apr_psprintf(p, "worker hostname (%s) too long", uri.hostname);
+ }
wshared->port = uri.port;
wshared->flush_packets = flush_off;
wshared->flush_wait = PROXY_FLUSH_WAIT;