From 6e932b2870762bf8875f3616ad15df36dc859f05 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Sat, 11 Aug 2001 04:04:13 +0000 Subject: [PATCH] Fix the new method code. We need to cast 1 to an apr_int64_t or it will be treated as a 32-bit integer, and it will wrap after being shifted 32 times. Submitted by: Cody Sherr and Ryan Morgan git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@90090 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_protocol.h | 5 ++-- include/httpd.h | 6 +++++ modules/aaa/mod_access.c | 4 ++-- modules/aaa/mod_auth.c | 2 +- modules/aaa/mod_auth_db.c | 2 +- modules/aaa/mod_auth_dbm.c | 2 +- modules/aaa/mod_auth_digest.c | 2 +- modules/cache/mod_file_cache.c | 2 +- modules/dav/main/mod_dav.c | 26 ++++++++++---------- modules/filters/mod_include.c | 2 +- modules/generators/mod_asis.c | 2 +- modules/generators/mod_autoindex.c | 2 +- modules/generators/mod_cgi.c | 4 ++-- modules/generators/mod_cgid.c | 4 ++-- modules/generators/mod_info.c | 2 +- modules/generators/mod_status.c | 2 +- modules/http/http_protocol.c | 38 +++++++++++++++--------------- modules/mappers/mod_actions.c | 2 +- modules/test/mod_autoindex.c | 2 +- modules/test/mod_rndchunk.c | 2 +- modules/test/mod_test_util_uri.c | 2 +- server/config.c | 2 +- server/core.c | 2 +- server/request.c | 2 +- 24 files changed, 64 insertions(+), 57 deletions(-) diff --git a/include/http_protocol.h b/include/http_protocol.h index a27d5e77b8..b2754ed910 100644 --- a/include/http_protocol.h +++ b/include/http_protocol.h @@ -246,7 +246,7 @@ AP_DECLARE(size_t) ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset, * @param methname The name of the new method to register. * @return Ab int value representing an offset into a bitmask. */ -AP_DECLARE(int) ap_method_register(apr_pool_t *p, char *methname); +AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname); /** * Initialize the method_registry and allocate memory for it. @@ -259,7 +259,8 @@ AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p); * This is a convenience macro to ease with checking a mask * against a method name. */ -#define AP_METHOD_CHECK_ALLOWED(mask, methname) ((mask) & (1 << ap_method_number_of((methname)))) +#define AP_METHOD_CHECK_ALLOWED(mask, methname) \ + ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname)))) /** * Create a new method list with the specified number of preallocated diff --git a/include/httpd.h b/include/httpd.h index e32ed8ef4a..254c098ea5 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -503,6 +503,12 @@ AP_DECLARE(const char *) ap_get_server_built(void); */ #define METHODS 64 +/** + * The method mask bit to shift for anding with a bitmask. + */ +#define AP_METHOD_BIT (apr_int64_t)1 + + typedef struct ap_method_list_t ap_method_list_t; /** * Structure for handling HTTP methods. Methods known to the server are diff --git a/modules/aaa/mod_access.c b/modules/aaa/mod_access.c index 41d6133879..6b77006e53 100644 --- a/modules/aaa/mod_access.c +++ b/modules/aaa/mod_access.c @@ -141,7 +141,7 @@ static const char *order(cmd_parms *cmd, void *dv, const char *arg) return "unknown order"; for (i = 0; i < METHODS; ++i) - if (cmd->limited & (1 << i)) + if (cmd->limited & (AP_METHOD_BIT << i)) d->order[i] = o; return NULL; @@ -239,7 +239,7 @@ static int find_allowdeny(request_rec *r, apr_array_header_t *a, int method) { allowdeny *ap = (allowdeny *) a->elts; - apr_int64_t mmask = (1 << method); + apr_int64_t mmask = (AP_METHOD_BIT << method); int i; int gothost = 0; const char *remotehost = NULL; diff --git a/modules/aaa/mod_auth.c b/modules/aaa/mod_auth.c index c3768a45fb..482b0249d4 100644 --- a/modules/aaa/mod_auth.c +++ b/modules/aaa/mod_auth.c @@ -268,7 +268,7 @@ static int check_user_access(request_rec *r) for (x = 0; x < reqs_arr->nelts; x++) { - if (!(reqs[x].method_mask & (1 << m))) + if (!(reqs[x].method_mask & (AP_METHOD_BIT << m))) continue; method_restricted = 1; diff --git a/modules/aaa/mod_auth_db.c b/modules/aaa/mod_auth_db.c index a39112e20c..3c13531280 100644 --- a/modules/aaa/mod_auth_db.c +++ b/modules/aaa/mod_auth_db.c @@ -360,7 +360,7 @@ static int db_check_auth(request_rec *r) for (x = 0; x < reqs_arr->nelts; x++) { - if (!(reqs[x].method_mask & (1 << m))) + if (!(reqs[x].method_mask & (AP_METHOD_BIT << m))) continue; t = reqs[x].requirement; diff --git a/modules/aaa/mod_auth_dbm.c b/modules/aaa/mod_auth_dbm.c index 25529b1b33..3d110e9659 100644 --- a/modules/aaa/mod_auth_dbm.c +++ b/modules/aaa/mod_auth_dbm.c @@ -299,7 +299,7 @@ static int dbm_check_auth(request_rec *r) for (x = 0; x < reqs_arr->nelts; x++) { - if (!(reqs[x].method_mask & (1 << m))) + if (!(reqs[x].method_mask & (AP_METHOD_BIT << m))) continue; t = reqs[x].requirement; diff --git a/modules/aaa/mod_auth_digest.c b/modules/aaa/mod_auth_digest.c index 1cbdc4facc..d7326370ba 100644 --- a/modules/aaa/mod_auth_digest.c +++ b/modules/aaa/mod_auth_digest.c @@ -1851,7 +1851,7 @@ static int digest_check_auth(request_rec *r) for (x = 0; x < reqs_arr->nelts; x++) { - if (!(reqs[x].method_mask & (1 << m))) + if (!(reqs[x].method_mask & (AP_METHOD_BIT << m))) continue; method_restricted = 1; diff --git a/modules/cache/mod_file_cache.c b/modules/cache/mod_file_cache.c index 0de8efb279..568e059098 100644 --- a/modules/cache/mod_file_cache.c +++ b/modules/cache/mod_file_cache.c @@ -387,7 +387,7 @@ static int file_cache_handler(request_rec *r) } /* note that we would handle GET on this resource */ - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); /* This handler has no use for a request body (yet), but we still * need to read and discard it if the client sent one. diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 5423affb2d..aa1f8ffedb 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -4466,28 +4466,28 @@ static int dav_handler(request_rec *r) * These are the HTTP-defined methods that we handle directly. */ r->allowed = 0 - | (1 << M_GET) - | (1 << M_PUT) - | (1 << M_DELETE) - | (1 << M_OPTIONS) - | (1 << M_INVALID); + | (AP_METHOD_BIT << M_GET) + | (AP_METHOD_BIT << M_PUT) + | (AP_METHOD_BIT << M_DELETE) + | (AP_METHOD_BIT << M_OPTIONS) + | (AP_METHOD_BIT << M_INVALID); /* * These are the DAV methods we handle. */ r->allowed |= 0 - | (1 << M_COPY) - | (1 << M_LOCK) - | (1 << M_UNLOCK) - | (1 << M_MKCOL) - | (1 << M_MOVE) - | (1 << M_PROPFIND) - | (1 << M_PROPPATCH); + | (AP_METHOD_BIT << M_COPY) + | (AP_METHOD_BIT << M_LOCK) + | (AP_METHOD_BIT << M_UNLOCK) + | (AP_METHOD_BIT << M_MKCOL) + | (AP_METHOD_BIT << M_MOVE) + | (AP_METHOD_BIT << M_PROPFIND) + | (AP_METHOD_BIT << M_PROPPATCH); /* * These are methods that we don't handle directly, but let the * server's default handler do for us as our agent. */ r->allowed |= 0 - | (1 << M_POST); + | (AP_METHOD_BIT << M_POST); /* ### hrm. if we return HTTP_METHOD_NOT_ALLOWED, then an Allow header * ### is sent; it will need the other allowed states; since the default diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index a20daea4ee..ac71a5b9e2 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -2680,7 +2680,7 @@ static apr_status_t includes_filter(ap_filter_t *f, apr_bucket_brigade *b) if (!(ap_allow_options(r) & OPT_INCLUDES)) { return ap_pass_brigade(f->next, b); } - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) { return ap_pass_brigade(f->next, b); } diff --git a/modules/generators/mod_asis.c b/modules/generators/mod_asis.c index c5fcdc5042..346b435113 100644 --- a/modules/generators/mod_asis.c +++ b/modules/generators/mod_asis.c @@ -79,7 +79,7 @@ static int asis_handler(request_rec *r) if(strcmp(r->handler,ASIS_MAGIC_TYPE) && strcmp(r->handler,"send-as-is")) return DECLINED; - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) return DECLINED; if (r->finfo.filetype == 0) { diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index 80a3a66d7f..407ce555e7 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -1994,7 +1994,7 @@ static int handle_autoindex(request_rec *r) d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config, &autoindex_module); - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) { return DECLINED; } diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index 13fc514d0f..d54da1d95b 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -586,8 +586,8 @@ static int cgi_handler(request_rec *r) if (r->method_number == M_OPTIONS) { /* 99 out of 100 CGI scripts, this is all they support */ - r->allowed |= (1 << M_GET); - r->allowed |= (1 << M_POST); + r->allowed |= (AP_METHOD_BIT << M_GET); + r->allowed |= (AP_METHOD_BIT << M_POST); return DECLINED; } diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index 26946a9657..900a8f4ca5 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -857,8 +857,8 @@ static int cgid_handler(request_rec *r) if (r->method_number == M_OPTIONS) { /* 99 out of 100 cgid scripts, this is all they support */ - r->allowed |= (1 << M_GET); - r->allowed |= (1 << M_POST); + r->allowed |= (AP_METHOD_BIT << M_GET); + r->allowed |= (AP_METHOD_BIT << M_POST); return DECLINED; } diff --git a/modules/generators/mod_info.c b/modules/generators/mod_info.c index 3cf4ffdf5b..515dd84147 100644 --- a/modules/generators/mod_info.c +++ b/modules/generators/mod_info.c @@ -373,7 +373,7 @@ static int display_info(request_rec *r) if (strcmp(r->handler, "server-info")) return DECLINED; - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) return DECLINED; diff --git a/modules/generators/mod_status.c b/modules/generators/mod_status.c index b713ee3cb7..6681bc9d31 100644 --- a/modules/generators/mod_status.c +++ b/modules/generators/mod_status.c @@ -270,7 +270,7 @@ static int status_handler(request_rec *r) "Server status unavailable in inetd mode"); return HTTP_INTERNAL_SERVER_ERROR; } - r->allowed = (1 << M_GET); + r->allowed = (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) return DECLINED; diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index f178fa4eb3..1c00260783 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -328,7 +328,7 @@ AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p) apr_pool_cleanup_null); } -AP_DECLARE(int) ap_method_register(apr_pool_t *p, char *methname) +AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname) { int *newmethnum; @@ -985,23 +985,23 @@ static char *make_allow(request_rec *r) mask = r->allowed_methods->method_mask; list = apr_pstrcat(r->pool, - (mask & (1 << M_GET)) ? ", GET, HEAD" : "", - (mask & (1 << M_POST)) ? ", POST" : "", - (mask & (1 << M_PUT)) ? ", PUT" : "", - (mask & (1 << M_DELETE)) ? ", DELETE" : "", - (mask & (1 << M_CONNECT)) ? ", CONNECT" : "", - (mask & (1 << M_OPTIONS)) ? ", OPTIONS" : "", - (mask & (1 << M_PATCH)) ? ", PATCH" : "", - (mask & (1 << M_PROPFIND)) ? ", PROPFIND" : "", - (mask & (1 << M_PROPPATCH)) ? ", PROPPATCH" : "", - (mask & (1 << M_MKCOL)) ? ", MKCOL" : "", - (mask & (1 << M_COPY)) ? ", COPY" : "", - (mask & (1 << M_MOVE)) ? ", MOVE" : "", - (mask & (1 << M_LOCK)) ? ", LOCK" : "", - (mask & (1 << M_UNLOCK)) ? ", UNLOCK" : "", + (mask & (AP_METHOD_BIT << M_GET)) ? ", GET, HEAD" : "", + (mask & (AP_METHOD_BIT << M_POST)) ? ", POST" : "", + (mask & (AP_METHOD_BIT << M_PUT)) ? ", PUT" : "", + (mask & (AP_METHOD_BIT << M_DELETE)) ? ", DELETE" : "", + (mask & (AP_METHOD_BIT << M_CONNECT)) ? ", CONNECT" : "", + (mask & (AP_METHOD_BIT << M_OPTIONS)) ? ", OPTIONS" : "", + (mask & (AP_METHOD_BIT << M_PATCH)) ? ", PATCH" : "", + (mask & (AP_METHOD_BIT << M_PROPFIND)) ? ", PROPFIND" : "", + (mask & (AP_METHOD_BIT << M_PROPPATCH)) ? ", PROPPATCH" : "", + (mask & (AP_METHOD_BIT << M_MKCOL)) ? ", MKCOL" : "", + (mask & (AP_METHOD_BIT << M_COPY)) ? ", COPY" : "", + (mask & (AP_METHOD_BIT << M_MOVE)) ? ", MOVE" : "", + (mask & (AP_METHOD_BIT << M_LOCK)) ? ", LOCK" : "", + (mask & (AP_METHOD_BIT << M_UNLOCK)) ? ", UNLOCK" : "", ", TRACE", NULL); - if ((mask & (1 << M_INVALID)) + if ((mask & (AP_METHOD_BIT << M_INVALID)) && (r->allowed_methods->method_list != NULL) && (r->allowed_methods->method_list->nelts != 0)) { int i; @@ -2089,7 +2089,7 @@ AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method) */ methnum = ap_method_number_of(method); if (methnum != M_INVALID) { - return !!(l->method_mask & (1 << methnum)); + return !!(l->method_mask & (AP_METHOD_BIT << methnum)); } /* * Otherwise, see if the method name is in the array or string names @@ -2121,7 +2121,7 @@ AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method) * bitmask. */ methnum = ap_method_number_of(method); - l->method_mask |= (1 << methnum); + l->method_mask |= (AP_METHOD_BIT << methnum); if (methnum != M_INVALID) { return; } @@ -2154,7 +2154,7 @@ AP_DECLARE(void) ap_method_list_remove(ap_method_list_t *l, * by a module, use the bitmask. */ methnum = ap_method_number_of(method); - l->method_mask |= ~(1 << methnum); + l->method_mask |= ~(AP_METHOD_BIT << methnum); if (methnum != M_INVALID) { return; } diff --git a/modules/mappers/mod_actions.c b/modules/mappers/mod_actions.c index d6a31ddeb1..2eb411be34 100644 --- a/modules/mappers/mod_actions.c +++ b/modules/mappers/mod_actions.c @@ -172,7 +172,7 @@ static int action_handler(request_rec *r) /* Set allowed stuff */ for (i = 0; i < METHODS; ++i) { if (conf->scripted[i]) - r->allowed |= (1 << i); + r->allowed |= (AP_METHOD_BIT << i); } /* First, check for the method-handling scripts */ diff --git a/modules/test/mod_autoindex.c b/modules/test/mod_autoindex.c index f01365c043..7489164148 100644 --- a/modules/test/mod_autoindex.c +++ b/modules/test/mod_autoindex.c @@ -1670,7 +1670,7 @@ static int handle_autoindex(request_rec *r) d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config, &autoindex_module); - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) { return DECLINED; } diff --git a/modules/test/mod_rndchunk.c b/modules/test/mod_rndchunk.c index 6eeae175ac..c987a48a57 100644 --- a/modules/test/mod_rndchunk.c +++ b/modules/test/mod_rndchunk.c @@ -100,7 +100,7 @@ static int send_rndchunk(request_rec *r) char buf[MAX_SEGMENT + 1]; unsigned int len; - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) return DECLINED; diff --git a/modules/test/mod_test_util_uri.c b/modules/test/mod_test_util_uri.c index 3baae44bbd..ad76be0855 100644 --- a/modules/test/mod_test_util_uri.c +++ b/modules/test/mod_test_util_uri.c @@ -265,7 +265,7 @@ static int test_util_uri(request_rec *r) unsigned total_failures; int i; - r->allowed |= (1 << M_GET); + r->allowed |= (AP_METHOD_BIT << M_GET); if (r->method_number != M_GET) return DECLINED; diff --git a/server/config.c b/server/config.c index a8f1f26b5e..9d2850dd7e 100644 --- a/server/config.c +++ b/server/config.c @@ -362,7 +362,7 @@ AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method) { * added by a module and registered. */ if (methnum != M_INVALID) { - return !!(cmd->limited & (1<limited & (AP_METHOD_BIT << methnum)); } return 0; /* not found */ diff --git a/server/core.c b/server/core.c index f85f8834ad..e0bff5f285 100644 --- a/server/core.c +++ b/server/core.c @@ -1490,7 +1490,7 @@ AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dumm */ methnum = ap_method_register(cmd->pool, method); } - limited |= (1 << methnum); + limited |= (AP_METHOD_BIT << methnum); } /* Killing two features with one function, diff --git a/server/request.c b/server/request.c index fee0eff300..a7e67d194d 100644 --- a/server/request.c +++ b/server/request.c @@ -1280,7 +1280,7 @@ AP_DECLARE(int) ap_some_auth_required(request_rec *r) reqs = (require_line *) reqs_arr->elts; for (i = 0; i < reqs_arr->nelts; ++i) - if (reqs[i].method_mask & (1 << r->method_number)) + if (reqs[i].method_mask & (AP_METHOD_BIT << r->method_number)) return 1; return 0; -- 2.50.1