Text   |  XML   |  ReML   |   Visible Warnings:

Cast Alters Value  at strutil.c:534

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

hex_str_to_bytes

(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/strutil.c)expand/collapse
Show more  
 426  hex_str_to_bytes(const char *hex_str, GByteArray *bytes, gboolean force_separators) {
 427          guint8          val;
 428          const guchar    *p, *q, *r, *s, *punct;
 429          char            four_digits_first_half[3];
 430          char            four_digits_second_half[3];
 431          char            two_digits[3];
 432          char            one_digit[2];
 433   
 434          if (! hex_str || ! bytes) {
 435                  return FALSE;
 436          }
 437          g_byte_array_set_size(bytes, 0);
 438          p = (const guchar *)hex_str;
 439          while (*p) {
 440                  q = p+1;
 441                  r = p+2;
 442                  s = p+3;
 443   
 444                  if (*q && *r && *s
 445                      && isxdigit(*p) && isxdigit(*q) &&
 446                      isxdigit(*r) && isxdigit(*s)) {
 447                          four_digits_first_half[0] = *p;
 448                          four_digits_first_half[1] = *q;
 449                          four_digits_first_half[2] = '\0';
 450                          four_digits_second_half[0] = *r;
 451                          four_digits_second_half[1] = *s;
 452                          four_digits_second_half[2] = '\0';
 453   
 454                          /*
 455                           * Four or more hex digits in a row.
 456                           */
 457                          val = (guint8) strtoul(four_digits_first_half, NULL, 16);
 458                          g_byte_array_append(bytes, &val, 1);
 459                          val = (guint8) strtoul(four_digits_second_half, NULL, 16);
 460                          g_byte_array_append(bytes, &val, 1);
 461   
 462                          punct = s + 1;
 463                          if (*punct) {
 464                                  /*
 465                                   * Make sure the character after 
 466                                   * the forth hex digit is a byte 
 467                                   * separator, i.e. that we don't have 
 468                                   * more than four hex digits, or a
 469                                   * bogus character.
 470                                   */
 471                                  if (is_byte_sep(*punct)) {
 472                                          p = punct + 1;
 473                                          continue;
 474                                  }
 475                                  else if (force_separators) {
 476                                          return FALSE;
 477                                          break;
 478                                  }
 479                          }
 480                          p = punct;
 481                          continue;
 482                  }
 483   
 484                  else if (*q && isxdigit(*p) && isxdigit(*q)) {
 485                          two_digits[0] = *p;
 486                          two_digits[1] = *q;
 487                          two_digits[2] = '\0';
 488   
 489                          /*
 490                           * Two hex digits in a row.
 491                           */
 492                          val = (guint8) strtoul(two_digits, NULL, 16);
 493                          g_byte_array_append(bytes, &val, 1);
 494                          punct = q + 1;
 495                          if (*punct) {
 496                                  /*
 497                                   * Make sure the character after 
 498                                   * the second hex digit is a byte 
 499                                   * separator, i.e. that we don't have 
 500                                   * more than two hex digits, or a
 501                                   * bogus character.
 502                                   */
 503                                  if (is_byte_sep(*punct)) {
 504                                          p = punct + 1;
 505                                          continue;
 506                                  }
 507                                  else if (force_separators) {
 508                                          return FALSE;
 509                                          break;
 510                                  }
 511                          }
 512                          p = punct;
 513                          continue;
 514                  }
 515                  else if (*q && isxdigit(*p) && is_byte_sep(*q)) {
 516                          one_digit[0] = *p;
 517                          one_digit[1] = '\0';
 518   
 519                          /*
 520                           * Only one hex digit (not at the end of the string)
 521                           */
 522                          val = (guint8) strtoul(one_digit, NULL, 16);
 523                          g_byte_array_append(bytes, &val, 1);
 524                          p = q + 1;
 525                          continue;
 526                  }
 527                  else if (!*q && isxdigit(*p)) {
 528                          one_digit[0] = *p;
 529                          one_digit[1] = '\0';
 530   
 531                          /*
 532                           * Only one hex digit (at the end of the string)
 533                           */
 534                          val = (guint8) strtoul(one_digit, NULL, 16);
 535                          g_byte_array_append(bytes, &val, 1);
 536                          p = q;
 537                          continue;
Show more  




Change Warning 1104.29762 : Cast Alters Value

Because they are very similar, this warning shares annotations with warning 1104.29764.

Priority:
State:
Finding:
Owner:
Note: