Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.2' into merge_12_13_12
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Aug 2, 2024
2 parents fc1c61f + 253fcab commit 1354f73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions deps/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static unsigned char dtable[256] = {

unsigned char *
UA_unbase64(const unsigned char *src, size_t len, size_t *out_len) {
if(len == 0)
if(len == 0 || len % 4 != 0)
return NULL;

unsigned char *out, *pos;
Expand All @@ -84,38 +84,40 @@ UA_unbase64(const unsigned char *src, size_t len, size_t *out_len) {
if(!out)
return NULL;

int pad = 0;
size_t count = 0;
size_t pad = 0;
unsigned char count = 0;
unsigned char block[4];
for(size_t i = 0; i < len; i++) {
unsigned char tmp = dtable[src[i]];
if(tmp == 0x80)
continue;
if(tmp == 0x80)
goto error; /* Invalid input */

if(src[i] == '=')
pad++;

block[count] = tmp;
count++;
if(count == 4) {
*pos++ = (block[0] << 2) | (block[1] >> 4);
*pos++ = (block[1] << 4) | (block[2] >> 2);
*pos++ = (block[2] << 6) | block[3];
count = 0;
if(pad) {
if(pad == 1)
pos--;
else if(pad == 2)
pos -= 2;
else {
/* Invalid padding */
UA_free(out);
return NULL;
}
if(pad == 1)
pos--;
else if(pad == 2)
pos -= 2;
else
goto error; /* Invalid padding */
break;
}
}
count = 0;
}
}

*out_len = (size_t)(pos - out);
return out;

error:
UA_free(out);
return NULL;
}
2 changes: 1 addition & 1 deletion tests/check_types_builtin_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -4384,7 +4384,7 @@ START_TEST(UA_ByteString_bad_json_decode) {

UA_StatusCode retval = UA_decodeJsonInternal(&buf, &out, &UA_TYPES[UA_TYPES_BYTESTRING]);
// then
ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
ck_assert_int_ne(retval, UA_STATUSCODE_GOOD);
UA_ByteString_clear(&out);
}
END_TEST
Expand Down

0 comments on commit 1354f73

Please sign in to comment.