(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/dissectors/packet-ber.c) |
| |
| 3745 | | | dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id) |
| 3746 | | | { |
| 3747 | | | char outstr[33]; |
| 3748 | | | char *outstrptr = outstr; |
| 3749 | | | const guint8 *instr; |
| 3750 | | | gint8 class; |
| 3751 | | | gboolean pc; |
| 3752 | | | gint32 tag; |
| 3753 | | | guint32 len, i, n; |
| 3754 | | | int hoffset; |
| 3755 | | | proto_item *cause; |
| 3756 | | | |
| 3757 | | | if(!implicit_tag){ |
| 3758 | | | hoffset = offset; |
| 3759 | | | offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &class, &pc, &tag); |
| 3760 | | | offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, NULL); |
| 3761 | | | |
| 3762 | | | |
| 3763 | | | if( (class!=BER_CLASS_UNI) || (tag!=BER_UNI_TAG_UTCTime) ) { |
| 3764 | | | tvb_ensure_bytes_exist(tvb, hoffset, 2); |
| 3765 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3766 | | | "BER Error: UTCTime expected but class:%s(%d) %s tag:%d was unexpected", |
| 3767 | | | val_to_str(class,ber_class_codes,"Unknown"), class, |
| 3768 | | | pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string, tag); |
| 3769 | | | proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN); |
| 3770 | | | expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: UTCTime expected"); |
| 3771 | | | if (decode_unexpected) { |
| 3772 | | | proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown); |
| 3773 | | | dissect_unknown_ber(actx->pinfo, tvb, hoffset, unknown_tree); |
| 3774 | | | } |
| 3775 | | | return offset+len; |
| 3776 | | | } |
| 3777 | | | } else { |
| 3778 | | | len = tvb_length_remaining(tvb,offset); |
| 3779 | | | } |
| 3780 | | | |
| 3781 | | | instr = tvb_get_ptr(tvb, offset, len); |
| 3782 | | | |
| 3783 | | | |
| 3784 | | | for(i=0;i<10;i++) { |
| 3785 | | | if(instr[i] < '0' || instr[i] > '9') { |
| 3786 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3787 | | | "BER Error: malformed UTCTime encoding, " |
| 3788 | | | "first 10 octets have to contain YYMMDDhhmm in digits"); |
| 3789 | | | goto malformed; |
| 3790 | | | } |
| 3791 | | | } |
| 3792 | | | g_snprintf(outstrptr, 15, "%.2s-%.2s-%.2s %.2s:%.2s", instr, instr+2, instr+4, instr+6, instr+8); |
| 3793 | | | outstrptr+= 14; |
| 3794 | | | |
| 3795 | | | |
| 3796 | | | if(len >= 12) { |
| 3797 | | | if(instr[i] >= '0' && instr[i] <= '9') { |
| 3798 | | | i++; |
| 3799 | | | if(instr[i] >= '0' && instr[i] <= '9') { |
| 3800 | | | i++; |
| 3801 | | | g_snprintf(outstrptr, 4, ":%.2s", instr+10); |
| 3802 | | | outstrptr+=3; |
| 3803 | | | } else { |
| 3804 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3805 | | | "BER Error: malformed UTCTime encoding, " |
| 3806 | | | "if 11th octet is a digit for seconds, " |
| 3807 | | | "the 12th octet has to be a digit, too"); |
| 3808 | | | goto malformed; |
| 3809 | | | } |
| 3810 | | | } |
| 3811 | | | } |
| 3812 | | | |
| 3813 | | | |
| 3814 | | | switch (instr[i]) { |
| 3815 | | | case 'Z': |
| 3816 | | | if(len!=i+1) { |
| 3817 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3818 | | | "BER Error: malformed UTCTime encoding, " |
| 3819 | | | "there must be no further octets after \'Z\'"); |
| 3820 | | | goto malformed; |
| 3821 | | | } |
| 3822 | | | g_snprintf(outstrptr, 7, " (UTC)"); |
| 3823 | | | i++; |
| 3824 | | | break; |
| 3825 | | | case '-': |
| 3826 | | | case '+': |
| 3827 | | | if(len!=i+5) { |
| 3828 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3829 | | | "BER Error: malformed UTCTime encoding, " |
| 3830 | | | "4 digits must follow on \'+\' resp. \'-\'"); |
| 3831 | | | goto malformed; |
| 3832 | | | } |
| 3833 | | | for(n=i+1;n<i+5;n++) { |
| 3834 | | | if(instr[n] < '0' || instr[n] > '9') { |
| 3835 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3836 | | | "BER Error: malformed UTCTime encoding, " |
| 3837 | | | "4 digits must follow on \'+\' resp. \'-\'"); |
| 3838 | | | goto malformed; |
| 3839 | | | } |
| 3840 | | | } |
| 3841 | | | g_snprintf(outstrptr, 12, " (UTC%c%.4s)", instr[i], instr+i+1); |
| 3842 | | | i+=5; |
| 3843 | | | break; |
| 3844 | | | default: |
| 3845 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3846 | | | "BER Error: malformed UTCTime encoding, " |
| 3847 | | | "unexpected character in %dth octet, " |
| 3848 | | | "must be \'Z\', \'+\' or \'-\'", i+1); |
| 3849 | | | goto malformed; |
| 3850 | | | break; |
Unreachable Control Flow
The highlighted code will not execute under any circumstances. This may be because of: |
|
| 3851 | | | } |
| 3852 | | | |
| 3853 | | | if(len!=i) { |
| 3854 | | | cause = proto_tree_add_text(tree, tvb, offset, len, |
| 3855 | | | "BER Error: malformed UTCTime encoding, " |
| 3856 | | | "%d unexpected character%s after %dth octet", |
| 3857 | | | len-i, (len==i-1?"s":""), i); |
| 3858 | | | goto malformed; |
| 3859 | | | } |
| 3860 | | | |
| 3861 | | | if(hf_id >= 0){ |
| 3862 | | | proto_tree_add_string(tree, hf_id, tvb, offset, len, outstr); |
| 3863 | | | } |
| 3864 | | | |
| 3865 | | | return offset+len; |
| 3866 | | | malformed: |
| 3867 | | | proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN); |
| 3868 | | | expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "BER Error: malformed UTCTime encoding"); |
| 3869 | | | g_snprintf(outstr, (len>29)?31:len+1, "%s", instr); |
| 3870 | | | if(hf_id >= 0){ |
| 3871 | | | proto_tree_add_string(tree, hf_id, tvb, offset, len, outstr); |
| 3872 | | | } |
| 3873 | | | return offset+len; |
| 3874 | | | } |
| |