From e47fdeb4203ef5a187855992519951b1b8d67a5f Mon Sep 17 00:00:00 2001 From: brectanus Date: Mon, 26 Nov 2007 22:53:51 +0000 Subject: [PATCH] Changed %p formatter to APRs %pp (wish that was documented). Marked msr_log() as a printf style function so GNU compiler can check formatting types. Fixed a few other warnings with msr_log() formatters. --- apache2/apache2.h | 2 +- apache2/apache2_io.c | 6 +++--- apache2/apache2_util.c | 2 +- apache2/mod_security2.c | 12 ++++++------ apache2/modsecurity.h | 5 +++++ apache2/msc_geo.c | 2 +- apache2/msc_logging.c | 4 ++-- apache2/msc_multipart.c | 4 ++-- apache2/msc_reqbody.c | 2 +- apache2/re.c | 4 ++-- 10 files changed, 24 insertions(+), 19 deletions(-) diff --git a/apache2/apache2.h b/apache2/apache2.h index e9157a81..cb96bb35 100644 --- a/apache2/apache2.h +++ b/apache2/apache2.h @@ -82,7 +82,7 @@ char DSOLOCAL *get_env_var(request_rec *r, char *name); void DSOLOCAL internal_log(request_rec *r, directory_config *dcfg, modsec_rec *msr, int level, const char *text, va_list ap); -void DSOLOCAL msr_log(modsec_rec *msr, int level, const char *text, ...); +void DSOLOCAL msr_log(modsec_rec *msr, int level, const char *text, ...) PRINTF_ATTRIBUTE(3,4); char DSOLOCAL *format_error_log_message(apr_pool_t *mp, error_message *em); diff --git a/apache2/apache2_io.c b/apache2/apache2_io.c index 7c773210..d7c68791 100644 --- a/apache2/apache2_io.c +++ b/apache2/apache2_io.c @@ -48,7 +48,7 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out, if ((msr->if_status == IF_STATUS_COMPLETE)||(msr->if_status == IF_STATUS_NONE)) { if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Input filter: Input forwarding already complete, skipping (f %p, r %p).", f, f->r); + msr_log(msr, 4, "Input filter: Input forwarding already complete, skipping (f %pp, r %pp).", f, f->r); } ap_remove_input_filter(f); return ap_get_brigade(f->next, bb_out, mode, block, nbytes); @@ -56,7 +56,7 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out, if (msr->txcfg->debuglog_level >= 4) { msr_log(msr, 4, "Input filter: Forwarding input: mode=%d, block=%d, nbytes=%" APR_OFF_T_FMT - " (f %p, r %p).", mode, block, nbytes, f, f->r); + " (f %pp, r %pp).", mode, block, nbytes, f, f->r); } if (msr->if_started_forwarding == 0) { @@ -483,7 +483,7 @@ apr_status_t output_filter(ap_filter_t *f, apr_bucket_brigade *bb_in) { msr->r = r; if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Output filter: Receiving output (f %p, r %p).", f, f->r); + msr_log(msr, 4, "Output filter: Receiving output (f %pp, r %pp).", f, f->r); } /* Initialise on first invocation */ diff --git a/apache2/apache2_util.c b/apache2/apache2_util.c index 11a65014..072f39c9 100644 --- a/apache2/apache2_util.c +++ b/apache2/apache2_util.c @@ -246,7 +246,7 @@ void internal_log(request_rec *r, directory_config *dcfg, modsec_rec *msr, /* Construct the message. */ apr_vsnprintf(str1, sizeof(str1), text, ap); - apr_snprintf(str2, sizeof(str2), "[%s] [%s/sid#%p][rid#%p][%s][%d] %s\n", + apr_snprintf(str2, sizeof(str2), "[%s] [%s/sid#%pp][rid#%pp][%s][%d] %s\n", current_logtime(msr->mp), ap_get_server_name(r), (r->server), r, ((r->uri == NULL) ? "" : log_escape_nq(msr->mp, r->uri)), level, str1); diff --git a/apache2/mod_security2.c b/apache2/mod_security2.c index a82685e6..1553c962 100644 --- a/apache2/mod_security2.c +++ b/apache2/mod_security2.c @@ -348,7 +348,7 @@ static modsec_rec *create_tx_context(request_rec *r) { store_tx_context(msr, r); if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Transaction context created (dcfg %p).", msr->dcfg1); + msr_log(msr, 4, "Transaction context created (dcfg %pp).", msr->dcfg1); } return msr; @@ -629,7 +629,7 @@ static int hook_request_late(request_rec *r) { } if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Second phase starting (dcfg %p).", msr->dcfg2); + msr_log(msr, 4, "Second phase starting (dcfg %pp).", msr->dcfg2); } /* Figure out whether or not to extract multipart files. */ @@ -899,7 +899,7 @@ static void hook_insert_filter(request_rec *r) { /* Add the input filter, but only if we need it to run. */ if (msr->if_status == IF_STATUS_WANTS_TO_RUN) { if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Hook insert_filter: Adding input forwarding filter %s(r %p).", (((r->main != NULL)||(r->prev != NULL)) ? "for subrequest " : ""), r); + msr_log(msr, 4, "Hook insert_filter: Adding input forwarding filter %s(r %pp).", (((r->main != NULL)||(r->prev != NULL)) ? "for subrequest " : ""), r); } ap_add_input_filter("MODSECURITY_IN", msr, r, r->connection); @@ -914,7 +914,7 @@ static void hook_insert_filter(request_rec *r) { /* We always add the PDF XSS protection filter. */ if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Hook insert_filter: Adding PDF XSS protection output filter (r %p).", r); + msr_log(msr, 4, "Hook insert_filter: Adding PDF XSS protection output filter (r %pp).", r); } ap_add_output_filter("PDFP_OUT", msr, r, r->connection); @@ -934,7 +934,7 @@ static void hook_insert_filter(request_rec *r) { */ if (msr->of_status != OF_STATUS_COMPLETE) { if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Hook insert_filter: Adding output filter (r %p).", r); + msr_log(msr, 4, "Hook insert_filter: Adding output filter (r %pp).", r); } ap_add_output_filter("MODSECURITY_OUT", msr, r, r->connection); @@ -967,7 +967,7 @@ static void hook_insert_error_filter(request_rec *r) { */ if (msr->of_status != OF_STATUS_COMPLETE) { if (msr->txcfg->debuglog_level >= 4) { - msr_log(msr, 4, "Hook insert_error_filter: Adding output filter (r %p).", r); + msr_log(msr, 4, "Hook insert_error_filter: Adding output filter (r %pp).", r); } /* Make a note that the output we will be receiving is a diff --git a/apache2/modsecurity.h b/apache2/modsecurity.h index 91ceb486..8ff1ac55 100644 --- a/apache2/modsecurity.h +++ b/apache2/modsecurity.h @@ -30,6 +30,11 @@ typedef struct msc_string msc_string; #define DSOLOCAL #endif +/* For GNU C, tell the compiler to check printf like formatters */ +#if defined(__GNUC__) +#define PRINTF_ATTRIBUTE(a,b) __attribute__((format (printf, a, b))) +#endif + #include "msc_logging.h" #include "msc_multipart.h" #include "msc_pcre.h" diff --git a/apache2/msc_geo.c b/apache2/msc_geo.c index 6693f05d..a2e9c5e4 100644 --- a/apache2/msc_geo.c +++ b/apache2/msc_geo.c @@ -316,7 +316,7 @@ int geo_lookup(modsec_rec *msr, geo_rec *georec, const char *target, char **erro /* Why is this in host byte order? */ ipnum = ntohl(addr->sa.sin.sin_addr.s_addr); - msr_log(msr, 9, "GEO: Using address \"%s\" (0x%08x).", targetip, ipnum); + msr_log(msr, 9, "GEO: Using address \"%s\" (0x%08lx).", targetip, ipnum); for (level = 31; level >= 0; level--) { diff --git a/apache2/msc_logging.c b/apache2/msc_logging.c index 3f79c2e0..aeee51c0 100644 --- a/apache2/msc_logging.c +++ b/apache2/msc_logging.c @@ -921,14 +921,14 @@ void sec_audit_logger(modsec_rec *msr) { nbytes = strlen(text); if (msr->txcfg->debuglog_level >= 9) { - msr_log(msr, 9, "Audit Log: Writing %d bytes to primary concurrent index", nbytes); + msr_log(msr, 9, "Audit Log: Writing %" APR_SIZE_T_FMT " bytes to primary concurrent index", nbytes); } apr_file_write_full(msr->txcfg->auditlog_fd, text, nbytes, &nbytes_written); /* Write to the secondary audit log if we have one */ if (msr->txcfg->auditlog2_fd != NULL) { if (msr->txcfg->debuglog_level >= 9) { - msr_log(msr, 9, "Audit Log: Writing %d bytes to secondary concurrent index", nbytes); + msr_log(msr, 9, "Audit Log: Writing %" APR_SIZE_T_FMT " bytes to secondary concurrent index", nbytes); } apr_file_write_full(msr->txcfg->auditlog2_fd, text, nbytes, &nbytes_written); } diff --git a/apache2/msc_multipart.c b/apache2/msc_multipart.c index 22dfddea..ba8bd5e3 100644 --- a/apache2/msc_multipart.c +++ b/apache2/msc_multipart.c @@ -520,7 +520,7 @@ static int multipart_process_boundary(modsec_rec *msr, int last_part, char **err *(multipart_part **)apr_array_push(msr->mpd->parts) = msr->mpd->mpp; if (msr->mpd->mpp->type == MULTIPART_FILE) { if (msr->txcfg->debuglog_level >= 9) { - msr_log(msr, 9, "Multipart: Added file part %p to the list: name \"%s\" " + msr_log(msr, 9, "Multipart: Added file part %pp to the list: name \"%s\" " "file name \"%s\" (offset %u, length %u)", msr->mpd->mpp, log_escape(msr->mp, msr->mpd->mpp->name), log_escape(msr->mp, msr->mpd->mpp->filename), @@ -529,7 +529,7 @@ static int multipart_process_boundary(modsec_rec *msr, int last_part, char **err } else { if (msr->txcfg->debuglog_level >= 9) { - msr_log(msr, 9, "Multipart: Added part %p to the list: name \"%s\" " + msr_log(msr, 9, "Multipart: Added part %pp to the list: name \"%s\" " "(offset %u, length %u)", msr->mpd->mpp, log_escape(msr->mp, msr->mpd->mpp->name), msr->mpd->mpp->offset, msr->mpd->mpp->length); } diff --git a/apache2/msc_reqbody.c b/apache2/msc_reqbody.c index 2ef6d9ea..19db695a 100644 --- a/apache2/msc_reqbody.c +++ b/apache2/msc_reqbody.c @@ -170,7 +170,7 @@ static apr_status_t modsecurity_request_body_store_memory(modsec_rec *msr, msr->msc_reqbody_chunks = NULL; apr_pool_clear(msr->msc_reqbody_mp); - msr_log(msr, 4, "Input filter: Wrote %" APR_SIZE_T_FMT " bytes from memory to disk.", disklen); + msr_log(msr, 4, "Input filter: Wrote %u bytes from memory to disk.", disklen); /* Continue with disk storage from now on */ return modsecurity_request_body_store_disk(msr, data, length, error_msg); diff --git a/apache2/re.c b/apache2/re.c index 82a802f0..1f5d60e0 100644 --- a/apache2/re.c +++ b/apache2/re.c @@ -782,7 +782,7 @@ apr_status_t msre_ruleset_process_phase(msre_ruleset *ruleset, modsec_rec *msr) if (rule->actionset != NULL && rule->actionset->rev != NULL) { rev = apr_psprintf(p, " [rev \"%s\"]", rule->actionset->rev); } - msr_log(msr, 4, "Recipe: Invoking rule %p;%s%s%s.", + msr_log(msr, 4, "Recipe: Invoking rule %pp;%s%s%s.", rule, (fn ? fn : ""), (id ? id : ""), (rev ? rev : "")); } @@ -935,7 +935,7 @@ apr_status_t msre_ruleset_process_phase(msre_ruleset *ruleset, modsec_rec *msr) rules = (msre_rule **)arr->elts; for (i = 0; i < arr->nelts; i++) { msre_rule *rule = rules[i]; - msr_log(msr, 1, "Rule %p [id \"%s\"][file \"%s\"][line \"%d\"]: %lu usec", rule, + msr_log(msr, 1, "Rule %pp [id \"%s\"][file \"%s\"][line \"%d\"]: %lu usec", rule, ((rule->actionset != NULL)&&(rule->actionset->id != NULL)) ? rule->actionset->id : "-", rule->filename != NULL ? rule->filename : "-", rule->line_num,