Skip to content

Commit be785d6

Browse files
committed
FIXED HTTP plugin variable-length IE IPFIX export
1 parent 681049e commit be785d6

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

process/http.hpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <ipfixprobe/flowifc.hpp>
6060
#include <ipfixprobe/packet.hpp>
6161
#include <ipfixprobe/ipfix-elements.hpp>
62+
#include <ipfixprobe/utils.hpp>
6263

6364
namespace ipxp {
6465

@@ -132,56 +133,45 @@ struct RecordExtHTTP : public RecordExt {
132133

133134
virtual int fill_ipfix(uint8_t *buffer, int size)
134135
{
135-
int length, total_length = 0;
136+
uint16_t length = 0;
137+
uint32_t total_length = 0;
136138

137139
length = strlen(user_agent);
138-
if (length + 1 > size) {
140+
if (uint32_t (length + 1) > (uint32_t) size) {
139141
return -1;
140142
}
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);
144144

145145
length = strlen(method);
146-
if (total_length + length + 1 > size) {
146+
if (total_length + length + 3 > (uint32_t)size) {
147147
return -1;
148148
}
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);
152150

153151
length = strlen(host);
154-
if (total_length + length + 1 > size) {
152+
if (total_length + length + 3 > (uint32_t)size) {
155153
return -1;
156154
}
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);
160156

161157
length = strlen(referer);
162-
if (total_length + length + 1 > size) {
158+
if (total_length + length + 3 > (uint32_t)size) {
163159
return -1;
164160
}
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);
168162

169163
length = strlen(uri);
170-
if (total_length + length + 4 > size) {
164+
if (total_length + length + 4 > (uint32_t)size) {
171165
return -1;
172166
}
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);
176168

177169
length = strlen(content_type);
178-
if (total_length + length + 3 > size) {
170+
if (total_length + length + 3 > (uint32_t)size) {
179171
return -1;
180172
}
181-
buffer[total_length] = length;
173+
total_length += variable2ipfix_buffer(buffer + total_length, (uint8_t*) content_type, length);
182174

183-
memcpy(buffer + total_length + 1, content_type, length);
184-
total_length += length + 1;
185175
*(uint16_t *) (buffer + total_length) = ntohs(code);
186176
total_length += 2;
187177

0 commit comments

Comments
 (0)