/src/krb5/src/include/k5-input.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
2 | | /* include/k5-input.h - k5input helper functions */ |
3 | | /* |
4 | | * Copyright (C) 2014 by the Massachusetts Institute of Technology. |
5 | | * All rights reserved. |
6 | | * |
7 | | * Redistribution and use in source and binary forms, with or without |
8 | | * modification, are permitted provided that the following conditions |
9 | | * are met: |
10 | | * |
11 | | * * Redistributions of source code must retain the above copyright |
12 | | * notice, this list of conditions and the following disclaimer. |
13 | | * |
14 | | * * Redistributions in binary form must reproduce the above copyright |
15 | | * notice, this list of conditions and the following disclaimer in |
16 | | * the documentation and/or other materials provided with the |
17 | | * distribution. |
18 | | * |
19 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
22 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
23 | | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
24 | | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
25 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
26 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
27 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
28 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
30 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | | */ |
32 | | |
33 | | #ifndef K5_INPUT_H |
34 | | #define K5_INPUT_H |
35 | | |
36 | | #include "k5-platform.h" |
37 | | |
38 | | /* |
39 | | * The k5input module defines helpers for safely consuming a fixed-sized block |
40 | | * of memory. If an overrun or allocation failure occurs at any step, |
41 | | * subsequent functions will return default values until the error is detected |
42 | | * by looking at the status field. |
43 | | */ |
44 | | |
45 | | struct k5input { |
46 | | const unsigned char *ptr; |
47 | | size_t len; |
48 | | int32_t status; |
49 | | }; |
50 | | |
51 | | static inline void |
52 | | k5_input_init(struct k5input *in, const void *ptr, size_t len) |
53 | 0 | { |
54 | 0 | in->ptr = ptr; |
55 | 0 | in->len = len; |
56 | 0 | in->status = 0; |
57 | 0 | } Unexecuted instantiation: pac.c:k5_input_init Unexecuted instantiation: cc_kcm.c:k5_input_init Unexecuted instantiation: ucstr.c:k5_input_init Unexecuted instantiation: dnsglue.c:k5_input_init Unexecuted instantiation: dnssrv.c:k5_input_init Unexecuted instantiation: ccmarshal.c:k5_input_init Unexecuted instantiation: utf8_conv.c:k5_input_init |
58 | | |
59 | | /* Only set the status value of in if it hasn't already been set, so status |
60 | | * reflects the first thing to go wrong. */ |
61 | | static inline void |
62 | | k5_input_set_status(struct k5input *in, int32_t status) |
63 | 0 | { |
64 | 0 | if (!in->status) |
65 | 0 | in->status = status; |
66 | 0 | } Unexecuted instantiation: pac.c:k5_input_set_status Unexecuted instantiation: cc_kcm.c:k5_input_set_status Unexecuted instantiation: ucstr.c:k5_input_set_status Unexecuted instantiation: dnsglue.c:k5_input_set_status Unexecuted instantiation: dnssrv.c:k5_input_set_status Unexecuted instantiation: ccmarshal.c:k5_input_set_status Unexecuted instantiation: utf8_conv.c:k5_input_set_status |
67 | | |
68 | | static inline const unsigned char * |
69 | | k5_input_get_bytes(struct k5input *in, size_t len) |
70 | 0 | { |
71 | 0 | if (in->len < len) |
72 | 0 | k5_input_set_status(in, EINVAL); |
73 | 0 | if (in->status) |
74 | 0 | return NULL; |
75 | 0 | in->len -= len; |
76 | 0 | in->ptr += len; |
77 | 0 | return in->ptr - len; |
78 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_bytes Unexecuted instantiation: cc_kcm.c:k5_input_get_bytes Unexecuted instantiation: ucstr.c:k5_input_get_bytes Unexecuted instantiation: dnsglue.c:k5_input_get_bytes Unexecuted instantiation: dnssrv.c:k5_input_get_bytes Unexecuted instantiation: ccmarshal.c:k5_input_get_bytes Unexecuted instantiation: utf8_conv.c:k5_input_get_bytes |
79 | | |
80 | | static inline unsigned char |
81 | | k5_input_get_byte(struct k5input *in) |
82 | 0 | { |
83 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 1); |
84 | 0 | return (ptr == NULL) ? '\0' : *ptr; |
85 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_byte Unexecuted instantiation: cc_kcm.c:k5_input_get_byte Unexecuted instantiation: ucstr.c:k5_input_get_byte Unexecuted instantiation: dnsglue.c:k5_input_get_byte Unexecuted instantiation: dnssrv.c:k5_input_get_byte Unexecuted instantiation: ccmarshal.c:k5_input_get_byte Unexecuted instantiation: utf8_conv.c:k5_input_get_byte |
86 | | |
87 | | static inline uint16_t |
88 | | k5_input_get_uint16_be(struct k5input *in) |
89 | 0 | { |
90 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 2); |
91 | 0 | return (ptr == NULL) ? 0 : load_16_be(ptr); |
92 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint16_be Unexecuted instantiation: cc_kcm.c:k5_input_get_uint16_be Unexecuted instantiation: ucstr.c:k5_input_get_uint16_be Unexecuted instantiation: dnsglue.c:k5_input_get_uint16_be Unexecuted instantiation: dnssrv.c:k5_input_get_uint16_be Unexecuted instantiation: ccmarshal.c:k5_input_get_uint16_be Unexecuted instantiation: utf8_conv.c:k5_input_get_uint16_be |
93 | | |
94 | | static inline uint16_t |
95 | | k5_input_get_uint16_le(struct k5input *in) |
96 | 0 | { |
97 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 2); |
98 | 0 | return (ptr == NULL) ? 0 : load_16_le(ptr); |
99 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint16_le Unexecuted instantiation: cc_kcm.c:k5_input_get_uint16_le Unexecuted instantiation: ucstr.c:k5_input_get_uint16_le Unexecuted instantiation: dnsglue.c:k5_input_get_uint16_le Unexecuted instantiation: dnssrv.c:k5_input_get_uint16_le Unexecuted instantiation: ccmarshal.c:k5_input_get_uint16_le Unexecuted instantiation: utf8_conv.c:k5_input_get_uint16_le |
100 | | |
101 | | static inline uint16_t |
102 | | k5_input_get_uint16_n(struct k5input *in) |
103 | 0 | { |
104 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 2); |
105 | 0 | return (ptr == NULL) ? 0 : load_16_n(ptr); |
106 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint16_n Unexecuted instantiation: cc_kcm.c:k5_input_get_uint16_n Unexecuted instantiation: ucstr.c:k5_input_get_uint16_n Unexecuted instantiation: dnsglue.c:k5_input_get_uint16_n Unexecuted instantiation: dnssrv.c:k5_input_get_uint16_n Unexecuted instantiation: ccmarshal.c:k5_input_get_uint16_n Unexecuted instantiation: utf8_conv.c:k5_input_get_uint16_n |
107 | | |
108 | | static inline uint32_t |
109 | | k5_input_get_uint32_be(struct k5input *in) |
110 | 0 | { |
111 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 4); |
112 | 0 | return (ptr == NULL) ? 0 : load_32_be(ptr); |
113 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint32_be Unexecuted instantiation: cc_kcm.c:k5_input_get_uint32_be Unexecuted instantiation: ucstr.c:k5_input_get_uint32_be Unexecuted instantiation: dnsglue.c:k5_input_get_uint32_be Unexecuted instantiation: dnssrv.c:k5_input_get_uint32_be Unexecuted instantiation: ccmarshal.c:k5_input_get_uint32_be Unexecuted instantiation: utf8_conv.c:k5_input_get_uint32_be |
114 | | |
115 | | static inline uint32_t |
116 | | k5_input_get_uint32_le(struct k5input *in) |
117 | 0 | { |
118 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 4); |
119 | 0 | return (ptr == NULL) ? 0 : load_32_le(ptr); |
120 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint32_le Unexecuted instantiation: cc_kcm.c:k5_input_get_uint32_le Unexecuted instantiation: ucstr.c:k5_input_get_uint32_le Unexecuted instantiation: dnsglue.c:k5_input_get_uint32_le Unexecuted instantiation: dnssrv.c:k5_input_get_uint32_le Unexecuted instantiation: ccmarshal.c:k5_input_get_uint32_le Unexecuted instantiation: utf8_conv.c:k5_input_get_uint32_le |
121 | | |
122 | | static inline uint32_t |
123 | | k5_input_get_uint32_n(struct k5input *in) |
124 | 0 | { |
125 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 4); |
126 | 0 | return (ptr == NULL) ? 0 : load_32_n(ptr); |
127 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint32_n Unexecuted instantiation: cc_kcm.c:k5_input_get_uint32_n Unexecuted instantiation: ucstr.c:k5_input_get_uint32_n Unexecuted instantiation: dnsglue.c:k5_input_get_uint32_n Unexecuted instantiation: dnssrv.c:k5_input_get_uint32_n Unexecuted instantiation: ccmarshal.c:k5_input_get_uint32_n Unexecuted instantiation: utf8_conv.c:k5_input_get_uint32_n |
128 | | |
129 | | static inline uint64_t |
130 | | k5_input_get_uint64_be(struct k5input *in) |
131 | 0 | { |
132 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 8); |
133 | 0 | return (ptr == NULL) ? 0 : load_64_be(ptr); |
134 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint64_be Unexecuted instantiation: cc_kcm.c:k5_input_get_uint64_be Unexecuted instantiation: ucstr.c:k5_input_get_uint64_be Unexecuted instantiation: dnsglue.c:k5_input_get_uint64_be Unexecuted instantiation: dnssrv.c:k5_input_get_uint64_be Unexecuted instantiation: ccmarshal.c:k5_input_get_uint64_be Unexecuted instantiation: utf8_conv.c:k5_input_get_uint64_be |
135 | | |
136 | | static inline uint64_t |
137 | | k5_input_get_uint64_le(struct k5input *in) |
138 | 0 | { |
139 | 0 | const unsigned char *ptr = k5_input_get_bytes(in, 8); |
140 | 0 | return (ptr == NULL) ? 0 : load_64_le(ptr); |
141 | 0 | } Unexecuted instantiation: pac.c:k5_input_get_uint64_le Unexecuted instantiation: cc_kcm.c:k5_input_get_uint64_le Unexecuted instantiation: ucstr.c:k5_input_get_uint64_le Unexecuted instantiation: dnsglue.c:k5_input_get_uint64_le Unexecuted instantiation: dnssrv.c:k5_input_get_uint64_le Unexecuted instantiation: ccmarshal.c:k5_input_get_uint64_le Unexecuted instantiation: utf8_conv.c:k5_input_get_uint64_le |
142 | | |
143 | | #endif /* K5_BUF_H */ |