From 3df1676b3c71b581fd5ba4c73c8c8911cde0aba9 Mon Sep 17 00:00:00 2001 From: Greg Ames Date: Mon, 26 Feb 2001 22:07:00 +0000 Subject: [PATCH] insure that canned error msgs are translated to ascii before leaving an ebcdic server in worst case scenarios. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88361 13f79535-47bb-0310-9956-ffa450edef68 --- include/util_ebcdic.h | 10 ++++++++++ modules/http/http_protocol.c | 16 +++++++++++----- server/util_ebcdic.c | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/include/util_ebcdic.h b/include/util_ebcdic.h index 7cc01941d4..6dae00b4ed 100644 --- a/include/util_ebcdic.h +++ b/include/util_ebcdic.h @@ -96,6 +96,14 @@ void ap_xlate_proto_to_ascii(char *buffer, apr_size_t len); */ void ap_xlate_proto_from_ascii(char *buffer, apr_size_t len); +/** + * Convert protocol data from the implementation charater + * set to ASCII, then send it. + * @param r the current request + * @param ... the strings to write, followed by a NULL pointer + */ +int ap_rvputs_proto_in_ascii(request_rec *r, ...); + #ifdef __cplusplus } #endif @@ -105,6 +113,8 @@ void ap_xlate_proto_from_ascii(char *buffer, apr_size_t len); #define ap_xlate_proto_to_ascii(x,y) /* NOOP */ #define ap_xlate_proto_from_ascii(x,y) /* NOOP */ +#define ap_rvputs_proto_in_ascii ap_rvputs + #endif /* APR_CHARSET_EBCDIC */ #endif /* !APACHE_UTIL_EBCDIC_H */ diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 4d06da3c96..c678eb743e 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -2043,22 +2043,28 @@ AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error) /* folks decided they didn't want the error code in the H1 text */ h1 = &title[4]; - ap_rvputs(rlast, + /* can't count on a charset filter being in place here, + * so do ebcdic->ascii translation explicity (if needed) + */ + + ap_rvputs_proto_in_ascii(rlast, DOCTYPE_HTML_2_0 "\n", title, "\n\n

", h1, "

\n", NULL); - ap_rputs(get_canned_error_string(status, r, location),rlast); + ap_rvputs_proto_in_ascii(rlast, + get_canned_error_string(status, r, location), + NULL); if (recursive_error) { - ap_rvputs(rlast, "

Additionally, a ", + ap_rvputs_proto_in_ascii(rlast, "

Additionally, a ", status_lines[ap_index_of_response(recursive_error)], "\nerror was encountered while trying to use an " "ErrorDocument to handle the request.\n", NULL); } - ap_rputs(ap_psignature("


\n", r), rlast); - ap_rputs("\n", rlast); + ap_rvputs_proto_in_ascii(rlast, ap_psignature("
\n", r), NULL); + ap_rvputs_proto_in_ascii(rlast, "\n", NULL); } ap_finalize_request_protocol(r); } diff --git a/server/util_ebcdic.c b/server/util_ebcdic.c index 447ba6ef83..75a1b7dd3d 100644 --- a/server/util_ebcdic.c +++ b/server/util_ebcdic.c @@ -141,4 +141,28 @@ void ap_xlate_proto_from_ascii(char *buffer, apr_size_t len) buffer, &outbytes_left); } +int ap_rvputs_proto_in_ascii(request_rec *r, ...) +{ + va_list va; + const char *s; + char *ascii_s; + apr_size_t len; + apr_size_t written = 0; + + va_start(va, r); + while (1) { + s = va_arg(va, const char *); + if (s == NULL) + break; + len = strlen(s); + ascii_s = apr_pstrndup(r->pool, s, len); + ap_xlate_proto_to_ascii(ascii_s, len); + if (ap_rputs(ascii_s, r) < 0) + return -1; + written += len; + } + va_end(va); + + return written; +} #endif /* APR_CHARSET_EBCDIC */ -- 2.50.0