[ntp] fix errors in ntpstat found by coverity
Miroslav Lichvar
mlichvar at fedoraproject.org
Thu Oct 6 15:30:20 UTC 2011
commit d76274e1e9446a435825d6db92af48250d50ce1b
Author: Miroslav Lichvar <mlichvar at redhat.com>
Date: Thu Oct 6 17:03:58 2011 +0200
fix errors in ntpstat found by coverity
ntp.spec | 3 +++
ntpstat-0.2-errorbit.patch | 32 ++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/ntp.spec b/ntp.spec
index 7c3422b..b61a11e 100644
--- a/ntp.spec
+++ b/ntp.spec
@@ -82,6 +82,8 @@ Patch51: ntpstat-0.2-multipacket.patch
Patch52: ntpstat-0.2-sysvars.patch
# print synchronization distance instead of dispersion
Patch53: ntpstat-0.2-maxerror.patch
+# fix error bit checking
+Patch54: ntpstat-0.2-errorbit.patch
URL: http://www.ntp.org
Requires(post): systemd-units
@@ -165,6 +167,7 @@ This package contains NTP documentation in HTML format.
%patch51 -p1 -b .multipacket
%patch52 -p1 -b .sysvars
%patch53 -p1 -b .maxerror
+%patch54 -p1 -b .errorbit
# set default path to sntp KoD database
sed -i 's|/var/db/ntp-kod|%{_localstatedir}/lib/ntp/sntp-kod|' sntp/{sntp.1,main.c}
diff --git a/ntpstat-0.2-errorbit.patch b/ntpstat-0.2-errorbit.patch
new file mode 100644
index 0000000..06e9342
--- /dev/null
+++ b/ntpstat-0.2-errorbit.patch
@@ -0,0 +1,32 @@
+diff -up ntp-4.2.6p4/ntpstat-0.2/ntpstat.c.errorbit ntp-4.2.6p4/ntpstat-0.2/ntpstat.c
+--- ntp-4.2.6p4/ntpstat-0.2/ntpstat.c.errorbit 2011-10-06 13:41:38.591669772 +0200
++++ ntp-4.2.6p4/ntpstat-0.2/ntpstat.c 2011-10-06 16:50:01.708315811 +0200
+@@ -104,6 +104,7 @@ int main (void) {
+ FD_ZERO(&fds);
+
+ inet_aton("127.0.0.1", &address);
++ memset(&sock, 0, sizeof (sock));;
+ sock.sin_family = AF_INET;
+ sock.sin_addr = address;
+ sock.sin_port = htons(NTP_PORT);
+@@ -159,15 +160,18 @@ int main (void) {
+ die ("return data appears to be invalid based on status word");
+ }
+
+- if (!(ntpmsg.byte2 | EMASK)) {
++ if (ntpmsg.byte2 & EMASK) {
+ fprintf (stderr,"status byte2 is %02x\n", ntpmsg.byte2 );
+ die ("error bit is set in reply");
+ }
+
+- if (!(ntpmsg.byte2 | MMASK)) {
++ /* ignore the more bit */
++#if 0
++ if (ntpmsg.byte2 & MMASK) {
+ fprintf (stderr,"status byte2 is %02x\n", ntpmsg.byte2 );
+ fprintf (stderr,"More bit unexpected in reply");
+ }
++#endif
+
+ /* if the leap indicator (LI), which is the two most significant bits
+ in status byte1, are both one, then the clock is not synchronised. */
More information about the scm-commits
mailing list