~ubuntu-branches/debian/stretch/haserl/stretch

« back to all changes in this revision

Viewing changes to src/sliding_buffer.c

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-08-06 12:46:56 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140806124656-p8oc3sgj615qixjr
Tags: 0.9.33-1
* [16945f6] Imported Upstream version 0.9.33
* [ac08f26] No-change bump of Standards-Version to 3.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* --------------------------------------------------------------------------
2
 
 * Copyright 2003-2011 (inclusive) Nathan Angelacos 
 
2
 * Copyright 2003-2014 (inclusive) Nathan Angelacos 
3
3
 *                   (nangel@users.sourceforge.net)
4
4
 * 
5
5
 *   This file is part of haserl.
31
31
#include <fcntl.h>
32
32
 
33
33
#include "sliding_buffer.h"
 
34
#include "h_error.h"
34
35
 
35
36
/*
36
37
 * initialize a sliding buffer structure 
128
129
   */
129
130
  pos = 0;
130
131
  len = sbuf->bufsize - (int) (sbuf->ptr - sbuf->buf) - strlen (matchstr);
131
 
  while (memcmp (matchstr, sbuf->ptr + pos, strlen (matchstr)) && (pos < len))
132
 
    {
133
 
      pos++;
134
 
    }
135
 
 
136
 
  /*
137
 
   * if we found it 
138
 
   */
139
 
  if (pos < len)
140
 
    {
141
 
      sbuf->len = pos;
142
 
      sbuf->segment = sbuf->ptr;
143
 
      sbuf->ptr = sbuf->segment + pos + strlen (matchstr);
144
 
      return -1;
145
 
    }
146
 
 
147
 
  if (sbuf->eof)
148
 
    {
149
 
      len += strlen (matchstr);
150
 
    }
151
 
 
 
132
  /* a malicious client can send a matchstr longer than the actual content body 
 
133
     do not allow reads beyond the buffer limits
 
134
  */
 
135
  len = ( len < 0 ) ? 0 : len;
 
136
 
 
137
  /* if have a matchstr, look for it, otherwise return the chunk */
 
138
  if ( strlen(matchstr) > 0 )  {
 
139
 
 
140
          while (memcmp (matchstr, sbuf->ptr + pos, strlen (matchstr)) && (pos < len))
 
141
            {
 
142
              pos++;
 
143
            }
 
144
 
 
145
          /*
 
146
           * if we found it 
 
147
           */
 
148
          if (pos < len)
 
149
            {
 
150
              sbuf->len = pos;
 
151
              sbuf->segment = sbuf->ptr;
 
152
              sbuf->ptr = sbuf->segment + pos + strlen (matchstr);
 
153
              return -1;
 
154
            }
 
155
        
 
156
 
 
157
          if (sbuf->eof)
 
158
            {
 
159
              len += strlen (matchstr);
 
160
            }
 
161
 
 
162
  } 
152
163
  /*
153
164
   * ran off the end, didn't find the matchstr
154
165
   */