Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai
sso
Commits
7f8c4640
Commit
7f8c4640
authored
Sep 13, 2015
by
ale
Browse files
alternate implementation of get_cookie that does not leak memory forever
parent
4f9671df
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/mod_sso/mod_sso.c
View file @
7f8c4640
...
...
@@ -254,25 +254,28 @@ static int is_valid_redir(request_rec *r,
* @return the cookie value, or an empty string if no cookie was found.
*/
static
char
*
get_cookie
(
request_rec
*
r
,
const
char
*
cookie_name
)
{
char
*
cookie_value
=
NULL
,
*
strptr
=
NULL
,
*
token
;
const
char
*
cookies_c
=
apr_table_get
(
r
->
headers_in
,
"Cookie"
);
char
*
rv
=
NULL
,
*
cookie
,
*
tokenizerCtx
=
NULL
;
int
cookie_name_len
;
// How do we know this is writable? TODO: make a copy.
char
*
cookies_c
=
(
char
*
)
apr_table_get
(
r
->
headers_in
,
"Cookie"
);
if
(
cookies_c
==
NULL
)
{
return
cookie_value
;
return
NULL
;
}
while
((
token
=
strtok_r
(
apr_pstrdup
(
r
->
pool
,
cookies_c
),
";"
,
&
strptr
))
!=
NULL
)
{
c
har
*
sep
=
strchr
(
token
,
'='
);
if
(
!
sep
)
{
continue
;
}
*
sep
++
=
'\0'
;
if
(
!
strcmp
(
token
,
cookie_name
))
{
cookie_value
=
sep
;
cookie_name_len
=
strlen
(
cookie_name
);
c
ookie
=
apr_strtok
(
cookies_c
,
";"
,
&
tokenizerCtx
);
do
{
while
(
cookie
!=
NULL
&&
*
cookie
==
' '
)
cookie
++
;
if
(
strncmp
(
cookie
,
cookie_name
,
cookie_name_len
)
==
0
)
{
cookie
+=
(
cookie_name
_len
+
1
);
rv
=
apr_pstrdup
(
r
->
pool
,
cookie
)
;
break
;
}
}
return
cookie_value
;
cookie
=
apr_strtok
(
NULL
,
";"
,
&
tokenizerCtx
);
}
while
(
cookie
!=
NULL
);
return
rv
;
}
char
*
get_cookie_name
(
request_rec
*
r
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment