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

Retention Count config uint64 overflow #755

Open
yhabteab opened this issue May 23, 2024 · 4 comments · May be fixed by Icinga/icinga-go-library#86
Open

Retention Count config uint64 overflow #755

yhabteab opened this issue May 23, 2024 · 4 comments · May be fixed by Icinga/icinga-go-library#86
Labels
enhancement New feature or request

Comments

@yhabteab
Copy link
Member

Describe the bug

The config.Retention.Count is user configurable via the YAML file and thus should not be of type uint64, otherwise it can easily be overflowed.

can't parse YAML file config.example.yml: cannot unmarshal -10 into Go value of type uint64 ( overflow )
exit status 1
@yhabteab yhabteab added the bug Something isn't working label May 23, 2024
@yhabteab yhabteab mentioned this issue May 23, 2024
@yhabteab yhabteab added enhancement New feature or request and removed bug Something isn't working labels May 23, 2024
@julianbrost
Copy link
Contributor

julianbrost commented May 23, 2024

Note that it's not that uint64 in inherently wrong here, it's just that the YAML parser we use seems to return a more helpful error message with mismatching types (parsing string into int) than with integer values out out range:

$ go run ./cmd/icingadb --config <(echo 'retention: {count: -1}')
can't parse YAML file /proc/self/fd/11: cannot unmarshal -1 into Go value of type uint64 ( overflow )
exit status 1
$ go run ./cmd/icingadb --config <(echo 'retention: {count: "str"}')
can't parse YAML file /proc/self/fd/11: [1:20] cannot unmarshal string into Go struct field Config.Retention of type uint64
>  1 | retention: {count: "str"}
                          ^

exit status 1

Using a signed int could be a workaround to provide a more helpful error message, at least in some more common error cases (something like trying -1 to disable something).

@oxzi
Copy link
Member

oxzi commented Jul 29, 2024

This issue is not restricted to the Count struct field, but to every uint64 configuration field.

$ ./icingadb --config <(echo 'retention: {history-days: -1}')
can't parse YAML file /proc/self/fd/11: cannot unmarshal -1 into Go value of type uint64 ( overflow )
$ ./icingadb --config <(echo 'retention: {sla-days: -1}')
can't parse YAML file /proc/self/fd/11: cannot unmarshal -1 into Go value of type uint64 ( overflow )

A quick fix could be to change the type to int64 and add a greater-zero check in Validate(), but this feels a bit like throwing the type system under the bus. Thus, as @julianbrost wrote, I would say that this is something to be fixed in the YAML library.

@oxzi
Copy link
Member

oxzi commented Jul 29, 2024

This would be a quick fix addressing this goccy/go-yaml#470.

@oxzi
Copy link
Member

oxzi commented Oct 29, 2024

The mentioned PR got merged and a new go-yaml release was drafted, #832. In the meantime, the retention size was also modified in #824. @yhabteab, would you please take another look at this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants