(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/pcapng.c) |
| |
| 321 | | | (FILE_T fh, *bh, |
| 322 | | | pcapng_t *pn, wtapng_block_t *wblock, int *err, |
| 323 | | | gchar **err_info _U_) |
| 324 | | | { |
| 325 | | | int bytes_read; |
| 326 | | | int block_read; |
| 327 | | | int to_read; |
| 328 | | | shb; |
| 329 | | | oh; |
| 330 | | | char option_content[100]; |
| 331 | | | |
| 332 | | | |
| 333 | | | |
| 334 | | | errno = WTAP_ERR_CANT_READ; |
| 335 | | | bytes_read = file_read(&shb, 1, sizeof shb, fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 336 | | | if (bytes_read != sizeof shb) { |
| 337 | | | *err = file_error(fh); |
| 338 | | | if (*err != 0) |
| 339 | | | return -1; |
| 340 | | | return 0; |
| 341 | | | } |
| 342 | | | block_read = bytes_read; |
| 343 | | | |
| 344 | | | |
| 345 | | | switch(shb.magic) { |
| 346 | | | case(0x1A2B3C4D): |
| 347 | | | |
| 348 | | | pn->byte_swapped = FALSE; |
| 349 | | | pn->version_major = shb.version_major; |
| 350 | | | pn->version_minor = shb.version_minor; |
| 351 | | | |
| 352 | | | pcapng_debug3(": SHB (little endian) V%u.%u, len %u", |
| 353 | | | pn->version_major, pn->version_minor, bh->block_total_length); |
| 354 | | | break; |
| 355 | | | case(0x4D3C2B1A): |
| 356 | | | |
| 357 | | | pn->byte_swapped = TRUE; |
| 358 | | | pn->version_major = BSWAP16(shb.version_major); |
| 359 | | | pn->version_minor = BSWAP16(shb.version_minor); |
| 360 | | | |
| 361 | | | |
| 362 | | | bh->block_total_length = BSWAP32(bh->block_total_length);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
297 | #define BSWAP32(x) \ |
298 | ((((x)&0xFF000000)>>24) | \ |
299 | (((x)&0x00FF0000)>>8) | \ |
300 | (((x)&0x0000FF00)<<8) | \ |
301 | (((x)&0x000000FF)<<24)) |
| |
|
| 363 | | | |
| 364 | | | pcapng_debug3(": SHB (big endian) V%u.%u, len %u", |
| 365 | | | pn->version_major, pn->version_minor, bh->block_total_length); |
| 366 | | | break; |
| 367 | | | default: |
| 368 | | | |
| 369 | | | pcapng_debug1(": unknown magic number %u (probably not an pcapng file)", shb.magic); |
| 370 | | | return 0; |
| 371 | | | } |
| 372 | | | |
| 373 | | | |
| 374 | | | if(pn->version_major != 1 || pn->version_minor != 0) { |
| 375 | | | pcapng_debug2(": unknown SHB version %u.%u", |
| 376 | | | pn->version_major, pn->version_minor); |
| 377 | | | return 0; |
| 378 | | | } |
| 379 | | | |
| 380 | | | |
| 381 | | | if(pn->byte_swapped) { |
| 382 | | | wblock->data.section.section_length = BSWAP64(shb.section_length);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
288 | #define BSWAP64(x) \ |
289 | ((((x)&G_GINT64_CONSTANT(0xFF00000000000000U))>>56) | \ |
290 | (((x)&G_GINT64_CONSTANT(0x00FF000000000000U))>>40) | \ |
291 | (((x)&G_GINT64_CONSTANT(0x0000FF0000000000U))>>24) | \ |
292 | (((x)&G_GINT64_CONSTANT(0x000000FF00000000U))>>8) | \ |
293 | (((x)&G_GINT64_CONSTANT(0x00000000FF000000U))<<8) | \ |
294 | (((x)&G_GINT64_CONSTANT(0x0000000000FF0000U))<<24) | \ |
295 | (((x)&G_GINT64_CONSTANT(0x000000000000FF00U))<<40) | \ |
296 | (((x)&G_GINT64_CONSTANT(0x00000000000000FFU))<<56)) |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
x /usr/lib/i386-linux-gnu/glib-2.0/include/glibconfig.h |
| |
55 | #define G_GINT64_CONSTANT(val) (G_GNUC_EXTENSION (val##LL)) |
| |
x /usr/include/glib-2.0/glib/gmacros.h |
| |
47 | # define G_GNUC_EXTENSION __extension__ |
| |
|
| 383 | | | } else { |
| 384 | | | wblock->data.section.section_length = shb.section_length; |
| 385 | | | } |
| 386 | | | |
| 387 | | | |
| 388 | | | wblock->data.section. = NULL; |
| 389 | | | wblock->data.section.shb_hardware = NULL; |
| 390 | | | wblock->data.section.shb_os = NULL; |
| 391 | | | wblock->data.section.shb_user_appl = NULL; |
| 392 | | | |
| 393 | | | |
| 394 | | | errno = WTAP_ERR_CANT_READ; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 395 | | | to_read = bh->block_total_length |
| 396 | | | - (int)sizeof() |
| 397 | | | - (int)sizeof () |
| 398 | | | - (int)sizeof(bh->block_total_length); |
| 399 | | | while(to_read > 0) { |
| 400 | | | |
| 401 | | | bytes_read = pcapng_read_option(fh, pn, &oh, option_content, sizeof(option_content), err, err_info); |
| 402 | | | if (bytes_read <= 0) { |
| 403 | | | pcapng_debug0(": failed to read option"); |
| 404 | | | return bytes_read; |
| 405 | | | } |
| 406 | | | block_read += bytes_read; |
| 407 | | | to_read -= bytes_read; |
| 408 | | | |
| 409 | | | |
| 410 | | | switch(oh.option_code) { |
| 411 | | | case(0): |
| 412 | | | if(to_read != 0) { |
| 413 | | | pcapng_debug1(": %u bytes after opt_endofopt", to_read); |
| 414 | | | } |
| 415 | | | |
| 416 | | | to_read = 0; |
| 417 | | | break; |
| 418 | | | case(1): |
| 419 | | | if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) { |
| 420 | | | wblock->data.section. = g_strndup(option_content, sizeof(option_content)); |
| 421 | | | pcapng_debug1(": %s", wblock->data.section.); |
| 422 | | | } else { |
| 423 | | | pcapng_debug1(": length %u seems strange", oh.option_length); |
| 424 | | | } |
| 425 | | | break; |
| 426 | | | case(2): |
| 427 | | | if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) { |
| 428 | | | wblock->data.section.shb_hardware = g_strndup(option_content, sizeof(option_content)); |
| 429 | | | pcapng_debug1(": shb_hardware %s", wblock->data.section.shb_hardware); |
| 430 | | | } else { |
| 431 | | | pcapng_debug1(": shb_hardware length %u seems strange", oh.option_length); |
| 432 | | | } |
| 433 | | | break; |
| 434 | | | case(3): |
| 435 | | | if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) { |
| 436 | | | wblock->data.section.shb_os = g_strndup(option_content, sizeof(option_content)); |
| 437 | | | pcapng_debug1(": shb_os %s", wblock->data.section.shb_os); |
| 438 | | | } else { |
| 439 | | | pcapng_debug1(": shb_os length %u seems strange", oh.option_length); |
| 440 | | | } |
| 441 | | | break; |
| 442 | | | case(4): |
| 443 | | | if(oh.option_length > 0 && oh.option_length < sizeof(option_content)) { |
| 444 | | | wblock->data.section.shb_user_appl = g_strndup(option_content, sizeof(option_content)); |
| 445 | | | pcapng_debug1(": shb_userappl %s", wblock->data.section.shb_user_appl); |
| 446 | | | } else { |
| 447 | | | pcapng_debug1(": shb_userappl length %u seems strange", oh.option_length); |
| 448 | | | } |
| 449 | | | break; |
| 450 | | | default: |
| 451 | | | pcapng_debug2(": unknown option %u - ignoring %u bytes", |
| 452 | | | oh.option_code, oh.option_length); |
| 453 | | | } |
| 454 | | | } |
| 455 | | | |
| 456 | | | if (pn->interface_data != NULL) { |
| 457 | | | g_array_free(pn->interface_data, TRUE); |
| 458 | | | } |
| 459 | | | pn->interface_data = g_array_new(FALSE, FALSE, sizeof(interface_data_t)); |
| 460 | | | pn->number_of_interfaces = 0; |
| 461 | | | |
| 462 | | | return block_read; |
| 463 | | | } |
| |