Text   |  XML   |  ReML   |   Visible Warnings:

Free Null Pointer  at istream-raw-mbox.c:105

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

istream_raw_mbox_seek

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/mbox/istream-raw-mbox.c)expand/collapse
Show more  
 688  int istream_raw_mbox_seek(struct istream *stream, uoff_t offset)
 689  {
 690          struct raw_mbox_istream *rstream =
 691                  (struct raw_mbox_istream *)stream->real_stream;
 692          bool check;
 693   
 694          i_assert(rstream->locked);
 695   
 696          rstream->corrupted = FALSE;
 697          rstream->eof = FALSE;
 698          rstream->istream.istream.eof = FALSE;
 699   
 700          /* if seeked is FALSE, we unlocked in the middle. don't try to use 
 701             any cached state then. */
 702          if (rstream->mail_size != (uoff_t)-1 && rstream->seeked &&
 703              rstream->hdr_offset + rstream->mail_size == offset) {
 704                  istream_raw_mbox_next(stream, (uoff_t)-1);
 705                  return 0;
 706          }
 707   
 708          if (offset == rstream->from_offset && rstream->seeked) {
 709                  /* back to beginning of current message */
 710                  offset = rstream->hdr_offset;
 711                  check = offset == 0;
 712          } else {
 713                  rstream->body_offset = (uoff_t)-1;
 714                  rstream->mail_size = (uoff_t)-1;
 715                  rstream->received_time = (time_t)-1;
 716                  rstream->next_received_time = (time_t)-1;
 717                  rstream->header_missing_eoh = FALSE;
 718   
 719                  i_free(rstream->sender);
 720                  rstream->sender = NULL;
 721                  i_free(rstream->next_sender);
 722                  rstream->next_sender = NULL;
 723   
 724                  rstream->from_offset = offset;
 725                  rstream->hdr_offset = offset;
 726                  check = TRUE;
 727          }
 728          rstream->seeked = TRUE;
 729   
 730          i_stream_seek_mark(stream, offset);
 731          i_stream_seek_mark(rstream->istream.parent, offset);
 732   
 733          if (check)
 734[+]                 (void)i_stream_raw_mbox_read(&rstream->istream);
expand/collapse

i_stream_raw_mbox_read

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/mbox/istream-raw-mbox.c)expand/collapse
Show more  
 169  static ssize_t i_stream_raw_mbox_read(struct istream_private *stream)
 170  {
 171          static const char *mbox_from = "\nFrom ";
 172          struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream;
 173          const unsigned char *buf;
 174          const char *fromp;
 175          char *sender;
 176          time_t received_time;
 177          size_t i, pos, new_pos, from_start_pos, from_after_pos;
 178          ssize_t ret = 0;
 179          int eoh_char, tz;
 180          bool crlf_ending = FALSE;
 181   
 182          i_assert(rstream->seeked);
 183          i_assert(stream->istream.v_offset >= rstream->from_offset);
 184   
 185          if (stream->istream.eof)
 186                  return -1;
 187          if (rstream->corrupted) {
 188                  rstream->istream.istream.stream_errno = EINVAL;
 189                  return -1;
 190          }
 191   
 192          i_stream_seek(stream->parent, stream->istream.v_offset);
 193   
 194          stream->pos -= stream->skip;
 195          stream->skip = 0;
 196          stream->buffer = NULL;
 197   
 198          ret = 0;
 199          do {
 200                  buf = i_stream_get_data(stream->parent, &pos);
 201                  if (pos > 1 && stream->istream.v_offset + pos >
 202                      rstream->input_peak_offset) {
 203                          /* fake our read count. needed because if in the end
 204                             we have only one character in buffer and we skip it
 205                             (as potential CR), we want to get back to this 
 206                             i_stream_raw_mbox_read() to read more data. */
 207                          ret = pos;
 208                          break;
 209                  }
 210[+]                 ret = i_stream_read(stream->parent);
 211          } while (ret > 0);
 212          stream->istream.stream_errno = stream->parent->stream_errno;
 213   
 214          if (ret < 0) {
 215                  if (ret == -2) {
 216                          if (stream->skip == stream->pos) {
 217                                  /* From_-line is longer than our input buffer.
 218                                     finish the check without seeing the LF. */
 219                          } else if (stream->istream.v_offset + pos ==
 220                                     rstream->input_peak_offset) {
 221                                  /* we've read everything our parent stream 
 222                                     has to offer. */
 223                                  stream->buffer = buf;
 224                                  return -2;
 225
247
Show [ Lines 225 to 247 omitted. ]
 248                                     stream is now at EOF */
 249                                  rstream->eof = TRUE;
 250                          }
 251                          stream->istream.eof = TRUE;
 252                          rstream->crlf_ending = crlf_ending;
 253                          handle_end_of_mail(rstream, pos);
 254                          return ret < 0 ? i_stream_raw_mbox_read(stream) : ret;
 255                  }
 256          }
 257   
 258          if (stream->istream.v_offset == rstream->from_offset) {
 259                  /* beginning of message, we haven't yet read our From-line */
 260                  if (pos == 2 && ret > 0) {
 261                          /* we're at the end of file with CR+LF linefeeds?
 262                             need more data to verify it. */
 263                          rstream->input_peak_offset =
 264                                  stream->istream.v_offset + pos;
 265                          return i_stream_raw_mbox_read(stream);
 266                  }
 267[+]                 if (mbox_read_from_line(rstream) < 0) {
expand/collapse

mbox_read_from_line

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/mbox/istream-raw-mbox.c)expand/collapse
Show more  
 50  static int mbox_read_from_line(struct raw_mbox_istream *rstream)
 51  {
 52          const unsigned char *buf, *p;
 53          char *sender;
 54          time_t received_time;
 55          size_t pos, line_pos;
 56          ssize_t ret;
 57          unsigned int skip;
 58          int tz;
 59   
 60          buf = i_stream_get_data(rstream->istream.parent, &pos);
 61          i_assert(pos > 0);
 62   
 63          /* from_offset points to "\nFrom ", so unless we're at the beginning 
 64             of the file, skip the initial \n */
 65          if (rstream->from_offset == 0)
 66                  skip = 0;
 67          else {
 68                  skip = 1;
 69                  if (*buf == '\r')
 70                          skip++;
 71          }
 72   
 73          while ((p = memchr(buf+skip, '\n', pos-skip)) == NULL) {
 74                  ret = i_stream_read(rstream->istream.parent);
 75                  buf = i_stream_get_data(rstream->istream.parent, &pos);
 76                  if (ret < 0) {
 77                          if (ret == -2) {
 78                                  /* From_-line is too long, but we should be
 79                                     able to parse what we have so far. */
 80                                  break;
 81                          }
 82                          /* EOF shouldn't happen */
 83                          rstream->istream.istream.eof =
 84                                  rstream->istream.parent->eof;
 85                          rstream->istream.istream.stream_errno =
 86                                  rstream->istream.parent->stream_errno;
 87                          return -1;
 88                  }
 89                  i_assert(pos > 0);
 90          }
 91          line_pos = p == NULL ? 0 : (size_t)(p - buf);
 92   
 93          /* beginning of mbox */
 94          if (memcmp(buf+skip, "From ", 5) != 0 ||
 95              mbox_from_parse((buf+skip)+5, (pos-skip)-5,
 96[+]                             &received_time, &tz, &sender) < 0) {
 97                  /* broken From - should happen only at beginning of
 98                     file if this isn't a mbox.. */
 99                  rstream->istream.istream.stream_errno = EINVAL;
 100                  return -1;
 101          }
 102   
 103          if (rstream->istream.istream.v_offset == rstream->from_offset) {
 104                  rstream->received_time = received_time;
 105                  i_free(rstream->sender);
Show more  
Show more  
Show more  




Change Warning 11664.24608 : Free Null Pointer

Priority:
State:
Finding:
Owner:
Note: