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

DeckManager: fix LoadLFListSingle, LoadDeck (std::istringstream) #2699

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

salix5
Copy link
Collaborator

@salix5 salix5 commented Feb 23, 2025

LoadLFListSingle

C99
7.19.6.2 The fscanf function
10
Except in the case of a % specifier, the input item (or, in the case of a %n directive, the count of input characters) is converted to a type appropriate to the conversion specifier.
If the input item is not a matching sequence, the execution of the directive fails: this condition is a matching failure.
Unless assignment suppression was indicated by a *, the result of the conversion is placed in the object pointed to by the first argument following the format argument that has not already received a conversion result.
If this object does not have an appropriate type, or if the result of the conversion cannot be represented in the object, the behavior is undefined.

If there is a line in lflist.conf

12345678901234567890 1

The behavior is undefined.

Now we only accept

std::sscanf(linebuf, "%9d[ ]%9d", &code, &count) == 2

LoadDeck (std::istringstream)

https://en.cppreference.com/w/cpp/string/basic_string/stol
Exceptions

  • std::invalid_argument if no conversion could be performed.
  • std::out_of_range if the converted value would fall out of the range of the result type or if the underlying function (std::strtol or std::strtoll) sets errno to ERANGE.

123.ydk

12345678901234567890 

The process will terminate when loading 123.ydk.

Now we use

std::strtol(linebuf.c_str(), nullptr, 10);

and check errno.

@mercury233
@purerosefallen
@Wind2009-Louse
@fallenstardust

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

Successfully merging this pull request may close these issues.

1 participant