mirror of
https://github.com/curl/curl.git
synced 2026-07-24 08:47:50 +03:00
tool_writeout_json: fix JSON encoding of non-ascii bytes
char variables if unspecified can be either signed or unsigned depending
on the platform according to the C standard; in most platforms, they are
signed.
This meant that the *i<32 waas always true for bytes with the top bit
set. So they were always getting encoded as \uXXXX, and then since they
were also signed negative, they were getting extended with 1s causing
'\xe2' to be expanded to \uffffffe2, for example:
$ curl --variable 'v=“' --expand-write-out '{{v:json}}\n' file:///dev/null
\uffffffe2\uffffff80\uffffff9c
I fixed this bug by making the code use explicitly unsigned char*
variables instead of char* variables.
Test 268 verifies
Reported-by: iconoclasthero
Closes #12434
This commit is contained in:
parent
83e4d61981
commit
6c7da81561
3 changed files with 62 additions and 3 deletions
|
|
@ -41,8 +41,8 @@
|
|||
int jsonquoted(const char *in, size_t len,
|
||||
struct curlx_dynbuf *out, bool lowercase)
|
||||
{
|
||||
const char *i = in;
|
||||
const char *in_end = &in[len];
|
||||
const unsigned char *i = (unsigned char *)in;
|
||||
const unsigned char *in_end = &i[len];
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
for(; (i < in_end) && !result; i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue