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

Fix data type macro used for 64-bit timestamp variables #6897

Merged

Conversation

mike-myers-tob
Copy link
Member

Closes #6890

As described in the issue, sometimes 64-bit (long long) variables used for timestamps were being put through the INTEGER() macro which would fail in the tryto() routine. This PR changes the fields that need to hold these timestamps to be BIGINT.

@mike-myers-tob
Copy link
Member Author

Before changing to Ready for Review, I have a question:

Should the type actually be DATETIME, as is already the case for the certificates table spec? I've been told the data type is actually ignored and everything ends up text before being stored in the table, but, definitely the INTEGER casting function was failing out and needed to be changed.

Second question: will this affect 32-bit builds? I assume not, since processes already used BIGINT for its timestamps.

One other note: in logged_in_users.cpp for non-Windows systems (so, the POSIX implementation of the table), the code is taking the 64-bit timestamp from utmp and discarding the lower 32-bits (the microseconds). Is that desirable?

@mike-myers-tob mike-myers-tob marked this pull request as ready for review January 28, 2021 16:28
@mike-myers-tob mike-myers-tob added the ready for review Pull requests that are ready to be reviewed by a maintainer label Jan 28, 2021
@mike-myers-tob
Copy link
Member Author

I wasn't able to get feedback on this, maybe someone could weigh in. My question is about what was intended to be, so we can adjust the data types macro calls to be consistent.

@Smjert
Copy link
Member

Smjert commented Jan 28, 2021

@mike-myers-tob I fear that there's not much consistency with it, although I personally believe we should follow what all sql servers (at least MySQL and SQL Server) normally show with that column type, which is text with the format YYYY-MM-DD HH:MI:SS.

Now the reason why I'm saying there's no consistency is because in sqlite while the DATETIME type exists, it exists only for compatibility reasons and it maps actually to the another type which is NUMERIC (https://www.sqlite.org/datatype3.html in the 3.1.1. Affinity Name Examples section).
Now we (osquery core) don't actually support DATETIME or NUMERIC as sqlite does, but we map DATETIME to TEXT

DATETIME = DataType("TEXT_TYPE")

But it seems that we then expect it to be a timestamp:

query = "select CAST(seconds AS DATETIME) FROM time";

which imho is wrong; DATETIME should tell the user of the table what kind of format is expected.

So as you've seen there's only one usage of that column type, in the certificates table and it should show dates not a timestamp as it's showing now.

Now to answer your question on what to put then, I would personally put BIGINT because a timestamp is a number.
Putting TEXT simply goes around any possible check we can do internally to see if the value is somehow incorrect.

@mike-myers-tob mike-myers-tob merged commit de78a66 into osquery:master Feb 2, 2021
@mike-myers-tob mike-myers-tob deleted the mike/fix-timestamp-conversion branch February 2, 2021 18:11
@mike-myers-tob mike-myers-tob removed the ready for review Pull requests that are ready to be reviewed by a maintainer label Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix timestamp to integer conversion operation in scheduled_tasks
3 participants