|
59 | 59 | #include <ipfixprobe/flowifc.hpp> |
60 | 60 | #include <ipfixprobe/packet.hpp> |
61 | 61 | #include <ipfixprobe/ipfix-elements.hpp> |
| 62 | +#include <ipfixprobe/utils.hpp> |
62 | 63 |
|
63 | 64 | namespace ipxp { |
64 | 65 |
|
@@ -132,56 +133,45 @@ struct RecordExtHTTP : public RecordExt { |
132 | 133 |
|
133 | 134 | virtual int fill_ipfix(uint8_t *buffer, int size) |
134 | 135 | { |
135 | | - int length, total_length = 0; |
| 136 | + uint16_t length = 0; |
| 137 | + uint32_t total_length = 0; |
136 | 138 |
|
137 | 139 | length = strlen(user_agent); |
138 | | - if (length + 1 > size) { |
| 140 | + if (uint32_t (length + 1) > (uint32_t) size) { |
139 | 141 | return -1; |
140 | 142 | } |
141 | | - buffer[0] = length; |
142 | | - memcpy(buffer + 1, user_agent, length); |
143 | | - total_length = length + 1; |
| 143 | + total_length += variable2ipfix_buffer(buffer + total_length, (uint8_t*) user_agent, length); |
144 | 144 |
|
145 | 145 | length = strlen(method); |
146 | | - if (total_length + length + 1 > size) { |
| 146 | + if (total_length + length + 3 > (uint32_t)size) { |
147 | 147 | return -1; |
148 | 148 | } |
149 | | - buffer[total_length] = length; |
150 | | - memcpy(buffer + total_length + 1, method, length); |
151 | | - total_length += length + 1; |
| 149 | + total_length += variable2ipfix_buffer(buffer + total_length, (uint8_t*) method, length); |
152 | 150 |
|
153 | 151 | length = strlen(host); |
154 | | - if (total_length + length + 1 > size) { |
| 152 | + if (total_length + length + 3 > (uint32_t)size) { |
155 | 153 | return -1; |
156 | 154 | } |
157 | | - buffer[total_length] = length; |
158 | | - memcpy(buffer + total_length + 1, host, length); |
159 | | - total_length += length + 1; |
| 155 | + total_length += variable2ipfix_buffer(buffer + total_length, (uint8_t*) host, length); |
160 | 156 |
|
161 | 157 | length = strlen(referer); |
162 | | - if (total_length + length + 1 > size) { |
| 158 | + if (total_length + length + 3 > (uint32_t)size) { |
163 | 159 | return -1; |
164 | 160 | } |
165 | | - buffer[total_length] = length; |
166 | | - memcpy(buffer + total_length + 1, referer, length); |
167 | | - total_length += length + 1; |
| 161 | + total_length += variable2ipfix_buffer(buffer + total_length, (uint8_t*) referer, length); |
168 | 162 |
|
169 | 163 | length = strlen(uri); |
170 | | - if (total_length + length + 4 > size) { |
| 164 | + if (total_length + length + 4 > (uint32_t)size) { |
171 | 165 | return -1; |
172 | 166 | } |
173 | | - buffer[total_length] = length; |
174 | | - memcpy(buffer + total_length + 1, uri, length); |
175 | | - total_length += length + 1; |
| 167 | + total_length += variable2ipfix_buffer(buffer + total_length, (uint8_t*) uri, length); |
176 | 168 |
|
177 | 169 | length = strlen(content_type); |
178 | | - if (total_length + length + 3 > size) { |
| 170 | + if (total_length + length + 3 > (uint32_t)size) { |
179 | 171 | return -1; |
180 | 172 | } |
181 | | - buffer[total_length] = length; |
| 173 | + total_length += variable2ipfix_buffer(buffer + total_length, (uint8_t*) content_type, length); |
182 | 174 |
|
183 | | - memcpy(buffer + total_length + 1, content_type, length); |
184 | | - total_length += length + 1; |
185 | 175 | *(uint16_t *) (buffer + total_length) = ntohs(code); |
186 | 176 | total_length += 2; |
187 | 177 |
|
|
0 commit comments