diff options
Diffstat (limited to 'sftp-server.c')
-rw-r--r-- | sftp-server.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/sftp-server.c b/sftp-server.c index d68584b52..76edebc5a 100644 --- a/sftp-server.c +++ b/sftp-server.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp-server.c,v 1.72 2007/04/18 01:12:43 stevesk Exp $ */ | 1 | /* $OpenBSD: sftp-server.c,v 1.73 2007/05/17 07:55:29 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000-2004 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000-2004 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -1214,7 +1214,7 @@ main(int argc, char **argv) | |||
1214 | int in, out, max, ch, skipargs = 0, log_stderr = 0; | 1214 | int in, out, max, ch, skipargs = 0, log_stderr = 0; |
1215 | ssize_t len, olen, set_size; | 1215 | ssize_t len, olen, set_size; |
1216 | SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; | 1216 | SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; |
1217 | char *cp; | 1217 | char *cp, buf[4*4096]; |
1218 | 1218 | ||
1219 | extern char *optarg; | 1219 | extern char *optarg; |
1220 | extern char *__progname; | 1220 | extern char *__progname; |
@@ -1298,7 +1298,15 @@ main(int argc, char **argv) | |||
1298 | memset(rset, 0, set_size); | 1298 | memset(rset, 0, set_size); |
1299 | memset(wset, 0, set_size); | 1299 | memset(wset, 0, set_size); |
1300 | 1300 | ||
1301 | FD_SET(in, rset); | 1301 | /* |
1302 | * Ensure that we can read a full buffer and handle | ||
1303 | * the worst-case length packet it can generate, | ||
1304 | * otherwise apply backpressure by stopping reads. | ||
1305 | */ | ||
1306 | if (buffer_check_alloc(&iqueue, sizeof(buf)) && | ||
1307 | buffer_check_alloc(&oqueue, SFTP_MAX_MSG_LENGTH)) | ||
1308 | FD_SET(in, rset); | ||
1309 | |||
1302 | olen = buffer_len(&oqueue); | 1310 | olen = buffer_len(&oqueue); |
1303 | if (olen > 0) | 1311 | if (olen > 0) |
1304 | FD_SET(out, wset); | 1312 | FD_SET(out, wset); |
@@ -1312,7 +1320,6 @@ main(int argc, char **argv) | |||
1312 | 1320 | ||
1313 | /* copy stdin to iqueue */ | 1321 | /* copy stdin to iqueue */ |
1314 | if (FD_ISSET(in, rset)) { | 1322 | if (FD_ISSET(in, rset)) { |
1315 | char buf[4*4096]; | ||
1316 | len = read(in, buf, sizeof buf); | 1323 | len = read(in, buf, sizeof buf); |
1317 | if (len == 0) { | 1324 | if (len == 0) { |
1318 | debug("read eof"); | 1325 | debug("read eof"); |
@@ -1334,7 +1341,13 @@ main(int argc, char **argv) | |||
1334 | buffer_consume(&oqueue, len); | 1341 | buffer_consume(&oqueue, len); |
1335 | } | 1342 | } |
1336 | } | 1343 | } |
1337 | /* process requests from client */ | 1344 | |
1338 | process(); | 1345 | /* |
1346 | * Process requests from client if we can fit the results | ||
1347 | * into the output buffer, otherwise stop processing input | ||
1348 | * and let the output queue drain. | ||
1349 | */ | ||
1350 | if (buffer_check_alloc(&oqueue, SFTP_MAX_MSG_LENGTH)) | ||
1351 | process(); | ||
1339 | } | 1352 | } |
1340 | } | 1353 | } |