(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-index/mail-cache-lookup.c) |
| |
| 453 | | | (struct mail_cache_view *view, string_t *dest, |
| 454 | | | uint32_t seq, unsigned int field_idxs[], |
| 455 | | | unsigned int fields_count) |
| 456 | | | { |
| 457 | | | struct mail_cache *cache = view->cache; |
| 458 | | | struct mail_cache_lookup_iterate_ctx iter; |
| 459 | | | struct mail_cache_iterate_field field; |
| 460 | | | struct ctx; |
| 461 | | | struct *lines; |
| 462 | | | const unsigned char *p, *start, *end; |
| 463 | | | uint8_t *field_state; |
| 464 | | | unsigned int i, count, max_field = 0; |
| 465 | | | size_t hdr_size; |
| 466 | | | uint8_t want = HDR_FIELD_STATE_WANT; |
| 467 | | | buffer_t *buf; |
| 468 | | | int ret; |
| 469 | | | |
| 470 | | | if (fields_count == 0) |
| 471 | | | return 1; |
| 472 | | | |
| 473 | | | if (!view->cache->opened) |
| 474 | | | (void)mail_cache_open_and_verify(view->cache); |
| 475 | | | |
| 476 | | | |
| 477 | | | |
| 478 | | | for (i = 0; i < fields_count; i++) |
| 479 | | | mail_cache_decision_state_update(view, seq, field_idxs[i]); |
| 480 | | | |
| 481 | | | |
| 482 | | | buf = buffer_create_dynamic(pool_datastack_create(), 32); |
Ignored Return Value
The return value of buffer_create_dynamic() is never checked in the highlighted execution scenario. - If the return value can indicate an error, the error will be ignored if the highlighted code executes.
- The return value of buffer_create_dynamic() is checked 98% of the time in this project. CodeSonar is configured to enforce Ignored Return Value checks for any function whose return value is checked at least 96% of the time, unless the function is used fewer than 20 times. (To modify these thresholds, use configuration file parameters RETURN_CHECKER_SAMPLE_SIZE and RETURN_CHECKER_RATIO. To exempt buffer_create_dynamic() from the Ignored Return Value check, use configuration file parameter RETURN_CHECKER_IGNORED_FUNCS).
Show: All events | Only primary events |
|
| 483 | | | for (i = 0; i < fields_count; i++) { |
| 484 | | | if (!mail_cache_file_has_field(cache, field_idxs[i])) |
| 485 | | | return 0; |
| 486 | | | |
| 487 | | | if (field_idxs[i] > max_field) |
| 488 | | | max_field = field_idxs[i]; |
| 489 | | | |
| 490 | | | buffer_write(buf, field_idxs[i], &want, 1); |
| 491 | | | } |
| 492 | | | field_state = buffer_get_modifiable_data(buf, NULL); |
| 493 | | | |
| 494 | | | |
| 495 | | | memset(&ctx, 0, sizeof(ctx)); |
| 496 | | | ctx.view = view; |
| 497 | | | t_array_init(&ctx.lines, 32);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/array.h |
| |
39 | #define t_array_init(array, init_count) \ |
40 | p_array_init(array, pool_datastack_create(), init_count) |
| |
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/array.h |
| |
35 | #define p_array_init(array, pool, init_count) \ |
36 | array_create(array, pool, sizeof(**(array)->v), init_count) |
| |
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/array.h |
| |
75 | #define array_create(array, pool, element_size, init_count) \ |
76 | array_create_i(&(array)->arr, pool, element_size, init_count) |
| |
|
| 498 | | | |
| 499 | | | mail_cache_lookup_iter_init(view, seq, &iter); |
| 500 | | | while ((ret = mail_cache_lookup_iter_next(&iter, &field)) > 0) { |
| 501 | | | if (field.field_idx > max_field || |
| 502 | | | field_state[field.field_idx] != HDR_FIELD_STATE_WANT) { |
| 503 | | | |
| 504 | | | } else { |
| 505 | | | field_state[field.field_idx] = HDR_FIELD_STATE_SEEN; |
| 506 | | | (&ctx, &field); |
| 507 | | | } |
| 508 | | | |
| 509 | | | } |
| 510 | | | if (ret < 0) |
| 511 | | | return -1; |
| 512 | | | |
| 513 | | | |
| 514 | | | for (i = 0; i <= max_field; i++) { |
| 515 | | | if (field_state[i] == HDR_FIELD_STATE_WANT) |
| 516 | | | return 0; |
| 517 | | | } |
| 518 | | | |
| 519 | | | |
| 520 | | | |
| 521 | | | lines = array_get_modifiable(&ctx.lines, &count);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/array.h |
| |
174 | #define array_get_modifiable(array, count) \ |
175 | ARRAY_TYPE_CAST_MODIFIABLE(array) \ |
176 | array_get_modifiable_i(&(array)->arr, count) |
| |
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/array.h |
| |
45 | # define ARRAY_TYPE_CAST_MODIFIABLE(array) \ |
46 | (typeof(*(array)->v_modifiable)) |
| |
|
| 522 | | | qsort(lines, count, sizeof(*lines), ); |
| 523 | | | |
| 524 | | | |
| 525 | | | for (i = 0; i < count; i++) { |
| 526 | | | start = CONST_PTR_OFFSET(cache->data, lines[i].data->offset);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/macros.h |
| |
29 | #define CONST_PTR_OFFSET(ptr, offset) \ |
30 | ((const void *) (((const unsigned char *) (ptr)) + (offset))) |
| |
|
| 527 | | | end = start + lines[i].data->data_size; |
| 528 | | | |
| 529 | | | |
| 530 | | | for (p = start; p != end; p++) { |
| 531 | | | if (*p == '\n' && |
| 532 | | | (p+1 == end || (p[1] != ' ' && p[1] != '\t'))) { |
| 533 | | | p++; |
| 534 | | | break; |
| 535 | | | } |
| 536 | | | } |
| 537 | | | hdr_size = (size_t)(p - start); |
| 538 | | | buffer_append(dest, start, hdr_size); |
| 539 | | | |
| 540 | | | |
| 541 | | | |
| 542 | | | lines[i].data->offset += hdr_size; |
| 543 | | | lines[i].data->data_size -= hdr_size; |
| 544 | | | } |
| 545 | | | return 1; |
| 546 | | | } |
| |