Menu

#58 Parse an error string but no returning false or expection

0.5.0
closed-fixed
nobody
None
5
2015-03-06
2013-03-14
yyy_3y
No

#include <iostream>
#include <json/json.h>
using namespace std;
using namespace Json;

int main()
{
string s;
s = "957{\"uid\":\"181800860\"}";
//if the first is a character of number 0~9,
//then the following parse will not return false,
//but when running to the value["uid"], an expection is thrown

Value value;
Reader reader;

if (!reader.parse(s, value)) {
cout << "error" << endl;
return 0;
}
value["uid"];
}

Discussion

  • Olof Asplund

    Olof Asplund - 2014-04-11

    This problem leads to even more serious issues.

    1. Parse an invalid object as above.
    2. Your program will think it has a parsed json. But since you know about this bug, you perform several checks on the object before you access the data (isMember("xxx"), get("xxx", "fail") etc.
      All these checks will ALSO result in a crash, hence this is a very serious bug
     
  • Christopher Dunn

    This is now fixed via strictMode at: https://github.com/open-source-parsers/jsoncpp/

     
  • Christopher Dunn

    • status: open --> closed-fixed
    • Group: --> 0.5.0
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.