Text   |  XML   |  ReML   |   Visible Warnings:

Null Test After Dereference  at tshark.c:563

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

add_decode_as

(/home/sate/Testcases/c/cve/wireshark-1.2.0/tshark.c)expand/collapse
Show more  
 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    /* The following code will allocate and copy the command-line options in a string pointed by decoded_param */
 452   
 453    g_assert(cl_param);
 454    decoded_param = g_strdup(cl_param);
 455    g_assert(decoded_param);
 456   
 457   
 458    /* The lines below will parse this string (modifying it) to extract all 
 459      necessary information.  Note that decoded_param is still needed since
 460      strings are not copied - we just save pointers. */
 461   
 462    /* This section extracts a layer type (table_name) from decoded_param */
 463    table_name = decoded_param; /* Layer type string starts from beginning */
 464   
 465    remaining_param = strchr(table_name, '=');
 466    if (remaining_param == NULL) {
 467      cmdarg_err("Parameter \"%s\" doesn't follow the template \"%s\"", cl_param, decode_as_arg_template);
 468      /* If the argument does not follow the template, carry on anyway to check 
 469         if the table name is at least correct.  If remaining_param is NULL,
 470         we'll exit anyway further down */
 471    }
 472    else {
 473      *remaining_param = '\0'; /* Terminate the layer type string (table_name) where '=' was detected */
 474    }
 475   
 476    /* Remove leading and trailing spaces from the table name */
 477    while ( table_name[0] == ' ' )
 478      table_name++;
 479    while ( table_name[strlen(table_name) - 1] == ' ' )
 480      table_name[strlen(table_name) - 1] = '\0'; /* Note: if empty string, while loop will eventually exit */
 481   
 482  /* The following part searches a table matching with the layer type specified */
 483    table_matching = NULL;
 484   
 485  /* Look for the requested table */
 486    if ( !(*(table_name)) ) { /* Is the table name empty, if so, don't even search for anything, display a message */
 487      cmdarg_err("No layer type specified"); /* Note, we don't exit here, but table_matching will remain NULL, so we exit below */
 488    }
 489    else {
 490      table_matching = find_dissector_table(table_name);
 491      if (!table_matching) {
 492        cmdarg_err("Unknown layer type -- %s", table_name); /* Note, we don't exit here, but table_matching will remain NULL, so we exit below */
 493      }
 494    }
 495   
 496    if (!table_matching) {
 497      /* Display a list of supported layer types to help the user, if the
 498         specified layer type was not found */
 499      cmdarg_err("Valid layer types are:");
 500      fprint_all_layer_types(stderr);
 501    }
 502    if (remaining_param == NULL || !table_matching) {
 503      /* Exit if the layer type was not found, or if no '=' separator was found 
 504         (see above) */
 505      g_free(decoded_param);
 506      return FALSE;
 507    }
 508   
 509    if (*(remaining_param + 1) != '=') { /* Check for "==" and not only '=' */
 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++; /* Move to the second '=' */
 514      *remaining_param = '\0'; /* Remove the second '=' */
 515    }
 516    remaining_param++; /* Position after the layer type string */
 517   
 518    /* This section extracts a selector value (selector_str) from decoded_param */
 519   
 520    selector_str = remaining_param; /* Next part starts with the selector number */
 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      /* If the argument does not follow the template, carry on anyway to check 
 526         if the selector value is at least correct.  If remaining_param is NULL,
 527         we'll exit anyway further down */
 528    }
 529    else {
 530      *remaining_param = '\0'; /* Terminate the selector number string (selector_str) where ',' was detected */
 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      /* The selector for this table is an unsigned number.  Parse it as such.
 542         There's no need to remove leading and trailing spaces from the
 543         selector number string, because sscanf will do that for us. */
 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      /* The selector for this table is a string. */
 555      break;
 556   
 557    default:
 558      /* There are currently no dissector tables with any types other
 559         than the ones listed above. */
 560      g_assert_not_reached();
 561    }
 562   
 563    if (remaining_param == NULL) {
 564      /* Exit if no ',' separator was found (see above) */
 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++; /* Position after the selector number string */
 572   
 573    /* This section extracts a protocol filter name (dissector_str) from decoded_param */
 574   
 575    dissector_str = remaining_param; /* All the rest of the string is the dissector (decode as protocol) name */
 576   
 577    /* Remove leading and trailing spaces from the dissector name */
 578    while ( dissector_str[0] == ' ' )
 579      dissector_str++;
 580    while ( dissector_str[strlen(dissector_str) - 1] == ' ' )
 581      dissector_str[strlen(dissector_str) - 1] = '\0'; /* Note: if empty string, while loop will eventually exit */
 582   
 583    dissector_matching = NULL;
 584   
 585    /* We now have a pointer to the handle for the requested table inside the variable table_matching */
 586    if ( ! (*dissector_str) ) { /* Is the dissector name empty, if so, don't even search for a matching dissector and display all dissectors found for the selected table */
 587      cmdarg_err("No protocol name specified"); /* Note, we don't exit here, but dissector_matching will remain NULL, so we exit below */
 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); /* Go and perform the search for this dissector in the this table's dissectors' names and shortnames */
 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        /* OK, check whether the problem is that there isn't any such
 604           protocol, or that there is but it's not specified as a protocol 
 605           that's valid for that dissector table.
 606           Note, we don't exit here, but dissector_matching will remain NULL,
 607           so we exit below */
 608        if (proto_get_id_by_filter_name(dissector_str) == -1) {
 609          /* No such protocol */
 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  /* This is the end of the code that parses the command-line options.
 626     All information is now stored in the variables:
 627     table_name
 628     selector
 629     dissector_matching
 630     The above variables that are strings are still pointing to areas within 
 631     decoded_parm.  decoded_parm thus still needs to be kept allocated in
 632     until we stop needing these variables 
 633     decoded_param will be deallocated at each exit point of this function */
 634   
 635   
 636    /* We now have a pointer to the handle for the requested dissector
 637       (requested protocol) inside the variable dissector_matching */
 638    switch (dissector_table_selector_type) {
 639   
 640    case FT_UINT8:
 641    case FT_UINT16:
 642    case FT_UINT24:
 643    case FT_UINT32:
 644      /* The selector for this table is an unsigned number. */
 645      dissector_change(table_name, selector, dissector_matching);
 646      break;
 647   
 648    case FT_STRING:
 649    case FT_STRINGZ:
 650    case FT_EBCDIC:
 651      /* The selector for this table is a string. */
 652      dissector_change_string(table_name, selector_str, dissector_matching);
 653      break;
 654   
 655    default:
 656      /* There are currently no dissector tables with any types other
 657         than the ones listed above. */
 658      g_assert_not_reached();
 659    }
 660    g_free(decoded_param); /* "Decode As" rule has been succesfully added */
 661    return TRUE;
 662  }
Show more  




Change Warning 12277.30242 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: