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

IcingaDB::PrepareObject(): round Notification#interval and limit it to >=0 #9793

Conversation

Al2Klimov
Copy link
Member

otherwise, e.g. with -42.5 (my successful before/after test case btw.), the Go daemon crashes. It expects uints there.

…o >=0

otherwise, e.g. with -42.5, the Go daemon crashes. It expects uints there.
@Al2Klimov Al2Klimov added bug Something isn't working area/icingadb New backend labels Jun 19, 2023
@Al2Klimov Al2Klimov added this to the 2.14.0 milestone Jun 19, 2023
@cla-bot cla-bot bot added the cla/signed label Jun 19, 2023
@julianbrost julianbrost requested a review from yhabteab June 19, 2023 14:07
Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look fine, but since you're already touching Notification-related stuff, I'd also check for any other attributes of that type that would cause Icinga DB to crash. First example times.begin:

2023-06-20T07:27:41.430Z        FATAL   icingadb        json: cannot unmarshal number 30.3 into Go value of type int64
can't unmarshal JSON into *int64
github.com/icinga/icingadb/internal.UnmarshalJSON
        /go/src/github.com/Icinga/icingadb/internal/internal.go:47
github.com/icinga/icingadb/pkg/types.(*Int).UnmarshalJSON
        /go/src/github.com/Icinga/icingadb/pkg/types/int.go:52
...

@Al2Klimov
Copy link
Member Author

Actually I've done that, but completely overseen that particular attribute attribute. Thanks. I'll make a separate PR.

Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't an Icinga 2 problem, but rather an Icinga DB one, nonetheless setting the notification.interval to Math.pow(2,32) still crashes Icinga DB.

2023-06-20T10:19:55.792Z        FATAL   icingadb        json: cannot unmarshal number 4294967296 into Go struct field Notification.notification_interval of type uint32
can't unmarshal JSON into *v1.Notification
github.com/icinga/icingadb/internal.UnmarshalJSON
        /go/src/github.com/Icinga/icingadb/internal/internal.go:47
github.com/icinga/icingadb/pkg/icingaredis.CreateEntities.func1.1

@Al2Klimov
Copy link
Member Author

And, let me guess, if I double both the Go struct data type bits and the second argument to Math.pow, it still crashes?

@yhabteab
Copy link
Member

And, let me guess, if I double both the Go struct data type bits and the second argument to Math.pow, it still crashes?

Yep! But I don't think we have valid use cases for using > 64 bit integer. You can of course set a value on the Icinga2 side that is beyond 64 bit signs but that would not only crash the Icinga DB daemon.

@Al2Klimov
Copy link
Member Author

I doubt the latter.

<1> => Math.pow(2,128)
340282366920938463463374607431768211456.000000
<2> => Math.pow(2,128) < get_time()
false
<3> => Math.pow(2,128) > get_time()
true
<4> =>

But even Math.pow(2,32) in prod is a provocation, not an actual usage IMAO.

@Al2Klimov Al2Klimov requested a review from julianbrost June 20, 2023 10:50
@julianbrost
Copy link
Contributor

But even Math.pow(2,32) in prod is a provocation, not an actual usage IMAO.

If it's accepted and it crashes, it's a bug. Imagine if some (restricted) user is allowed to edit some objects and this allows them to crash the process, that's not good.

@Al2Klimov
Copy link
Member Author

If this is your benchmark, you have just opened the pandora can. A lot of stuff is affected by this sabotage possibility. But instead of replicating signed/unsigned and bits amount info from Go to C++, I'd close/stall all such PRs of mine and instead make a templated type on Go side which handles all this gracefully. What do you think?

type MakeItEinfachGeil[T NumericConstraint] T

@julianbrost
Copy link
Contributor

As discussed in our team meeting earlier today: most of the bad stuff should be handled by Icinga/icingadb#607, i.e. some funky object shouldn't bring down everything in Icinga DB. But the overall goal should still be that Icinga 2 writes consistent information into Redis, so the PRs here shouldn't be abandoned.

@julianbrost julianbrost removed their assignment Jun 21, 2023
@julianbrost julianbrost dismissed yhabteab’s stale review June 27, 2023 07:59

These concerns will be addressed separately: #9794 Icinga/icingadb#607

@julianbrost julianbrost merged commit bd11bc2 into master Jun 27, 2023
@icinga-probot icinga-probot bot deleted the unmarshal-number-42-5-into-go-struct-field-notification-notification_interval branch June 27, 2023 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/icingadb New backend bug Something isn't working cla/signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants