(/home/sate/Testcases/c/cve/wireshark-1.2.0/epan/strutil.c) |
| |
| 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 | | | |
| 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 | | | |
| 466 | | | |
| 467 | | | |
| 468 | | | |
| 469 | | | |
| 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 | | | |
| 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 | | | |
| 498 | | | |
| 499 | | | |
| 500 | | | |
| 501 | | | |
| 502 | | | |
| 503 | | | if (is_byte_sep(*punct)) { |
| 504 | | | p = punct + 1; |
| 505 | | | continue; |
| 506 | | | } |
| 507 | | | else if (force_separators) { |
| 508 | | | return FALSE; |
| 509 | | | break; |
Unreachable Control Flow
The highlighted code will not execute under any circumstances. This may be because of: |
|
| 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 | | | |
| 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 | | | |
| 533 | | | |
| 534 | | | val = (guint8) strtoul(one_digit, NULL, 16); |
| 535 | | | g_byte_array_append(bytes, &val, 1); |
| 536 | | | p = q; |
| 537 | | | continue; |
| 538 | | | } |
| 539 | | | else { |
| 540 | | | return FALSE; |
| 541 | | | } |
| 542 | | | } |
| 543 | | | return TRUE; |
| 544 | | | } |
| |