From: William A. Rowe Jr Date: Fri, 6 Jan 2012 18:15:28 +0000 (+0000) Subject: Clean up size_t abuse, part 2. ap_malloc/calloc/realloc are explicitly X-Git-Tag: 2.4.0~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=678bbff9f4e015854bdd85d2daaddd5e5db1f691;p=apache Clean up size_t abuse, part 2. ap_malloc/calloc/realloc are explicitly excluded from this cleanup as they must be signature identical to the clib functions, and although the definition of size_t has been flakey, the definition of those functions appears to be generally clean since ANSI C. Backports: r1228323 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1228324 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/http_config.h b/include/http_config.h index 40f0721443..30ec368594 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -260,7 +260,7 @@ struct ap_configfile_t { /**< an apr_file_getc()-like function */ apr_status_t (*getch) (char *ch, void *param); /**< an apr_file_gets()-like function */ - apr_status_t (*getstr) (void *buf, size_t bufsiz, void *param); + apr_status_t (*getstr) (void *buf, apr_size_t bufsiz, void *param); /**< a close handler function */ apr_status_t (*close) (void *param); /**< the argument passed to getch/getstr/close */ @@ -773,7 +773,7 @@ AP_DECLARE(ap_configfile_t *) ap_pcfg_open_custom(apr_pool_t *p, const char *descr, void *param, apr_status_t (*getc_func) (char *ch, void *param), - apr_status_t (*gets_func) (void *buf, size_t bufsiz, void *param), + apr_status_t (*gets_func) (void *buf, apr_size_t bufsiz, void *param), apr_status_t (*close_func) (void *param)); /** @@ -784,7 +784,7 @@ AP_DECLARE(ap_configfile_t *) ap_pcfg_open_custom(apr_pool_t *p, * @param cfp File to read from * @return error status, APR_ENOSPC if bufsize is too small for the line */ -AP_DECLARE(apr_status_t) ap_cfg_getline(char *buf, size_t bufsize, ap_configfile_t *cfp); +AP_DECLARE(apr_status_t) ap_cfg_getline(char *buf, apr_size_t bufsize, ap_configfile_t *cfp); /** * Read one char from open configfile_t, increase line number upon LF diff --git a/include/http_core.h b/include/http_core.h index 12a29e4279..81b36c7507 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -239,7 +239,7 @@ AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r); * @param r The current request * @return the maximum number of bytes in XML request msg body */ -AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r); +AP_DECLARE(apr_size_t) ap_get_limit_xml_body(const request_rec *r); /** * Install a custom response handler for a given status diff --git a/include/http_protocol.h b/include/http_protocol.h index 77493de586..377b8f1248 100644 --- a/include/http_protocol.h +++ b/include/http_protocol.h @@ -209,8 +209,10 @@ AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t of * @param length The amount of data to send * @return The number of bytes sent */ -AP_DECLARE(size_t) ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset, - size_t length); +AP_DECLARE(apr_size_t) ap_send_mmap(apr_mmap_t *mm, + request_rec *r, + apr_size_t offset, + apr_size_t length); #endif diff --git a/include/httpd.h b/include/httpd.h index 71b4c0dcf7..987d2978fe 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -1802,8 +1802,9 @@ AP_DECLARE(void) ap_pregfree(apr_pool_t *p, ap_regex_t *reg); * @param pmatch the pmatch array returned from ap_pregex * @return The substituted string, or NULL on error */ -AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, const char *source, - size_t nmatch, ap_regmatch_t pmatch[]); +AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, + const char *source, apr_size_t nmatch, + ap_regmatch_t pmatch[]); /** * After performing a successful regex match, you may use this function to @@ -1821,7 +1822,8 @@ AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, const char *sour */ AP_DECLARE(apr_status_t) ap_pregsub_ex(apr_pool_t *p, char **result, const char *input, const char *source, - size_t nmatch, ap_regmatch_t pmatch[], + apr_size_t nmatch, + ap_regmatch_t pmatch[], apr_size_t maxlen); /** diff --git a/include/util_varbuf.h b/include/util_varbuf.h index db737d4fb8..696284620b 100644 --- a/include/util_varbuf.h +++ b/include/util_varbuf.h @@ -143,7 +143,8 @@ AP_DECLARE(char *) ap_varbuf_pdup(apr_pool_t *p, struct ap_varbuf *vb, */ AP_DECLARE(apr_status_t) ap_varbuf_regsub(struct ap_varbuf *vb, const char *input, - const char *source, size_t nmatch, + const char *source, + apr_size_t nmatch, ap_regmatch_t pmatch[], apr_size_t maxlen); diff --git a/server/config.c b/server/config.c index 8c56308b9a..409ca0695a 100644 --- a/server/config.c +++ b/server/config.c @@ -1648,7 +1648,7 @@ typedef struct { /* arr_elts_getstr() returns the next line from the string array. */ -static apr_status_t arr_elts_getstr(void *buf, size_t bufsiz, void *param) +static apr_status_t arr_elts_getstr(void *buf, apr_size_t bufsiz, void *param) { arr_elts_param_t *arr_param = (arr_elts_param_t *)param; char *elt; diff --git a/server/core.c b/server/core.c index c4ad3ff44a..f0a29dd5d4 100644 --- a/server/core.c +++ b/server/core.c @@ -64,7 +64,7 @@ /* LimitXMLRequestBody handling */ #define AP_LIMIT_UNSET ((long) -1) -#define AP_DEFAULT_LIMIT_XML_BODY ((size_t)1000000) +#define AP_DEFAULT_LIMIT_XML_BODY ((apr_size_t)1000000) #define AP_MIN_SENDFILE_BYTES (256) @@ -3347,7 +3347,7 @@ static const char *set_max_reversals(cmd_parms *cmd, void *conf_, const char *ar return NULL; } -AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r) +AP_DECLARE(apr_size_t) ap_get_limit_xml_body(const request_rec *r) { core_dir_config *conf; @@ -3355,7 +3355,7 @@ AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r) if (conf->limit_xml_body == AP_LIMIT_UNSET) return AP_DEFAULT_LIMIT_XML_BODY; - return (size_t)conf->limit_xml_body; + return (apr_size_t)conf->limit_xml_body; } #if !defined (RLIMIT_CPU) || !(defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)) || !defined (RLIMIT_NPROC) diff --git a/server/protocol.c b/server/protocol.c index 733cdaacf3..5a9135c8b2 100644 --- a/server/protocol.c +++ b/server/protocol.c @@ -1465,8 +1465,10 @@ AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, #if APR_HAS_MMAP /* send data from an in-memory buffer */ -AP_DECLARE(size_t) ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset, - size_t length) +AP_DECLARE(apr_size_t) ap_send_mmap(apr_mmap_t *mm, + request_rec *r, + apr_size_t offset, + apr_size_t length) { conn_rec *c = r->connection; apr_bucket_brigade *bb = NULL; diff --git a/server/request.c b/server/request.c index bb2a054de3..37cffdde04 100644 --- a/server/request.c +++ b/server/request.c @@ -1033,7 +1033,7 @@ AP_DECLARE(int) ap_directory_walk(request_rec *r) seg_name = r->filename + filename_len; delim = strchr(r->path_info + (*r->path_info == '/' ? 1 : 0), '/'); if (delim) { - size_t path_info_len = delim - r->path_info; + apr_size_t path_info_len = delim - r->path_info; *delim = '\0'; memcpy(seg_name, r->path_info, path_info_len + 1); filename_len += path_info_len; @@ -1041,7 +1041,7 @@ AP_DECLARE(int) ap_directory_walk(request_rec *r) *delim = '/'; } else { - size_t path_info_len = strlen(r->path_info); + apr_size_t path_info_len = strlen(r->path_info); memcpy(seg_name, r->path_info, path_info_len + 1); filename_len += path_info_len; r->path_info += path_info_len; diff --git a/server/util.c b/server/util.c index 9ff8e39487..3c38fa9008 100644 --- a/server/util.c +++ b/server/util.c @@ -372,13 +372,13 @@ AP_DECLARE(const char *) ap_stripprefix(const char *bigstring, static apr_status_t regsub_core(apr_pool_t *p, char **result, struct ap_varbuf *vb, const char *input, - const char *source, size_t nmatch, + const char *source, apr_size_t nmatch, ap_regmatch_t pmatch[], apr_size_t maxlen) { const char *src = input; char *dst; char c; - size_t no; + apr_size_t no; apr_size_t len = 0; AP_DEBUG_ASSERT((result && p && !vb) || (vb && !p && !result)); @@ -465,7 +465,7 @@ static apr_status_t regsub_core(apr_pool_t *p, char **result, #define AP_PREGSUB_MAXLEN (HUGE_STRING_LEN * 8) #endif AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, - const char *source, size_t nmatch, + const char *source, apr_size_t nmatch, ap_regmatch_t pmatch[]) { char *result; @@ -478,7 +478,7 @@ AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, AP_DECLARE(apr_status_t) ap_pregsub_ex(apr_pool_t *p, char **result, const char *input, const char *source, - size_t nmatch, ap_regmatch_t pmatch[], + apr_size_t nmatch, ap_regmatch_t pmatch[], apr_size_t maxlen) { apr_status_t rc = regsub_core(p, result, NULL, input, source, nmatch, @@ -725,7 +725,7 @@ AP_DECLARE(char *) ap_getword_nulls(apr_pool_t *atrans, const char **line, char *res; if (!pos) { - size_t len = strlen(*line); + apr_size_t len = strlen(*line); res = apr_pstrmemdup(atrans, *line, len); *line += len; return res; @@ -836,7 +836,7 @@ static apr_status_t cfg_getch(char *ch, void *param) return apr_file_getc(ch, param); } -static apr_status_t cfg_getstr(void *buf, size_t bufsiz, void *param) +static apr_status_t cfg_getstr(void *buf, apr_size_t bufsiz, void *param) { return apr_file_gets(buf, bufsiz, param); } @@ -926,7 +926,7 @@ AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg, AP_DECLARE(ap_configfile_t *) ap_pcfg_open_custom( apr_pool_t *p, const char *descr, void *param, apr_status_t (*getc_func) (char *ch, void *param), - apr_status_t (*gets_func) (void *buf, size_t bufsize, void *param), + apr_status_t (*gets_func) (void *buf, apr_size_t bufsize, void *param), apr_status_t (*close_func) (void *param)) { ap_configfile_t *new_cfg = apr_palloc(p, sizeof(*new_cfg)); @@ -962,7 +962,7 @@ AP_DECLARE(const char *) ap_pcfg_strerror(apr_pool_t *p, ap_configfile_t *cfp, /* Read one line from open ap_configfile_t, strip LF, increase line number */ /* If custom handler does not define a getstr() function, read char by char */ -static apr_status_t ap_cfg_getline_core(char *buf, size_t bufsize, +static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize, ap_configfile_t *cfp) { apr_status_t rc; @@ -970,7 +970,7 @@ static apr_status_t ap_cfg_getline_core(char *buf, size_t bufsize, if (cfp->getstr != NULL) { char *cp; char *cbuf = buf; - size_t cbufsize = bufsize; + apr_size_t cbufsize = bufsize; while (1) { ++cfp->line_number; @@ -1016,7 +1016,7 @@ static apr_status_t ap_cfg_getline_core(char *buf, size_t bufsize, } } else { /* No "get string" function defined; read character by character */ - size_t i = 0; + apr_size_t i = 0; if (bufsize < 2) { /* too small, assume caller is crazy */ @@ -1081,7 +1081,8 @@ static int cfg_trim_line(char *buf) /* Read one line from open ap_configfile_t, strip LF, increase line number */ /* If custom handler does not define a getstr() function, read char by char */ -AP_DECLARE(apr_status_t) ap_cfg_getline(char *buf, size_t bufsize, ap_configfile_t *cfp) +AP_DECLARE(apr_status_t) ap_cfg_getline(char *buf, apr_size_t bufsize, + ap_configfile_t *cfp) { apr_status_t rc = ap_cfg_getline_core(buf, bufsize, cfp); if (rc == APR_SUCCESS) @@ -2723,7 +2724,8 @@ AP_DECLARE(char *) ap_varbuf_pdup(apr_pool_t *p, struct ap_varbuf *buf, AP_DECLARE(apr_status_t) ap_varbuf_regsub(struct ap_varbuf *vb, const char *input, - const char *source, size_t nmatch, + const char *source, + apr_size_t nmatch, ap_regmatch_t pmatch[], apr_size_t maxlen) { diff --git a/server/util_cookies.c b/server/util_cookies.c index dc8c457b77..5139aecd4c 100644 --- a/server/util_cookies.c +++ b/server/util_cookies.c @@ -179,7 +179,7 @@ static int extract_cookie_line(ap_cookie_do * v, const char *key, const char *va char *last1, *last2; char *cookie = apr_pstrdup(v->r->pool, val); const char *name = apr_pstrcat(v->r->pool, v->name ? v->name : "", "=", NULL); - size_t len = strlen(name); + apr_size_t len = strlen(name); const char *new_cookie = ""; const char *comma = ","; char *next1;