Giter Site home page Giter Site logo

Buffer overrun about parson HOT 11 CLOSED

kgabis avatar kgabis commented on August 21, 2024
Buffer overrun

from parson.

Comments (11)

stuertz avatar stuertz commented on August 21, 2024

Upps sorry, Forgot to escape backslahes in the example above:
the right (failing) example line must be:

const char* msg = "Environment: \npid=13232\nhostname=con-js\nALLUSERSPROFILE=C:\\ProgramData\nAPPDATA=C:\\Users\\js\\AppData\\Roaming";

from parson.

measuredweighed avatar measuredweighed commented on August 21, 2024

Just a note to say that we're experiencing this issue too. Any string value containing more than one backslash (i.e: test\\) will cause a crash whereas I believe we would expect the value to be escaped like so: test\\\\

from parson.

measuredweighed avatar measuredweighed commented on August 21, 2024

Here's some simple code that'll reproduce the issue:

JSON_Value *root_value = json_value_init_object();
JSON_Object *root_object = json_value_get_object(root_value);

char *serialized_string = NULL;
json_object_set_string(root_object, "name", "John \\Smith");
serialized_string = json_serialize_to_string(root_value);
json_free_serialized_string(serialized_string);
json_value_free(root_value);

from parson.

stuertz avatar stuertz commented on August 21, 2024

Hi NialG,
I edited the tests a bit and could also reproduce this behavior using gcc.
Without calling json_serialize_to_string it works, but i do get an unescaped value, which looks also wrong to me, as you said.
When calling json_serialize_to_string with backslash values I do get a Segmentaion Fault, as on windows...

from parson.

kgabis avatar kgabis commented on August 21, 2024

Hi, thanks for reporting this bug.
I'm working on the solution, however current "" parsing behavior is correct. This is explained here: http://stackoverflow.com/questions/3807537/why-does-the-jquery-json-parser-need-double-escaping-for-backslashes

from parson.

leearmstrong avatar leearmstrong commented on August 21, 2024

What if the raw input actually needs to be \\ then escaping it to \\\\ is correct?

from parson.

measuredweighed avatar measuredweighed commented on August 21, 2024

That's good to hear. We actually experienced this crash when trying to serialize a string containing two unescaped backslashes.

Thanks for all of your hardwork. Do you have any idea when we're likely to see a fix?

from parson.

kgabis avatar kgabis commented on August 21, 2024

In the following days. But as I said, if you need to specify a windows path in a string in your C code then you must use "\\" instead of "\" (if you want it to be parsed as json).

from parson.

kgabis avatar kgabis commented on August 21, 2024

This should be fixed now (0d5ac45)

from parson.

leearmstrong avatar leearmstrong commented on August 21, 2024

It no longer crashes with the example above

JSON_Value *root_value = json_value_init_object();
JSON_Object *root_object = json_value_get_object(root_value);

char *serialized_string = NULL;
json_object_set_string(root_object, "name", "John \\Smith");
serialized_string = json_serialize_to_string(root_value);
json_free_serialized_string(serialized_string);
json_value_free(root_value);

However serialized_string is still null. I would expect it to be escaped to \\\\

from parson.

kgabis avatar kgabis commented on August 21, 2024

Hi, I've fixed this issue in 4a4cf7d

There's been some confusion, but I shouldn't have been parsing strings when using {set,dotset,replace,append}_string functions. So right now json_object_set_string(root_object, "name", "John \\Smith"); should work (and return JSONSuccess). However json_parse_string("{\"name\":\"John\\ Smith\"}") shouldn't work, as explained here: #26.

from parson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.