Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH 1/1] digest: fix error in base64 encode options
@ 2018-04-26 15:46 Vladislav Shpilevoy
  0 siblings, 0 replies; only message in thread
From: Vladislav Shpilevoy @ 2018-04-26 15:46 UTC (permalink / raw)
  To: tarantool-patches; +Cc: kostja

Any option of base64 leads to urlsafe encoding. It is wrong, and
caused by incorrect flag checking. Fix it.

Closes #3358
---
Issue: https://github.com/tarantool/tarantool/issues/3358
Branch: https://github.com/tarantool/tarantool/tree/gh-3358-digest-bug

 test/app/digest.result   | 18 ++++++++++++++++++
 test/app/digest.test.lua |  9 +++++++++
 third_party/base64.c     |  2 +-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/test/app/digest.result b/test/app/digest.result
index 1a86bcaff..bf1815136 100644
--- a/test/app/digest.result
+++ b/test/app/digest.result
@@ -506,6 +506,24 @@ digest.base64_decode(b)
 ---
 - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 ...
+--
+-- gh-3358: any option makes base64 work like urlsafe.
+--
+s = digest.base64_encode('?>>>', {nowrap = true})
+---
+...
+-- Check for '+' - it is not urlsafe.
+s:find('+') ~= nil
+---
+- true
+...
+s = digest.base64_encode('?>>>', {nopad = true})
+---
+...
+s:find('+') ~= nil
+---
+- true
+...
 digest.pbkdf2("password", "salt", 4096, 32)
 ---
 - !!binary xeR41ZKIyEGqUw22hFxMjZYok6ABzk4RpJY4c6qYE0o=
diff --git a/test/app/digest.test.lua b/test/app/digest.test.lua
index 76e71fe2d..3134efc92 100644
--- a/test/app/digest.test.lua
+++ b/test/app/digest.test.lua
@@ -161,6 +161,15 @@ b = digest.base64_encode(string.rep('a', 100), { nowrap = true })
 b
 digest.base64_decode(b)
 
+--
+-- gh-3358: any option makes base64 work like urlsafe.
+--
+s = digest.base64_encode('?>>>', {nowrap = true})
+-- Check for '+' - it is not urlsafe.
+s:find('+') ~= nil
+s = digest.base64_encode('?>>>', {nopad = true})
+s:find('+') ~= nil
+
 digest.pbkdf2("password", "salt", 4096, 32)
 digest.pbkdf2_hex("password", "salt", 4096, 32)
 digest.pbkdf2_hex("password", "salt")
diff --git a/third_party/base64.c b/third_party/base64.c
index e3bc0b727..8ecab23eb 100644
--- a/third_party/base64.c
+++ b/third_party/base64.c
@@ -186,7 +186,7 @@ base64_encode(const char *in_bin, int in_len,
 	      char *out_base64, int out_len, int options)
 {
 	const char *encoding;
-	if ((options & BASE64_URLSAFE) != 0)
+	if ((options & BASE64_URLSAFE) == BASE64_URLSAFE)
 		encoding = urlsafe_encoding;
 	else
 		encoding = default_encoding;
-- 
2.15.1 (Apple Git-101)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-04-26 15:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-26 15:46 [tarantool-patches] [PATCH 1/1] digest: fix error in base64 encode options Vladislav Shpilevoy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox