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

Y2038 bug in sensor gps_time and utility program query_gpsdo_sensors #659

Open
cosmos72 opened this issue Feb 8, 2023 · 0 comments
Open
Labels

Comments

@cosmos72
Copy link

cosmos72 commented Feb 8, 2023

Issue Description

Reading the example
https://github.com/EttusResearch/uhd/blob/master/host/utils/query_gpsdo_sensors.cpp#L215
I noticed that sensor value "gps_time" is converted to signed:

    uhd::sensor_value_t gps_time   = usrp->get_mboard_sensor("gps_time");
    // we only care about the full seconds
    signed gps_seconds    = gps_time.to_int();

which will overflow on 19 January 2038 - it's an instance of the Y2038 bug, see for example
https://en.wikipedia.org/wiki/Year_2038_problem

I tracked down where the sensor value for "gps_time" is created by uhd library, and it has an analogous problem:
https://github.com/EttusResearch/uhd/blob/master/host/lib/usrp/gps_ctrl.cpp#L274

    } else if (key == "gps_time") {
            return sensor_value_t("GPS epoch time", int(get_epoch_time()), "seconds");

while get_epoch_time() returns an int64_t, truncating it to int will again overflow on 19 January 2038.

Setup Details

To reproduce this bug, one would have to wait for 19 January 2038, and execute the utility program query_gpsdo_sensors on a radio with GPSDO chip and external GPS antenna.

Alternatively, a get_epoch_time() > 2^31-1 may be injected by modifying uhd sources.

Expected Behavior

query_gpsdo_sensors continues to work also after 19 January 2038.

Actual Behaviour

query_gpsdo_sensors will not be able to synchronize radio's clock to GPS time after 19 January 2038.

Steps to reproduce the problem

Wait for 19 January 2038, and execute the utility program query_gpsdo_sensors on a radio with GPSDO chip and external GPS antenna.

Alternatively, inject a get_epoch_time() > 2^31-1 by modifying uhd sources.

Additional Information

As a possible solution, host/lib/usrp/gps_ctrl.cpp could create the sensor value "gps_time" as follows:

    } else if (key == "gps_time") {
            return sensor_value_t("GPS epoch time", std::to_string(get_epoch_time()), "seconds");

with the (hopefully acceptable) side effect that sensor_value_t type changes from INT to STRING.

Also host/utils/query_gpsdo_sensors.cpp could read the sensor value as follows:

    uhd::sensor_value_t gps_time   = usrp->get_mboard_sensor("gps_time");
    // we only care about the full seconds
    long long gps_seconds    = std::stoll(gps_time.value);
@mbr0wn mbr0wn added the bug label Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants