Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-blobcode
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-blobcode
Commits
35bf67b2
Commit
35bf67b2
authored
Jan 18, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix conditions at end-of-string for base64_decode()
parent
287ca6ec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
11 deletions
+32
-11
base64.c
src/base64.c
+26
-11
base64.vtc
src/tests/base64.vtc
+6
-0
No files found.
src/base64.c
View file @
35bf67b2
...
...
@@ -33,6 +33,9 @@
#include "vrt.h"
#include "vas.h"
#define ILLEGAL -1
#define PAD -2
struct
b64_state_s
{
unsigned
magic
;
#define B64_STATE_MAGIC 0xc0b64b64
...
...
@@ -53,19 +56,23 @@ alpha_init(struct b64_alphabet *alpha)
const
char
*
p
;
for
(
i
=
0
;
i
<
256
;
i
++
)
alpha
->
i64
[
i
]
=
-
1
;
alpha
->
i64
[
i
]
=
ILLEGAL
;
for
(
p
=
alpha
->
b64
,
i
=
0
;
*
p
;
p
++
,
i
++
)
alpha
->
i64
[(
int
)
*
p
]
=
(
char
)
i
;
if
(
alpha
->
padding
)
alpha
->
i64
[
alpha
->
padding
]
=
0
;
alpha
->
i64
[
alpha
->
padding
]
=
PAD
;
}
static
inline
int
decode
3
(
char
*
restrict
*
restrict
dest
,
char
*
restrict
const
buf
,
const
size_t
maxlen
,
unsigned
u
)
decode
(
char
*
restrict
*
restrict
dest
,
char
*
restrict
const
buf
,
const
size_t
maxlen
,
unsigned
u
,
const
int
n
)
{
char
*
d
=
*
dest
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
char
*
d
;
if
(
n
<=
1
)
return
-
1
;
d
=
*
dest
;
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
if
(
d
==
buf
+
maxlen
)
return
-
1
;
*
d
++
=
(
u
>>
16
)
&
0xff
;
...
...
@@ -184,7 +191,7 @@ base64_decode(const enum encoding dec, char *restrict const buf,
struct
b64_alphabet
*
alpha
=
&
b64_alphabet
[
dec
];
const
char
*
s
;
char
*
dest
=
buf
;
unsigned
u
=
0
;
unsigned
u
=
0
,
term
=
0
;
int
n
;
AN
(
buf
);
...
...
@@ -192,27 +199,35 @@ base64_decode(const enum encoding dec, char *restrict const buf,
for
(
s
=
p
;
s
!=
vrt_magic_string_end
;
s
=
va_arg
(
ap
,
const
char
*
))
{
if
(
s
==
NULL
)
continue
;
if
(
*
s
&&
term
)
{
errno
=
EINVAL
;
return
-
1
;
}
while
(
*
s
)
{
for
(
n
=
0
;
n
<
4
;
n
++
)
{
char
b
=
alpha
->
i64
[(
unsigned
)
*
s
++
];
if
(
b
<
0
)
{
u
<<=
6
;
if
(
b
==
ILLEGAL
)
{
errno
=
EINVAL
;
return
-
1
;
}
u
<<=
6
;
if
(
b
==
PAD
)
{
term
++
;
continue
;
}
u
|=
(
unsigned
)
b
;
if
(
!*
s
)
break
;
}
if
(
n
==
4
)
if
(
decode
3
(
&
dest
,
buf
,
maxlen
,
u
)
<
0
)
{
if
(
decode
(
&
dest
,
buf
,
maxlen
,
u
,
n
-
term
)
<
0
)
{
errno
=
ENOMEM
;
return
-
1
;
}
}
}
if
(
n
!=
4
)
if
(
decode
3
(
&
dest
,
buf
,
maxlen
,
u
)
<
0
)
{
if
(
decode
(
&
dest
,
buf
,
maxlen
,
u
,
n
-
term
)
<
0
)
{
errno
=
ENOMEM
;
return
-
1
;
}
...
...
src/tests/base64.vtc
View file @
35bf67b2
...
...
@@ -44,6 +44,11 @@ varnish v1 -vcl+backend {
convert
.
decode
(
BASE64
,
"VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=="
));
set
resp
.
http
.
decenc
=
convert
.
encode
(
BASE64
,
convert
.
decode
(
BASE64
,
"L0hlbGxvIHdvcmxkLw=="
));
}
}
-
start
...
...
@@ -58,6 +63,7 @@ client c1 {
expect
resp
.
http
.
b64urlnopadxcode
==
"L0hlbGxvIHdvcmxkLw"
expect
resp
.
http
.
dec
==
"/Hello world/"
expect
resp
.
http
.
dec2
==
"The quick brown fox jumps over the lazy dog"
expect
resp
.
http
.
decenc
==
"L0hlbGxvIHdvcmxkLw=="
}
client
c1
-
run
Write
Preview
Markdown
is supported
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