(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/ascend.c) |
| |
| 91 | | | static gint64 ascend_seek(wtap *wth, int *err) |
| 92 | | | { |
| 93 | | | int byte; |
| 94 | | | gint64 date_off = -1, cur_off, packet_off; |
| 95 | | | size_t string_level[ASCEND_MAGIC_STRINGS]; |
| 96 | | | guint string_i = 0, type = 0; |
| 97 | | | guint excessive_read_count = 262144; |
| 98 | | | |
| 99 | | | memset(&string_level, 0, sizeof(string_level)); |
| 100 | | | |
| 101 | | | while (((byte = file_getc(wth->fh)) != EOF)) { |
| 102 | | | excessive_read_count--; |
| 103 | | | |
| 104 | | | if (!excessive_read_count) { |
| 105 | | | return -1; |
| 106 | | | } |
| 107 | | | |
| 108 | | | for (string_i = 0; string_i < ASCEND_MAGIC_STRINGS; string_i++) { |
| 109 | | | const gchar *strptr = ascend_magic[string_i].strptr; |
| 110 | | | size_t len = strlen(strptr); |
| 111 | | | |
| 112 | | | if (byte == *(strptr + string_level[string_i])) { |
| 113 | | | string_level[string_i]++; |
| 114 | | | if (string_level[string_i] >= len) { |
| 115 | | | cur_off = file_tell(wth->fh); |
| 116 | | | if (cur_off == -1) { |
| 117 | | | |
| 118 | | | *err = file_error(wth->fh); |
| 119 | | | return -1; |
| 120 | | | } |
| 121 | | | |
| 122 | | | |
| 123 | | | |
| 124 | | | if (strcmp(strptr, ASCEND_DATE) == 0) { |
| 125 | | | date_off = cur_off - len; |
| 126 | | | } else { |
| 127 | | | if (date_off == -1) { |
| 128 | | | |
| 129 | | | |
| 130 | | | packet_off = cur_off - len; |
| 131 | | | } else { |
| 132 | | | |
| 133 | | | |
| 134 | | | packet_off = date_off; |
| 135 | | | } |
| 136 | | | |
| 137 | | | type = ascend_magic[string_i].type; |
| 138 | | | goto found; |
| 139 | | | } |
| 140 | | | } |
| 141 | | | } else { |
| 142 | | | string_level[string_i] = 0; |
| 143 | | | } |
| 144 | | | } |
| 145 | | | } |
| 146 | | | |
| 147 | | | if (byte != EOF || file_eof(wth->fh)) { |
Redundant Condition
byte != -1 always evaluates to false. This may be because: - There is a constant assignment to one or more of the variables involved.
- An earlier conditional statement has already ensured that byte != -1 cannot be true.
- A crashing bug occurs on every path where byte != -1 could have evaluated to true. Look for a preceding Null Pointer Dereference or Division By Zero warning.
|
|
| 148 | | | |
| 149 | | | *err = 0; |
| 150 | | | } else { |
| 151 | | | |
| 152 | | | |
| 153 | | | *err = file_error(wth->fh); |
| 154 | | | } |
| 155 | | | return -1; |
| 156 | | | |
| 157 | | | found: |
| 158 | | | |
| 159 | | | |
| 160 | | | |
| 161 | | | |
| 162 | | | if (file_seek(wth->fh, packet_off, SEEK_SET, err) == -1)
x /usr/include/stdio.h |
| |
141 | #define SEEK_SET 0 /* Seek from beginning of file. */ |
| |
|
| 163 | | | return -1; |
| 164 | | | |
| 165 | | | wth->.ascend.type = type; |
| 166 | | | |
| 167 | | | return packet_off; |
| 168 | | | } |
| |