(/home/sate/Testcases/c/cve/wireshark-1.2.0/color_filters.c) |
| |
| 465 | | | read_filters_file(FILE *f, gpointer user_data) |
| 466 | | | { |
| 467 | | | #define INIT_BUF_SIZE 128 |
| 468 | | | gchar *name = NULL; |
| 469 | | | gchar *filter_exp = NULL; |
| 470 | | | guint32 name_len = INIT_BUF_SIZE; |
| 471 | | | guint32 filter_exp_len = INIT_BUF_SIZE; |
| 472 | | | guint32 i = 0; |
| 473 | | | gint32 c; |
| 474 | | | guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; |
| 475 | | | gboolean disabled = FALSE; |
| 476 | | | gboolean skip_end_of_line = FALSE; |
| 477 | | | |
| 478 | | | name = g_malloc(name_len + 1); |
| 479 | | | filter_exp = g_malloc(filter_exp_len + 1); |
| 480 | | | |
| 481 | | | while (1) { |
Event 3:
Entering loop body. 1 evaluates to true.
hide
|
|
| 482 | | | |
| 483 | | | if (skip_end_of_line) { |
Event 4:
Skipping " if". skip_end_of_line evaluates to false.
hide
|
|
| 484 | | | do { |
| 485 | | | c = getc(f); |
| 486 | | | } while (c != EOF && c != '\n'); |
| 487 | | | if (c == EOF) |
| 488 | | | break; |
| 489 | | | disabled = FALSE; |
| 490 | | | skip_end_of_line = FALSE; |
| 491 | | | } |
| 492 | | | |
| 493 | | | while ((c = getc(f)) != EOF && isspace(c)) { |
| 494 | | | if (c == '\n') { |
| 495 | | | continue; |
| 496 | | | } |
| 497 | | | } |
| 498 | | | |
| 499 | | | if (c == EOF) |
Event 6:
Skipping " if". c == -1 evaluates to false.
hide
|
|
| 500 | | | break; |
| 501 | | | |
| 502 | | | if (c == '!') { |
Event 7:
Skipping " if". c == 33 evaluates to false.
hide
|
|
| 503 | | | disabled = TRUE; |
| 504 | | | continue; |
| 505 | | | } |
| 506 | | | |
| 507 | | | |
| 508 | | | if (c != '@') { |
Event 8:
Skipping " if". c != 64 evaluates to false.
hide
|
|
| 509 | | | skip_end_of_line = TRUE; |
| 510 | | | continue; |
| 511 | | | } |
| 512 | | | |
| 513 | | | |
| 514 | | | |
| 515 | | | |
| 516 | | | |
| 517 | | | |
| 518 | | | |
| 519 | | | i = 0; |
| 520 | | | while (1) { |
Event 10:
During loop iterations, i is set to i + 1, which evaluates to a potentially dangerous value [ ?potentially dangerous: the value cannot be determined and may come from program input]. - This determines the position accessed in the buffer during the buffer overrun later.
hide
Event 11:
Continuing from loop body. Entering loop body. 1 evaluates to true.
hide
|
|
| 521 | | | c = getc(f); |
| 522 | | | if (c == EOF || c == '@') |
Event 12:
Skipping " if". - c == -1 evaluates to false.
- c == 64 evaluates to false.
hide
|
|
| 523 | | | break; |
| 524 | | | if (i >= name_len) { |
Event 13:
Taking true branch. i >= name_len evaluates to true.
hide
|
|
| 525 | | | |
| 526 | | | name_len *= 2; |
| 527 | | | name = g_realloc(name, name_len + 1); |
Event 14:
g_realloc is an Undefined Function.
hide
Event 15:
name is set to g_realloc(name, name_len + 1). - This points to the buffer that will be overrun later.
hide
|
|
| 528 | | | } |
| 529 | | | name[i++] = c; |
Buffer Overrun
This code could write past the end of the buffer pointed to by name. - name evaluates to g_realloc(name, name_len + 1) from color_filters.c:527.
- The code writes 1 byte starting at offset i++ from the beginning of the buffer pointed to by name.
- The number of bytes written could exceed the number of allocated bytes beyond that offset.
- i++ evaluates to the value assigned to i at color_filters.c:520, plus 1, which is bounded below by 1. See related event 10.
- The capacity of the buffer pointed to by name, in bytes, is the capacity of the buffer pointed to by g_realloc(name, name_len + 1) at color_filters.c:527. See related event 15.
- If i++ plus 1 is higher than the capacity of the buffer pointed to by g_realloc(name, name_len + 1) at color_filters.c:527, an overrun will occur. The analysis cannot rule out this possibility, so has issued this warning.
The issue can occur if the highlighted code executes. See related events 10 and 15. Show: All events | Only primary events |
|
| |