(/home/sate/Testcases/c/cve/wireshark-1.2.0/randpkt.c) |
| |
| 684 | | | seed(void) |
| 685 | | | { |
| 686 | | | unsigned int randomness; |
| 687 | | | time_t now; |
| 688 | | | #ifndef _WIN32 |
| 689 | | | int fd; |
| 690 | | | ssize_t ret; |
| 691 | | | |
| 692 | | | |
| 693 | | | |
| 694 | | | |
| 695 | | | |
| 696 | | | |
| 697 | | | |
| 698 | | | fd = open("/dev/random", O_RDONLY); |
Event 1:
open() allocates and returns the resource of interest.
hide
|
|
| 699 | | | if (fd == -1) { |
Event 3:
Skipping " if". fd == -1 evaluates to false.
hide
|
|
| 700 | | | if (errno != ENOENT) {
x /usr/include/asm-generic/errno-base.h |
| |
5 | #define ENOENT 2 /* No such file or directory */ |
| |
|
| 701 | | | fprintf(stderr, |
| 702 | | | "randpkt: Could not open /dev/random for reading: %s\n", |
| 703 | | | strerror(errno)); |
| 704 | | | exit(2); |
| 705 | | | } |
| 706 | | | goto fallback; |
| 707 | | | } |
| 708 | | | |
| 709 | | | ret = read(fd, &randomness, sizeof randomness); |
Event 4:
The resource of interest is passed to read() as the first argument. - read() does not free it or save any references that are freed later.
- fd, which evaluates to open("/dev/random", 0) from randpkt.c:698, is passed to read() as the first argument.
See related event 2.
hide
|
|
| 710 | | | if (ret == -1) { |
Event 5:
Skipping " if". ret == -1 evaluates to false.
hide
|
|
| 711 | | | fprintf(stderr, |
| 712 | | | "randpkt: Could not read from /dev/random: %s\n", |
| 713 | | | strerror(errno)); |
| 714 | | | exit(2); |
| 715 | | | } |
| 716 | | | if ((size_t)ret != sizeof randomness) { |
Event 6:
Skipping " if". (size_t)ret != sizeof( randomness ) evaluates to false.
hide
|
|
| 717 | | | fprintf(stderr, |
| 718 | | | "randpkt: Tried to read %lu bytes from /dev/random, got %ld\n", |
| 719 | | | (unsigned long)sizeof randomness, (long)ret); |
| 720 | | | exit(2); |
| 721 | | | } |
| 722 | | | srand(randomness); |
| 723 | | | return; |
| |