[Asterisk-code-review] time: add support for time64 libcs (asterisk[master])

Sebastian Kemper asteriskteam at digium.com
Mon Nov 1 06:31:40 CDT 2021


Hello Sean Bright, Friendly Automation, 

I'd like you to reexamine a change. Please visit

    https://gerrit.asterisk.org/c/asterisk/+/16621

to look at the new patch set (#4).

Change subject: time: add support for time64 libcs
......................................................................

time: add support for time64 libcs

libcs are implementing changes to fix the year 2038 issue on 32 bit
platforms (see [1]). musl libc already went ahead and implemented it,
starting with musl-1.2.0 (see [2]).

Running asterisk on a 32 bit box with a time64 libc causes some
problems. For instance registering to pjsip doesn't work. The
registration completes fine, but the AOR disappears immediately, making
the registered clients unreachable.

Currently time_t is always expected to be (long). This commit changes
this and instead always uses "lld" when dealing with time_t and casting
the values to be formatted to (long long). The aim is to be future proof
and portable. This was suggested on the musl mailing list ([3]).

When it comes to scanning, no assumptions can be made regarding the type
of the time_t destination. It is unknown as it is depending on the
platform. So we "read into a known-size integer (either int or long
long) and then assign the value to a time_t as a second step" (quote
from [4]).

These changes get rid of the new warnings that appeared with musl-1.2.0 and
make the pjsip registration work again. Below an example warning:

In file included from ../include/asterisk.h:23,
                 from res_pjsip/location.c:19:
res_pjsip/location.c: In function 'expiration_struct2str':
../include/asterisk/astmm.h:270:72: warning: format '%ld' expects argument of type 'long int', but argument 6 has type 'time_t' {aka 'long long int'} [-Wformat=]
  270 |         __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__)
      |                                                                        ^~~~~
res_pjsip/location.c:492:17: note: in expansion of macro 'ast_asprintf'
  492 |         return (ast_asprintf(buf, "%ld", contact->expiration_time.tv_sec) < 0) ? -1 : 0;
      |                 ^~~~~~~~~~~~

[1] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign
[2] https://musl.libc.org/time64.html
[3] https://www.openwall.com/lists/musl/2021/10/27/3
[4] https://stackoverflow.com/questions/4171478/how-to-read-data-into-a-time-t-variable-using-scanf

ASTERISK-29674 #close

Signed-off-by: Sebastian Kemper <sebastian_ml at gmx.net>
Change-Id: Ic8d61b26033f5c486b917e738c9608b0923a844e
---
M include/asterisk/time.h
M res/res_calendar_caldav.c
M res/res_calendar_icalendar.c
M res/res_http_media_cache.c
M res/res_odbc.c
M res/res_pjsip/location.c
M res/res_pjsip/pjsip_options.c
M res/res_pjsip_history.c
M res/res_pjsip_pubsub.c
M res/res_pjsip_registrar.c
M res/res_stir_shaken.c
11 files changed, 34 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/16621/4
-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16621
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ic8d61b26033f5c486b917e738c9608b0923a844e
Gerrit-Change-Number: 16621
Gerrit-PatchSet: 4
Gerrit-Owner: Sebastian Kemper <sebastian_ml at gmx.net>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: newpatchset
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211101/1312c108/attachment.html>


More information about the asterisk-code-review mailing list