Compare commits

...

5 Commits

Author SHA1 Message Date
Martin Chang
a38602ac2c fix windows 2023-12-15 17:55:51 +08:00
Martin Chang
26f99ecce3 fix integer overflow when data frame too small with padding 2023-12-15 17:45:43 +08:00
Martin Chang
da6139302d avoid status code overflow 2023-12-15 17:03:33 +08:00
Martin Chang
e5e777b844 Merge remote-tracking branch 'origin/master' into h2-client 2023-12-15 15:27:50 +08:00
Martin Chang
41b740f649
add discord link to readme (#1879) 2023-12-11 14:10:33 +08:00
5 changed files with 25 additions and 4 deletions

View File

@ -3,6 +3,7 @@
[![Build Status](https://github.com/an-tao/drogon/workflows/Build%20Drogon/badge.svg?branch=master)](https://github.com/drogonframework/drogon/actions)
[![Join the chat at https://gitter.im/drogon-web/community](https://badges.gitter.im/drogon-web/community.svg)](https://gitter.im/drogon-web/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Join the telegram group at https://t.me/joinchat/_mMNGv0748ZkMDAx](https://img.shields.io/badge/Telegram-2CA5E0?style=flat&logo=telegram&logoColor=white)](https://t.me/joinchat/_mMNGv0748ZkMDAx)
[![Join our Discord](https://dcbadge.vercel.app/api/server/3DvHY6Ewuj?style=flat)](https://discord.gg/3DvHY6Ewuj)
[![Docker image](https://img.shields.io/badge/Docker-image-blue.svg)](https://cloud.docker.com/u/drogonframework/repository/docker/drogonframework/drogon)
English | [简体中文](./README.zh-CN.md) | [繁體中文](./README.zh-TW.md)

View File

@ -3,6 +3,7 @@
[![Build Status](https://github.com/an-tao/drogon/workflows/Build%20Drogon/badge.svg?branch=master)](https://github.com/drogonframework/drogon/actions)
[![Join the chat at https://gitter.im/drogon-web/community](https://badges.gitter.im/drogon-web/community.svg)](https://gitter.im/drogon-web/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Join the telegram group at https://t.me/joinchat/_mMNGv0748ZkMDAx](https://img.shields.io/badge/Telegram-2CA5E0?style=flat&logo=telegram&logoColor=white)](https://t.me/joinchat/_mMNGv0748ZkMDAx)
[![Join our Discord](https://dcbadge.vercel.app/api/server/3DvHY6Ewuj?style=flat)](https://discord.gg/3DvHY6Ewuj)
[![Docker image](https://img.shields.io/badge/Docker-image-blue.svg)](https://cloud.docker.com/u/drogonframework/repository/docker/drogonframework/drogon)
[English](./README.md) | 简体中文 | [繁體中文](./README.zh-TW.md)

View File

@ -3,6 +3,7 @@
[![Build Status](https://github.com/an-tao/drogon/workflows/Build%20Drogon/badge.svg?branch=master)](https://github.com/drogonframework/drogon/actions)
[![Join the chat at https://gitter.im/drogon-web/community](https://badges.gitter.im/drogon-web/community.svg)](https://gitter.im/drogon-web/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Join the telegram group at https://t.me/joinchat/_mMNGv0748ZkMDAx](https://img.shields.io/badge/Telegram-2CA5E0?style=flat&logo=telegram&logoColor=white)](https://t.me/joinchat/_mMNGv0748ZkMDAx)
[![Join our Discord](https://dcbadge.vercel.app/api/server/3DvHY6Ewuj?style=flat)](https://discord.gg/3DvHY6Ewuj)
[![Docker image](https://img.shields.io/badge/Docker-image-blue.svg)](https://cloud.docker.com/u/drogonframework/repository/docker/drogonframework/drogon)
[English](./README.md) | [简体中文](./README.zh-CN.md) | 繁體中文

View File

@ -1,7 +1,10 @@
#include "Http2Transport.h"
#include "HttpFileUploadRequest.h"
#include <cstdint>
#include <fstream>
#include <limits>
#include <type_traits>
#include <variant>
using namespace drogon;
@ -25,6 +28,13 @@ static std::optional<size_t> stosz(const std::string &str)
}
}
template <typename Enum>
constexpr size_t enumMaxValue()
{
using Underlying = std::underlying_type_t<Enum>;
return (std::numeric_limits<Underlying>::max)();
}
enum class H2FrameType
{
Data = 0x0,
@ -289,13 +299,13 @@ std::optional<DataFrame> DataFrame::parse(ByteStream &payload, uint8_t flags)
}
assert(payload.remaining() >= frame.padLength);
size_t payloadSize = payload.remaining() - frame.padLength;
if (payloadSize < 0)
if (payload.remaining() > frame.padLength)
{
LOG_TRACE << "data padding is larger than the payload size";
return std::nullopt;
}
const size_t payloadSize = payload.remaining() - frame.padLength;
if (payloadSize > 0x7fffffff)
{
LOG_ERROR << "data frame payload size too large";
@ -836,6 +846,7 @@ void Http2Transport::onRecvMessage(const trantor::TcpConnectionPtr &,
}
// TODO: Should be half-closed but trantor doesn't support it
connPtr->shutdown();
return;
}
else if (std::holds_alternative<PingFrame>(frame))
{
@ -1062,7 +1073,7 @@ bool Http2Transport::parseAndApplyHeaders(internal::H2Stream &stream,
else if (key == ":status")
{
auto status = stosz(value);
if (!status)
if (!status || *status > enumMaxValue<HttpStatusCode>())
{
streamErrored(streamId, ReqResult::BadResponse);
return false;
@ -1094,7 +1105,7 @@ Http2Transport::Http2Transport(trantor::TcpConnectionPtr connPtr,
if (!connPtr->connected())
return;
// Send HTTP/2 magic string
connPtr->send(h2_preamble.data(), h2_preamble.length());
batchedSendBuffer.write(h2_preamble);
*bytesSent_ += h2_preamble.length();
// RFC 9113 3.4
@ -1103,6 +1114,7 @@ Http2Transport::Http2Transport(trantor::TcpConnectionPtr connPtr,
settingsFrame.settings.emplace_back((uint16_t)H2SettingsKey::EnablePush,
0); // Disable push
sendFrame(settingsFrame, 0);
sendBufferedData();
}
void Http2Transport::handleFrameForStream(const internal::H2Frame &frame,

View File

@ -5,6 +5,7 @@
// TODO: Write our own HPACK implementation
#include "hpack/HPacker.h"
#include <string_view>
#include <variant>
#include <climits>
@ -154,6 +155,11 @@ struct OByteStream
buffer.append((char *)ptr, size);
}
void write(const std::string_view &str)
{
buffer.append(str.data(), str.size());
}
void overwriteU24BE(size_t offset, uint32_t value)
{
assert(value <= 0xffffff);