mirror of
https://github.com/lxsang/luafcgi.git
synced 2024-12-26 05:08:23 +01:00
fix: limut stdout record to 2048bytes to prevent header length overflow
Some checks failed
gitea-sync/luafcgi/pipeline/head There was a failure building this commit
Some checks failed
gitea-sync/luafcgi/pipeline/head There was a failure building this commit
This commit is contained in:
parent
2cda1b84c0
commit
3ac6971a36
@ -17,7 +17,7 @@ rand = "0.8.5"
|
|||||||
twoway = "0.2.2"
|
twoway = "0.2.2"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 's'
|
opt-level = 3
|
||||||
# 's' for size
|
# 's' for size
|
||||||
lto = true
|
lto = true
|
||||||
# panic = 'abort'
|
# panic = 'abort'
|
||||||
|
15
src/lib.rs
15
src/lib.rs
@ -4,7 +4,7 @@ use rand::Rng;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fmt::Arguments;
|
use std::fmt::Arguments;
|
||||||
use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Write};
|
use std::io::{BufRead, BufReader, Cursor, Error, ErrorKind, Read, Write};
|
||||||
use std::os::fd::RawFd;
|
use std::os::fd::RawFd;
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
@ -724,7 +724,18 @@ impl FCGIOStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_record(&mut self, buf: Vec<u8>) -> Result<(), std::io::Error> {
|
fn write_record(&mut self, buf: Vec<u8>) -> Result<(), std::io::Error> {
|
||||||
fcgi_send_stdout(self, self.id, Some(buf))?;
|
let mut buf_reader = BufReader::with_capacity(2048, Cursor::new(buf));
|
||||||
|
loop {
|
||||||
|
let length = {
|
||||||
|
let buffer = buf_reader.fill_buf()?;
|
||||||
|
fcgi_send_stdout(self, self.id, Some(buffer.to_vec()))?;
|
||||||
|
buffer.len()
|
||||||
|
};
|
||||||
|
if length == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf_reader.consume(length);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user