r4 - 2013-02-10 - 02:28:21 - HarlanStennYou are here: NTP >  Dev Web > DevelopmentIssues > FixedSizeTypesAndSignExtensions
NTP users are strongly urged to take immediate action to ensure that their NTP daemons are not susceptible to being used in distributed denial-of-service (DDoS) attacks. Please also take this opportunity to defeat denial-of-service attacks by implementing Ingress and Egress filtering through BCP38.

ntp-4.2.8p15 was released on 23 June 2020. It addresses 1 medium-severity security issue in ntpd, and provides 13 non-security bugfixes over 4.2.8p13.

Please see the NTP Security Notice for vulnerability and mitigation details.

Are you using Autokey in production? If so, please contact Harlan - he's got some questions for you.

Fixed Sized Types and Sign Extensions

Related Items: bug_small.png Bug #881, bug_small.png Bug #886, bug_small.png Bug #2272

Problem Summary

With the advent of 64 bit systems several problems have been encountered with the handling of fixed sizes types highlighted by incorrect sign extension for user display.

Many printf and related functions use a format string in the form "%ld" or similar when displaying integers specifying a long argument rather than the more conventional int. I believe this was done in order to easily support larger numbers on machines where an int might be 16 bits and longs were commonly larger. A typical construct might be:

  fprintf(fp,"poll adjust: %ld\n", (long)ntohl(il->compliance));

ntohl() is defined as returning a 32 bit unsigned quantity and this solution works well on 16 and 32 bit systems. Even if compliance is a signed quantity the translation via ntohl still results in th e correct 32 bit pattern.

On some 64 bit systems however the promotion to long will require a sign extension and we will require more care with type casting to get the correct results.

  fprintf(fp,"poll adjust: %lu\n", (unsigned long)ntohl(il->compliance));
  fprintf(fp,"poll adjust: %ld\n", (long)(int32_t)ntohl(il->compliance));

bug_small.png Bug #886 has highlighted that we need to be careful with the fixed size types that we use for casts such as this.

bug_small.png Bug #2272 is mentioned because it recommends we convert from the variety of older integral types to C99 integral types.

Possible Solutions

Signed ntohl()

A version of ntohl() returning a signed 32 bit quantity might be a solution for some of the cases but might be difficult to implement as ntohl() is often a highly optimised macro.

A macro that typecasts ntohl() just reiterates the casting problem.

Type casting using fixed size types from ntp_config.h

Some fixed sized types are available in ntp_config.h which might be used for this purpose, all be it with slightly non-standard names.

  fprintf(fp,"poll adjust: %ld\n", (long)(int32)ntohl(il->compliance));

Or we could use C99 names and add these to ntp_config.h when they are missing in standard system files.

-- BobDunlop - 14 Sep 2007

Other Discussion

Is that ntp_config.h or ntp_types.h? It may be that the header files are a bit 'tangled' and we should add the new types to ntp_types.h and 'get' them via ntp_config.h - I haven't looked at this in a While.

-- HarlanStenn - 13 Sep 2007

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r4 < r3 < r2 < r1 | More topic actions
SSL security by CAcert
Get the CAcert Root Certificate
This site is powered by the TWiki collaboration platform
IPv6 Ready
Copyright & 1999-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding the site? Send feedback