Skip to content

Commit dd7b14b

Browse files
committed
fix(headers): add limit to maximum headers that should be parsed
Closes #256
1 parent c983ebf commit dd7b14b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/header/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use mucell::MuCell;
2020
use uany::{UnsafeAnyExt};
2121
use unicase::UniCase;
2222

23-
use {http, HttpResult};
23+
use {http, HttpResult, HttpError};
2424

2525
pub use self::shared::{Encoding, QualityItem, qitem};
2626
pub use self::common::*;
@@ -118,6 +118,8 @@ pub struct Headers {
118118
data: HashMap<HeaderName, MuCell<Item>>
119119
}
120120

121+
const MAX_HEADERS_COUNT: u8 = 100;
122+
121123
impl Headers {
122124

123125
/// Creates a new, empty headers map.
@@ -130,6 +132,7 @@ impl Headers {
130132
#[doc(hidden)]
131133
pub fn from_raw<R: Reader>(rdr: &mut R) -> HttpResult<Headers> {
132134
let mut headers = Headers::new();
135+
let mut count = 0u8;
133136
loop {
134137
match try!(http::read_header(rdr)) {
135138
Some((name, value)) => {
@@ -145,6 +148,11 @@ impl Headers {
145148
// Unreachable
146149
_ => {}
147150
};
151+
count += 1;
152+
if count > MAX_HEADERS_COUNT {
153+
debug!("Too many headers, aborting");
154+
return Err(HttpError::HttpHeaderError)
155+
}
148156
},
149157
None => break,
150158
}

0 commit comments

Comments
 (0)