Loading src/http.cpp +55 −10 Changes for src/http.cpp: 55 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -269,6 +269,8 @@ const std::vector<char> libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq) hsize=res.parse(data.data.buf,recv); ++hsize; recv-=hsize; std::move(data.data.buf+hsize,data.data.buf+BLOCKSIZE,data.data.buf); Loading Loading @@ -440,6 +442,8 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq libhttppp::HttpResponse res; hsize=res.parse(data.data.buf,recv); ++hsize; recv-=hsize; // Shift remaining data to the front of the buffer Loading Loading @@ -553,33 +557,74 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq int libhttppp::HttpClient::readchunk(const char *data,int datasize,int &pos){ // Skip any leading CRLF from the previous chunk's data terminator while (pos < datasize && (data[pos] == '\r' || data[pos] == '\n')) { ++pos; } // Now pos should be at the first hex digit of the chunk size line int start = pos; char value[512]; // Find the end of the chunk size line (CR) while (pos < datasize && data[pos] != '\r') { ++pos; } while( (pos < datasize) && data[++pos]!='\r'){}; if (pos >= datasize) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid chunked encoding (incomplete size line)"; throw ee; } int len = pos - start; if(len > 512){ if (len <= 0) { // Empty size line is illegal; treat as protocol error libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: chunck size: " << len << " to big aborting !"; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid chunked encoding (empty chunk size)"; throw ee; } memcpy(value,data+start,len); if (len >= 512) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: chunk size line (" << len << ") too big, aborting!"; throw ee; } char value[512]; memcpy(value, data + start, len); value[len] = '\0'; if (len < 1) { return 0; // Strip optional chunk extensions: "1A3;foo=bar" -> "1A3" char *semi = strchr(value, ';'); if (semi) { *semi = '\0'; } int result=strtol(value, NULL, 16); char *endptr = nullptr; long result = strtol(value, &endptr, 16); if (endptr == value) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid hex chunk size: '" << value << "'"; throw ee; } if (result < 0) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: negative chunk size: " << result; throw ee; } pos+=2; // Skip CRLF after the size line if (pos + 1 >= datasize || data[pos] != '\r' || data[pos + 1] != '\n') { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid chunked encoding (missing CRLF after size)"; throw ee; } pos += 2; // now pos points at the first byte of the chunk data return result; // Final chunk: result == 0 return static_cast<int>(result); } Loading Loading
src/http.cpp +55 −10 Changes for src/http.cpp: 55 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -269,6 +269,8 @@ const std::vector<char> libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq) hsize=res.parse(data.data.buf,recv); ++hsize; recv-=hsize; std::move(data.data.buf+hsize,data.data.buf+BLOCKSIZE,data.data.buf); Loading Loading @@ -440,6 +442,8 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq libhttppp::HttpResponse res; hsize=res.parse(data.data.buf,recv); ++hsize; recv-=hsize; // Shift remaining data to the front of the buffer Loading Loading @@ -553,33 +557,74 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq int libhttppp::HttpClient::readchunk(const char *data,int datasize,int &pos){ // Skip any leading CRLF from the previous chunk's data terminator while (pos < datasize && (data[pos] == '\r' || data[pos] == '\n')) { ++pos; } // Now pos should be at the first hex digit of the chunk size line int start = pos; char value[512]; // Find the end of the chunk size line (CR) while (pos < datasize && data[pos] != '\r') { ++pos; } while( (pos < datasize) && data[++pos]!='\r'){}; if (pos >= datasize) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid chunked encoding (incomplete size line)"; throw ee; } int len = pos - start; if(len > 512){ if (len <= 0) { // Empty size line is illegal; treat as protocol error libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: chunck size: " << len << " to big aborting !"; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid chunked encoding (empty chunk size)"; throw ee; } memcpy(value,data+start,len); if (len >= 512) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: chunk size line (" << len << ") too big, aborting!"; throw ee; } char value[512]; memcpy(value, data + start, len); value[len] = '\0'; if (len < 1) { return 0; // Strip optional chunk extensions: "1A3;foo=bar" -> "1A3" char *semi = strchr(value, ';'); if (semi) { *semi = '\0'; } int result=strtol(value, NULL, 16); char *endptr = nullptr; long result = strtol(value, &endptr, 16); if (endptr == value) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid hex chunk size: '" << value << "'"; throw ee; } if (result < 0) { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: negative chunk size: " << result; throw ee; } pos+=2; // Skip CRLF after the size line if (pos + 1 >= datasize || data[pos] != '\r' || data[pos + 1] != '\n') { libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << "nginxfiler: invalid chunked encoding (missing CRLF after size)"; throw ee; } pos += 2; // now pos points at the first byte of the chunk data return result; // Final chunk: result == 0 return static_cast<int>(result); } Loading