diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-03-10 10:33:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-10 10:33:25 (GMT) |
commit | 5077120a251980b4fafed61b4aa8fa5730a85443 (patch) | |
tree | 8500b8f5dbe774b399cfdc79f5665ba88ef7f255 /plugins/picohttpparser/picohttpparser.c | |
parent | a3de84594104ac87a91e200d569fb57edacca928 (diff) | |
parent | 269718094177fb8a7e3d3005d1310495009fe8c4 (diff) | |
download | monitoring-plugins-5077120a251980b4fafed61b4aa8fa5730a85443.tar.gz |
Merge branch 'master' into master
Diffstat (limited to 'plugins/picohttpparser/picohttpparser.c')
-rw-r--r-- | plugins/picohttpparser/picohttpparser.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/plugins/picohttpparser/picohttpparser.c b/plugins/picohttpparser/picohttpparser.c index 74ccc3e..d9680b7 100644 --- a/plugins/picohttpparser/picohttpparser.c +++ b/plugins/picohttpparser/picohttpparser.c | |||
@@ -242,7 +242,7 @@ static const char *is_complete(const char *buf, const char *buf_end, size_t last | |||
242 | } while (0) | 242 | } while (0) |
243 | 243 | ||
244 | /* returned pointer is always within [buf, buf_end), or null */ | 244 | /* returned pointer is always within [buf, buf_end), or null */ |
245 | static const char *parse_http_version(const char *buf, const char *buf_end, int *minor_version, int *ret) | 245 | static const char *parse_http_version(const char *buf, const char *buf_end, int *major_version, int *minor_version, int *ret) |
246 | { | 246 | { |
247 | /* we want at least [HTTP/1.<two chars>] to try to parse */ | 247 | /* we want at least [HTTP/1.<two chars>] to try to parse */ |
248 | if (buf_end - buf < 9) { | 248 | if (buf_end - buf < 9) { |
@@ -254,9 +254,13 @@ static const char *parse_http_version(const char *buf, const char *buf_end, int | |||
254 | EXPECT_CHAR_NO_CHECK('T'); | 254 | EXPECT_CHAR_NO_CHECK('T'); |
255 | EXPECT_CHAR_NO_CHECK('P'); | 255 | EXPECT_CHAR_NO_CHECK('P'); |
256 | EXPECT_CHAR_NO_CHECK('/'); | 256 | EXPECT_CHAR_NO_CHECK('/'); |
257 | EXPECT_CHAR_NO_CHECK('1'); | 257 | PARSE_INT(major_version, 1); |
258 | EXPECT_CHAR_NO_CHECK('.'); | 258 | if (*major_version == 1) { |
259 | PARSE_INT(minor_version, 1); | 259 | EXPECT_CHAR_NO_CHECK('.'); |
260 | PARSE_INT(minor_version, 1); | ||
261 | } else { | ||
262 | *minor_version = 0; | ||
263 | } | ||
260 | return buf; | 264 | return buf; |
261 | } | 265 | } |
262 | 266 | ||
@@ -339,7 +343,7 @@ static const char *parse_headers(const char *buf, const char *buf_end, struct ph | |||
339 | } | 343 | } |
340 | 344 | ||
341 | static const char *parse_request(const char *buf, const char *buf_end, const char **method, size_t *method_len, const char **path, | 345 | static const char *parse_request(const char *buf, const char *buf_end, const char **method, size_t *method_len, const char **path, |
342 | size_t *path_len, int *minor_version, struct phr_header *headers, size_t *num_headers, | 346 | size_t *path_len, int *major_version, int *minor_version, struct phr_header *headers, size_t *num_headers, |
343 | size_t max_headers, int *ret) | 347 | size_t max_headers, int *ret) |
344 | { | 348 | { |
345 | /* skip first empty line (some clients add CRLF after POST content) */ | 349 | /* skip first empty line (some clients add CRLF after POST content) */ |
@@ -364,7 +368,7 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha | |||
364 | *ret = -1; | 368 | *ret = -1; |
365 | return NULL; | 369 | return NULL; |
366 | } | 370 | } |
367 | if ((buf = parse_http_version(buf, buf_end, minor_version, ret)) == NULL) { | 371 | if ((buf = parse_http_version(buf, buf_end, major_version, minor_version, ret)) == NULL) { |
368 | return NULL; | 372 | return NULL; |
369 | } | 373 | } |
370 | if (*buf == '\015') { | 374 | if (*buf == '\015') { |
@@ -381,7 +385,7 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha | |||
381 | } | 385 | } |
382 | 386 | ||
383 | int phr_parse_request(const char *buf_start, size_t len, const char **method, size_t *method_len, const char **path, | 387 | int phr_parse_request(const char *buf_start, size_t len, const char **method, size_t *method_len, const char **path, |
384 | size_t *path_len, int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len) | 388 | size_t *path_len, int *major_version, int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len) |
385 | { | 389 | { |
386 | const char *buf = buf_start, *buf_end = buf_start + len; | 390 | const char *buf = buf_start, *buf_end = buf_start + len; |
387 | size_t max_headers = *num_headers; | 391 | size_t max_headers = *num_headers; |
@@ -391,6 +395,7 @@ int phr_parse_request(const char *buf_start, size_t len, const char **method, si | |||
391 | *method_len = 0; | 395 | *method_len = 0; |
392 | *path = NULL; | 396 | *path = NULL; |
393 | *path_len = 0; | 397 | *path_len = 0; |
398 | *major_version = -1; | ||
394 | *minor_version = -1; | 399 | *minor_version = -1; |
395 | *num_headers = 0; | 400 | *num_headers = 0; |
396 | 401 | ||
@@ -400,7 +405,7 @@ int phr_parse_request(const char *buf_start, size_t len, const char **method, si | |||
400 | return r; | 405 | return r; |
401 | } | 406 | } |
402 | 407 | ||
403 | if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len, minor_version, headers, num_headers, max_headers, | 408 | if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len, major_version, minor_version, headers, num_headers, max_headers, |
404 | &r)) == NULL) { | 409 | &r)) == NULL) { |
405 | return r; | 410 | return r; |
406 | } | 411 | } |
@@ -408,11 +413,11 @@ int phr_parse_request(const char *buf_start, size_t len, const char **method, si | |||
408 | return (int)(buf - buf_start); | 413 | return (int)(buf - buf_start); |
409 | } | 414 | } |
410 | 415 | ||
411 | static const char *parse_response(const char *buf, const char *buf_end, int *minor_version, int *status, const char **msg, | 416 | static const char *parse_response(const char *buf, const char *buf_end, int *major_version, int *minor_version, int *status, const char **msg, |
412 | size_t *msg_len, struct phr_header *headers, size_t *num_headers, size_t max_headers, int *ret) | 417 | size_t *msg_len, struct phr_header *headers, size_t *num_headers, size_t max_headers, int *ret) |
413 | { | 418 | { |
414 | /* parse "HTTP/1.x" */ | 419 | /* parse "HTTP/1.x" */ |
415 | if ((buf = parse_http_version(buf, buf_end, minor_version, ret)) == NULL) { | 420 | if ((buf = parse_http_version(buf, buf_end, major_version, minor_version, ret)) == NULL) { |
416 | return NULL; | 421 | return NULL; |
417 | } | 422 | } |
418 | /* skip space */ | 423 | /* skip space */ |
@@ -451,13 +456,14 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min | |||
451 | return parse_headers(buf, buf_end, headers, num_headers, max_headers, ret); | 456 | return parse_headers(buf, buf_end, headers, num_headers, max_headers, ret); |
452 | } | 457 | } |
453 | 458 | ||
454 | int phr_parse_response(const char *buf_start, size_t len, int *minor_version, int *status, const char **msg, size_t *msg_len, | 459 | int phr_parse_response(const char *buf_start, size_t len, int *major_version, int *minor_version, int *status, const char **msg, size_t *msg_len, |
455 | struct phr_header *headers, size_t *num_headers, size_t last_len) | 460 | struct phr_header *headers, size_t *num_headers, size_t last_len) |
456 | { | 461 | { |
457 | const char *buf = buf_start, *buf_end = buf + len; | 462 | const char *buf = buf_start, *buf_end = buf + len; |
458 | size_t max_headers = *num_headers; | 463 | size_t max_headers = *num_headers; |
459 | int r; | 464 | int r; |
460 | 465 | ||
466 | *major_version = -1; | ||
461 | *minor_version = -1; | 467 | *minor_version = -1; |
462 | *status = 0; | 468 | *status = 0; |
463 | *msg = NULL; | 469 | *msg = NULL; |
@@ -470,7 +476,7 @@ int phr_parse_response(const char *buf_start, size_t len, int *minor_version, in | |||
470 | return r; | 476 | return r; |
471 | } | 477 | } |
472 | 478 | ||
473 | if ((buf = parse_response(buf, buf_end, minor_version, status, msg, msg_len, headers, num_headers, max_headers, &r)) == NULL) { | 479 | if ((buf = parse_response(buf, buf_end, major_version, minor_version, status, msg, msg_len, headers, num_headers, max_headers, &r)) == NULL) { |
474 | return r; | 480 | return r; |
475 | } | 481 | } |
476 | 482 | ||