Logically dead code
As reported by Coverity in ntpd/ntp_control.c:
767 res_auth = NULL;
assignment: Assigning: req_count = (int)({...}).
768 req_count = (int)ntohs(pkt->count);
769 datanotbinflag = false;
770 datalinelen = 0;
771 datasent = false;
772 datapt = rpkt.data;
773
774 if ((rbufp->recv_length & 0x3) != 0)
775 DPRINT(3, ("Control packet length %zu unrounded\n",
776 rbufp->recv_length));
777
778 /*
779 * We're set up now. Make sure we've got at least enough
780 * incoming data space to match the count.
781 */
782 req_data = (int)rbufp->recv_length - (int)CTL_HEADER_LEN;
783 if (req_data < req_count || rbufp->recv_length & 0x3) {
784 ctl_error(CERR_BADFMT);
785 numctldatatooshort++;
786 return;
787 }
788
cond_at_most: Condition 468 < req_count, taking false branch. Now the value of req_count is at most 468.
789 if (CTL_MAX_DATA_LEN < req_count) {
790 /* count too big */
791 ctl_error(CERR_BADFMT);
792 numctlbadpkts++;
793 return;
794 }
795
796 properlen = req_count + (int)CTL_HEADER_LEN;
797 /* round up proper len to a 8 octet boundary */
798
799 properlen = (properlen + 7) & ~7;
800 maclen = rbufp->recv_length - (size_t)properlen;
801 if ((rbufp->recv_length & 3) == 0 &&
802 maclen >= MIN_MAC_LEN && maclen <= MAX_MAC_LEN) {
803 keyid_t keyid;
804 pkid = (void *)((char *)pkt + properlen);
805 keyid = ntohl(*pkid);
806 DPRINT(3, ("recv_len %zu, properlen %d, wants auth with keyid %08x, MAC length=%zu\n",
807 rbufp->recv_length, properlen, keyid,
808 maclen));
809
810 res_auth = authlookup(keyid, true); // FIXME
811 if (NULL == res_auth)
812 DPRINT(3, ("invalid keyid %08x\n", keyid));
813 else if (authdecrypt(res_auth, (uint32_t *)pkt,
814 (int)rbufp->recv_length - (int)maclen,
815 (int)maclen)) {
816 DPRINT(3, ("authenticated okay\n"));
817 } else {
818 res_auth = NULL;
819 DPRINT(3, ("authentication failed\n"));
820 }
821 }
822
823 /*
824 * Set up translate pointers
825 */
826 reqpt = (char *)pkt->data;
at_most: At condition 468 < req_count, the value of req_count must be at most 468.
dead_error_condition: The condition 468 < req_count cannot be true.
827 if (CTL_MAX_DATA_LEN < req_count) {
828 /* count too big */
829 /* coverity[deadcode] backstop to prevent stack overflow */
CID 184228 (#1 of 1): Logically dead code (DEADCODE)
dead_error_begin: Execution cannot reach this statement: ctl_error(2);.
830 ctl_error(CERR_BADFMT);
831 numctlbadpkts++;
832 return;
833 }
/cc @hal.murray