mirror of
http://galexander.org/git/simplesshd.git
synced 2025-02-20 02:21:59 +00:00
for the rsync/supersu buffering hack, limit the total buffer depth to 1MB
so that it doesn't cause memory exhaustion in extreme cases
This commit is contained in:
parent
4848e35b69
commit
0a033800b6
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#define WRAPPED_CMD "/data/data/org.galexander.sshd/lib/librsync.so"
|
#define WRAPPED_CMD "/data/data/org.galexander.sshd/lib/librsync.so"
|
||||||
#define WRAPPED_ARG0 "rsync"
|
#define WRAPPED_ARG0 "rsync"
|
||||||
|
#define MAX_BUFSZ (1024*1024)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -50,6 +51,17 @@ struct buf {
|
|||||||
struct block *tail; /* write here */
|
struct block *tail; /* write here */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
buf_length(struct buf *b)
|
||||||
|
{
|
||||||
|
struct block *p;
|
||||||
|
int ret = 0;
|
||||||
|
for (p = b->head; p; p = p->next) {
|
||||||
|
ret += p->len;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
buf_waiting(struct buf *b)
|
buf_waiting(struct buf *b)
|
||||||
{
|
{
|
||||||
@ -153,8 +165,12 @@ main(int argc, char **argv)
|
|||||||
while (1) {
|
while (1) {
|
||||||
int s;
|
int s;
|
||||||
FD_ZERO(&ifds);
|
FD_ZERO(&ifds);
|
||||||
|
if (buf_length(&buf0) < MAX_BUFSZ) {
|
||||||
FD_SET(0, &ifds);
|
FD_SET(0, &ifds);
|
||||||
|
}
|
||||||
|
if (buf_length(&buf1) < MAX_BUFSZ) {
|
||||||
FD_SET(child_stdout, &ifds);
|
FD_SET(child_stdout, &ifds);
|
||||||
|
}
|
||||||
FD_ZERO(&ofds);
|
FD_ZERO(&ofds);
|
||||||
if (buf_waiting(&buf1)) {
|
if (buf_waiting(&buf1)) {
|
||||||
FD_SET(1, &ofds);
|
FD_SET(1, &ofds);
|
||||||
|
Loading…
Reference in New Issue
Block a user