Skip to content

Commit c642248

Browse files
mmuehlenhoffmuehlenhoffMoritz Muehlenhoffdhawes
authored
Replace bespoke cookie parsing with ap_cookie_read() (#202)
* Replace bespoke cookie parsing with ap_cookie_read() * Fix escaping for small chars in urlEncode() The %%%x format string resolves to the literal "%" and the hex representation of the character to be encoded, but is always asssumed to return three characters. However for a small value like e.g. 7 it would return "%7" instead. None of the current two call sites of the function use such a small value, but apply correct padding just in case the function might be used elsewhere in the future. * Update src/mod_auth_cas.c Co-authored-by: David Hawes <[email protected]> * Update docs to require Apache 2.4 The upstream support for Apache 2.2.x ended on 2018-01-01 and also none of the long term Linux distros still support it, looking at the latest still supported releases: * Debian 8 ELTS has Apache httpd 2.4.10 * Ubuntu 14.4 has Apache httpd 2.4.5 * RHEL 7 has Apache httpd 2.4.6 * SLES 11 has Apache httpd 2.4.23 Co-authored-by: Moritz Muehlenhoff <[email protected]> Co-authored-by: Moritz Muehlenhoff <[email protected]> Co-authored-by: David Hawes <[email protected]>
1 parent de41363 commit c642248

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The following development libraries and utilities must be installed:
4747
* OpenSSL - 0.9.8c or higher
4848
* Apache Portable Runtime - 1.5.0 or higher
4949
* Apache Portable Runtime Utilities - 1.3.0 or higher
50-
* Apache Web Server - 2.2.3 or higher
50+
* Apache Web Server - 2.4 or higher
5151
* libcurl - 7.18.2 or higher
5252
* libpcre - 7.8 or higher
5353

src/mod_auth_cas.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "apr_thread_mutex.h"
5454
#include "apr_strings.h"
5555
#include "apr_xml.h"
56+
#include "util_cookies.h"
5657

5758
#include "cas_saml_attr.h"
5859

@@ -780,27 +781,9 @@ char *getCASTicket(request_rec *r)
780781

781782
char *getCASCookie(request_rec *r, char *cookieName)
782783
{
783-
char *cookie, *tokenizerCtx, *rv = NULL;
784-
char *cookies = apr_pstrdup(r->pool, (char *) apr_table_get(r->headers_in, "Cookie"));
785-
786-
if(cookies != NULL) {
787-
/* tokenize on ; to find the cookie we want */
788-
cookie = apr_strtok(cookies, ";", &tokenizerCtx);
789-
while (cookie != NULL) {
790-
while (*cookie == ' ') {
791-
cookie++;
792-
}
793-
if (strncmp(cookie, cookieName, strlen(cookieName)) == 0) {
794-
/* skip to the meat of the parameter (the value after the '=') */
795-
cookie += (strlen(cookieName)+1);
796-
rv = apr_pstrdup(r->pool, cookie);
797-
break;
798-
}
799-
cookie = apr_strtok(NULL, ";", &tokenizerCtx);
800-
}
801-
}
802-
803-
return rv;
784+
const char *rv = NULL;
785+
ap_cookie_read(r, cookieName, &rv, 0);
786+
return(apr_pstrdup(r->pool, rv));
804787
}
805788

806789
void setCASCookie(request_rec *r, char *cookieName, char *cookieValue, apr_byte_t secure, apr_time_t expireTime, char *cookieDomain, char *cookieSameSite)
@@ -916,7 +899,7 @@ char *urlEncode(const request_rec *r, const char *str,
916899
escaped = FALSE;
917900
for(i = 0; i < limit; i++) {
918901
if(*q == charsToEncode[i]) {
919-
sprintf(p, "%%%x", charsToEncode[i]);
902+
sprintf(p, "%%%02x", charsToEncode[i]);
920903
p+= 3;
921904
escaped = TRUE;
922905
break;

0 commit comments

Comments
 (0)