aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2018-05-09 14:41:05 +0000
committerWerner Koch <[email protected]>2018-05-09 14:41:05 +0000
commite54b110aec3165a32ff9551d0c5227b88aa3dd4f (patch)
treeda94aff60185d978cd1a74a9df83a1886dfd272a
parentcore: Make the status-fd monitor work for all gpgsm commands. (diff)
downloadgpgme-e54b110aec3165a32ff9551d0c5227b88aa3dd4f.tar.gz
gpgme-e54b110aec3165a32ff9551d0c5227b88aa3dd4f.zip
json: Improve auto-base64 encoding to not split UTF-8 chars.
* src/gpgme-json.c (make_data_object): Switch to Base64 also for UTF-8 characters. Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--src/gpgme-json.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/gpgme-json.c b/src/gpgme-json.c
index f1e9f256..fb5f149b 100644
--- a/src/gpgme-json.c
+++ b/src/gpgme-json.c
@@ -610,7 +610,8 @@ make_data_object (cjson_t result, gpgme_data_t data, size_t chunksize,
{
gpg_error_t err;
char *buffer;
- size_t buflen;
+ const char *s;
+ size_t buflen, n;
int c;
if (!base64 || base64 == -1) /* Make sure that we really have a string. */
@@ -629,13 +630,18 @@ make_data_object (cjson_t result, gpgme_data_t data, size_t chunksize,
base64 = 0;
if (!buflen)
log_fatal ("Appended Nul byte got lost\n");
- if (memchr (buffer, 0, buflen-1))
- {
- buflen--; /* Adjust for the extra nul byte. */
- base64 = 1;
- }
- /* Fixme: We might want to do more advanced heuristics than to
- * only look for a Nul. */
+ /* Figure out if there is any Nul octet in the buffer. In that
+ * case we need to Base-64 the buffer. Due to problems with the
+ * browser's Javascript we use Base-64 also in case an UTF-8
+ * character is in the buffer. This is because the chunking may
+ * split an UTF-8 characters and JS can't handle this. */
+ for (s=buffer, n=0; n < buflen -1; s++, n++)
+ if (!*s || (*s & 0x80))
+ {
+ buflen--; /* Adjust for the extra nul byte. */
+ base64 = 1;
+ break;
+ }
}
/* Adjust the chunksize if we need to do base64 conversion. */