diff options
author | Sangyoon Jang <s89.jang@samsung.com> | 2015-03-19 13:39:30 +0900 |
---|---|---|
committer | Sangyoon Jang <s89.jang@samsung.com> | 2015-03-20 10:24:59 +0900 |
commit | a0fa658e43635bf703701568eb24bf1003ec1b21 (patch) | |
tree | afc7b1aae707f04335e221476dc79d43a0bfc335 | |
parent | 8e510cddd4f5c50c19fcd126fcc136662a05bacc (diff) | |
download | bundle-a0fa658e43635bf703701568eb24bf1003ec1b21.tar.gz bundle-a0fa658e43635bf703701568eb24bf1003ec1b21.tar.bz2 bundle-a0fa658e43635bf703701568eb24bf1003ec1b21.zip |
Fix bundle_decode
g_base64_decode() decodes null-terminated string, but the result of
bundle_encode() is raw data(not null-terminated).
for decode raw data, it should use g_base64_decode_step().
Change-Id: Ia3d9cda70002cc0b2b53b8e315e0d109893e5d32
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
-rw-r--r-- | src/bundle.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/bundle.c b/src/bundle.c index 6f8618d..81ac13b 100644 --- a/src/bundle.c +++ b/src/bundle.c @@ -517,6 +517,8 @@ bundle_decode(const bundle_raw *r, const int data_size) bundle *b; bundle_raw *p_r; unsigned char *d_str; + gint state = 0; + guint save = 0; unsigned int d_len_raw; unsigned char *d_r; unsigned int d_len; @@ -534,8 +536,25 @@ bundle_decode(const bundle_raw *r, const int data_size) return NULL; } - /* base 64 decode of input string*/ - d_str = g_base64_decode((char *)r, &d_len_raw); + /* base 64 decode of input string + * Since base64 encodes 3 bytes in 4 chars (+3 may be needed in case of non-zero state) + * refer to: https://developer.gnome.org/glib/stable/glib-Base64-Encoding.html#g-base64-decode-step + */ + d_str = malloc((data_size / 4) * 3 + 3); + if (unlikely(NULL == d_str)) { + set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY); + free(extract_cksum); + return NULL; + } + + d_len_raw = g_base64_decode_step((char *)r, data_size, d_str, &state, &save); + if (d_len_raw < CHECKSUM_LENGTH) { + set_last_result(BUNDLE_ERROR_INVALID_PARAMETER); + free(d_str); + free(extract_cksum); + return NULL; + } + /*extract checksum from the received string */ strncpy(extract_cksum, (const char *)d_str, CHECKSUM_LENGTH); /* compute checksum for the data */ |