Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaml-cpp crashed when loading a wrong format yaml file #701

Closed
HensonLi opened this issue Apr 15, 2019 · 4 comments
Closed

yaml-cpp crashed when loading a wrong format yaml file #701

HensonLi opened this issue Apr 15, 2019 · 4 comments

Comments

@HensonLi
Copy link

HensonLi commented Apr 15, 2019

When using YAML::Node rNode = YAML::LoadFile(“test.yaml”)

  • terminal output log as below :
    terminating with uncaught exception of type YAML::ParserException: yaml-cpp: error at line 14, column 15: illegal map value

  • test.yaml's content as below:

com.hh.example:
permission: 1,2
bookManager:
descriptor: com.hh.example.service.BookManager
addMsg:
methodNumber: 2
permission: 1,2
getFrontMsg:
methodNumber: 1
permission: 1
com.hh.msp.client:
permission: 1,2
test:henson`

( sorry for that i can't make the file content indent correctly)

After checking the code, i found that the method Scanner::ScanValue() throw out a execption with throw ParserException(INPUT.mark(), ErrorMsg::MAP_VALUE);, but seems no code the handle this execption

Question :

  1. seems than the YAML::Parser can not parse or skip test:henson which has no black space after ":"
  2. Shoud there be one execption to handle such issue other that let it crash
@HensonLi HensonLi changed the title yaml-cpp yaml-cpp crashed when loading a wrong format yaml file Apr 15, 2019
@tt4g
Copy link
Contributor

tt4g commented Apr 15, 2019

I'm not good at English, so I may have misunderstood your comment.

seems than the YAML::Parser can not parse or skip test:henson which has no black space after ":"

test: henson can not be parsed as YAML, You have to add whitespace (i.e space) after ":".

Shoud there be one execption to handle such issue other that let it crash

This error is not handled inside yaml-cpp because it is a syntax error in the your YAML file.
You need to handle exception.

example:

try {
    YAML::Node rNode = YAML::LoadFile(“test.yaml”);

    // using YAML node.

} catch(const YAML::ParserException& ex) {
    std::cout << ex.what() << std::endl;
}

see:

/**
* Loads the input file as a single YAML document.
*
* @throws {@link ParserException} if it is malformed.
* @throws {@link BadFile} if the file cannot be loaded.
*/
YAML_CPP_API Node LoadFile(const std::string& filename);

@HensonLi
Copy link
Author

@tt4g Thanks for your reply, you have totally understood what i am saying, there is no problem about catch the execption myself, just recommend to handle it in yaml-cpp to prevent to programe from crash.

@tt4g
Copy link
Contributor

tt4g commented Apr 15, 2019

@HensonLi OK. The addition of an API that does not generate exception is closely related to the design of yaml-cpp.

Let's wait for @jbeder to confirm this issue.

@jbeder
Copy link
Owner

jbeder commented Apr 15, 2019

@tt4g is correct; this is working as intended. The library is designed for you to handle incorrectly formed YAML by catching ParserException.

@jbeder jbeder closed this as completed Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants