(/home/sate/Testcases/c/cve/wireshark-1.2.0/tshark.c) |
| |
| 438 | | | add_decode_as(const gchar *cl_param) |
| 439 | | | { |
| 440 | | | gchar *table_name; |
| 441 | | | guint32 selector; |
| 442 | | | gchar *decoded_param; |
| 443 | | | gchar *remaining_param; |
| 444 | | | gchar *selector_str; |
| 445 | | | gchar *dissector_str; |
| 446 | | | dissector_handle_t dissector_matching; |
| 447 | | | dissector_table_t table_matching; |
| 448 | | | ftenum_t dissector_table_selector_type; |
| 449 | | | struct protocol_name_search user_protocol_name; |
| 450 | | | |
| 451 | | | |
| 452 | | | |
| 453 | | | g_assert(cl_param);
x /usr/include/glib-2.0/glib/gtestutils.h |
| |
74 | #define g_assert(expr) do { if G_LIKELY (expr) ; else \ |
75 | g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ |
76 | #expr); } while (0) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
277 | #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
268 | #define _G_BOOLEAN_EXPR(expr) \ |
269 | __extension__ ({ \ |
270 | int _g_boolean_var_; \ |
271 | if (expr) \ |
272 | _g_boolean_var_ = 1; \ |
273 | else \ |
274 | _g_boolean_var_ = 0; \ |
275 | _g_boolean_var_; \ |
276 | }) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
160 | # define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__)) |
| |
|
Event 1:
Taking true branch. cl_param evaluates to true.
hide
Event 2:
Skipping " if". __builtin_expect(...) evaluates to true.
hide
Event 3:
Leaving loop. 0 evaluates to false.
hide
|
|
| 454 | | | decoded_param = g_strdup(cl_param); |
| 455 | | | g_assert(decoded_param);
x /usr/include/glib-2.0/glib/gtestutils.h |
| |
74 | #define g_assert(expr) do { if G_LIKELY (expr) ; else \ |
75 | g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ |
76 | #expr); } while (0) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
277 | #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
268 | #define _G_BOOLEAN_EXPR(expr) \ |
269 | __extension__ ({ \ |
270 | int _g_boolean_var_; \ |
271 | if (expr) \ |
272 | _g_boolean_var_ = 1; \ |
273 | else \ |
274 | _g_boolean_var_ = 0; \ |
275 | _g_boolean_var_; \ |
276 | }) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
160 | # define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__)) |
| |
|
Event 5:
Taking true branch. decoded_param evaluates to true.
hide
Event 6:
Skipping " if". __builtin_expect(...) evaluates to true.
hide
Event 7:
Leaving loop. 0 evaluates to false.
hide
|
|
| 456 | | | |
| 457 | | | |
| 458 | | | |
| 459 | | | |
| 460 | | | |
| 461 | | | |
| 462 | | | |
| 463 | | | table_name = decoded_param; |
| 464 | | | |
| 465 | | | remaining_param = strchr(table_name, '='); |
| 466 | | | if (remaining_param == NULL) { |
Event 8:
Taking false branch. remaining_param == (void *)0 evaluates to false.
hide
|
|
| 467 | | | cmdarg_err("Parameter \"%s\" doesn't follow the template \"%s\"", cl_param, decode_as_arg_template); |
| 468 | | | |
| 469 | | | |
| 470 | | | |
| 471 | | | } |
| 472 | | | else { |
| 473 | | | *remaining_param = '\0'; |
| 474 | | | } |
| 475 | | | |
| 476 | | | |
| 477 | | | while ( table_name[0] == ' ' ) |
Event 10:
Leaving loop. table_name[0] == 32 evaluates to false.
hide
|
|
| 478 | | | table_name++; |
| 479 | | | while ( table_name[strlen(table_name) - 1] == ' ' ) |
Event 11:
Leaving loop. table_name[strlen(...) - 1] == 32 evaluates to false.
hide
|
|
| 480 | | | table_name[strlen(table_name) - 1] = '\0'; |
| 481 | | | |
| 482 | | | |
| 483 | | | table_matching = NULL; |
| 484 | | | |
| 485 | | | |
| 486 | | | if ( !(*(table_name)) ) { |
Event 12:
Taking false branch. *table_name evaluates to true.
hide
|
|
| 487 | | | cmdarg_err("No layer type specified"); |
| 488 | | | } |
| 489 | | | else { |
| 490 | | | table_matching = find_dissector_table(table_name); |
| 491 | | | if (!table_matching) { |
Event 13:
Skipping " if". table_matching evaluates to true.
hide
|
|
| 492 | | | cmdarg_err("Unknown layer type -- %s", table_name); |
| 493 | | | } |
| 494 | | | } |
| 495 | | | |
| 496 | | | if (!table_matching) { |
Event 14:
Skipping " if". table_matching evaluates to true.
hide
|
|
| 497 | | | |
| 498 | | | |
| 499 | | | cmdarg_err("Valid layer types are:"); |
| 500 | | | fprint_all_layer_types(stderr); |
| 501 | | | } |
| 502 | | | if (remaining_param == NULL || !table_matching) { |
Null Test After Dereference
This code tests the nullness of remaining_param, which has already been dereferenced. - If remaining_param were null, there would have been a prior null pointer dereference at tshark.c:473, and potentially at other locations as well.
- Either this test is redundant, or the earlier dereference(s) should be guarded by a similar test.
The issue can occur if the highlighted code executes. See related event 9. Show: All events | Only primary events |
|
| 503 | | | |
| 504 | | | |
| 505 | | | g_free(decoded_param); |
| 506 | | | return FALSE; |
| 507 | | | } |
| 508 | | | |
| 509 | | | if (*(remaining_param + 1) != '=') { |
| 510 | | | cmdarg_err("WARNING: -d requires \"==\" instead of \"=\". Option will be treated as \"%s==%s\"", table_name, remaining_param + 1); |
| 511 | | | } |
| 512 | | | else { |
| 513 | | | remaining_param++; |
| 514 | | | *remaining_param = '\0'; |
| 515 | | | } |
| 516 | | | remaining_param++; |
| 517 | | | |
| 518 | | | |
| 519 | | | |
| 520 | | | selector_str = remaining_param; |
| 521 | | | |
| 522 | | | remaining_param = strchr(selector_str, ','); |
| 523 | | | if (remaining_param == NULL) { |
| 524 | | | cmdarg_err("Parameter \"%s\" doesn't follow the template \"%s\"", cl_param, decode_as_arg_template); |
| 525 | | | |
| 526 | | | |
| 527 | | | |
| 528 | | | } |
| 529 | | | else { |
| 530 | | | *remaining_param = '\0'; |
| 531 | | | } |
| 532 | | | |
| 533 | | | dissector_table_selector_type = get_dissector_table_selector_type(table_name); |
| 534 | | | |
| 535 | | | switch (dissector_table_selector_type) { |
| 536 | | | |
| 537 | | | case FT_UINT8: |
| 538 | | | case FT_UINT16: |
| 539 | | | case FT_UINT24: |
| 540 | | | case FT_UINT32: |
| 541 | | | |
| 542 | | | |
| 543 | | | |
| 544 | | | if ( sscanf(selector_str, "%u", &selector) != 1 ) { |
| 545 | | | cmdarg_err("Invalid selector number \"%s\"", selector_str); |
| 546 | | | g_free(decoded_param); |
| 547 | | | return FALSE; |
| 548 | | | } |
| 549 | | | break; |
| 550 | | | |
| 551 | | | case FT_STRING: |
| 552 | | | case FT_STRINGZ: |
| 553 | | | case FT_EBCDIC: |
| 554 | | | |
| 555 | | | break; |
| 556 | | | |
| 557 | | | default: |
| 558 | | | |
| 559 | | | |
| 560 | | | g_assert_not_reached();
x /usr/include/glib-2.0/glib/gtestutils.h |
| |
73 | #define g_assert_not_reached() do { g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
160 | # define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__)) |
| |
|
| 561 | | | } |
| 562 | | | |
| 563 | | | if (remaining_param == NULL) { |
| 564 | | | |
| 565 | | | cmdarg_err("Valid protocols for layer type \"%s\" are:", table_name); |
| 566 | | | fprint_all_protocols_for_layer_types(stderr, table_name); |
| 567 | | | g_free(decoded_param); |
| 568 | | | return FALSE; |
| 569 | | | } |
| 570 | | | |
| 571 | | | remaining_param++; |
| 572 | | | |
| 573 | | | |
| 574 | | | |
| 575 | | | dissector_str = remaining_param; |
| 576 | | | |
| 577 | | | |
| 578 | | | while ( dissector_str[0] == ' ' ) |
| 579 | | | dissector_str++; |
| 580 | | | while ( dissector_str[strlen(dissector_str) - 1] == ' ' ) |
| 581 | | | dissector_str[strlen(dissector_str) - 1] = '\0'; |
| 582 | | | |
| 583 | | | dissector_matching = NULL; |
| 584 | | | |
| 585 | | | |
| 586 | | | if ( ! (*dissector_str) ) { |
| 587 | | | cmdarg_err("No protocol name specified"); |
| 588 | | | } |
| 589 | | | else { |
| 590 | | | user_protocol_name.nb_match = 0; |
| 591 | | | user_protocol_name.searched_name = dissector_str; |
| 592 | | | user_protocol_name.matched_handle = NULL; |
| 593 | | | |
| 594 | | | dissector_table_foreach_handle(table_name, find_protocol_name_func, &user_protocol_name); |
| 595 | | | |
| 596 | | | if (user_protocol_name.nb_match != 0) { |
| 597 | | | dissector_matching = user_protocol_name.matched_handle; |
| 598 | | | if (user_protocol_name.nb_match > 1) { |
| 599 | | | cmdarg_err("WARNING: Protocol \"%s\" matched %u dissectors, first one will be used", dissector_str, user_protocol_name.nb_match); |
| 600 | | | } |
| 601 | | | } |
| 602 | | | else { |
| 603 | | | |
| 604 | | | |
| 605 | | | |
| 606 | | | |
| 607 | | | |
| 608 | | | if (proto_get_id_by_filter_name(dissector_str) == -1) { |
| 609 | | | |
| 610 | | | cmdarg_err("Unknown protocol -- \"%s\"", dissector_str); |
| 611 | | | } else { |
| 612 | | | cmdarg_err("Protocol \"%s\" isn't valid for layer type \"%s\"", |
| 613 | | | dissector_str, table_name); |
| 614 | | | } |
| 615 | | | } |
| 616 | | | } |
| 617 | | | |
| 618 | | | if (!dissector_matching) { |
| 619 | | | cmdarg_err("Valid protocols for layer type \"%s\" are:", table_name); |
| 620 | | | fprint_all_protocols_for_layer_types(stderr, table_name); |
| 621 | | | g_free(decoded_param); |
| 622 | | | return FALSE; |
| 623 | | | } |
| 624 | | | |
| 625 | | | |
| 626 | | | |
| 627 | | | |
| 628 | | | |
| 629 | | | |
| 630 | | | |
| 631 | | | |
| 632 | | | |
| 633 | | | |
| 634 | | | |
| 635 | | | |
| 636 | | | |
| 637 | | | |
| 638 | | | switch (dissector_table_selector_type) { |
| 639 | | | |
| 640 | | | case FT_UINT8: |
| 641 | | | case FT_UINT16: |
| 642 | | | case FT_UINT24: |
| 643 | | | case FT_UINT32: |
| 644 | | | |
| 645 | | | dissector_change(table_name, selector, dissector_matching); |
| 646 | | | break; |
| 647 | | | |
| 648 | | | case FT_STRING: |
| 649 | | | case FT_STRINGZ: |
| 650 | | | case FT_EBCDIC: |
| 651 | | | |
| 652 | | | dissector_change_string(table_name, selector_str, dissector_matching); |
| 653 | | | break; |
| 654 | | | |
| 655 | | | default: |
| 656 | | | |
| 657 | | | |
| 658 | | | g_assert_not_reached();
x /usr/include/glib-2.0/glib/gtestutils.h |
| |
73 | #define g_assert_not_reached() do { g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
160 | # define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__)) |
| |
|
| 659 | | | } |
| 660 | | | g_free(decoded_param); |
| 661 | | | return TRUE; |
| 662 | | | } |
| |