]> andersk Git - openssh.git/blobdiff - sftp-server.c
- (tim) [configure.ac] test for egrep (AC_PROG_EGREP) before first
[openssh.git] / sftp-server.c
index 1ff4750ea64c442c06d966ee1f68dff64aeaeb81..7060c44ad0833fcfbc8268e51f136e725fc6f492 100644 (file)
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 #include "includes.h"
-RCSID("$OpenBSD: sftp-server.c,v 1.47 2004/06/25 05:38:48 dtucker Exp $");
+RCSID("$OpenBSD: sftp-server.c,v 1.50 2006/01/02 01:20:31 djm Exp $");
 
 #include "buffer.h"
 #include "bufaux.h"
 #include "getput.h"
 #include "log.h"
 #include "xmalloc.h"
+#include "misc.h"
 
 #include "sftp.h"
 #include "sftp-common.h"
@@ -31,11 +32,7 @@ RCSID("$OpenBSD: sftp-server.c,v 1.47 2004/06/25 05:38:48 dtucker Exp $");
 #define get_string(lenp)               buffer_get_string(&iqueue, lenp);
 #define TRACE                          debug
 
-#ifdef HAVE___PROGNAME
 extern char *__progname;
-#else
-char *__progname;
-#endif
 
 /* input and output queue */
 Buffer iqueue;
@@ -134,7 +131,7 @@ Handle      handles[100];
 static void
 handle_init(void)
 {
-       int i;
+       u_int i;
 
        for (i = 0; i < sizeof(handles)/sizeof(Handle); i++)
                handles[i].use = HANDLE_UNUSED;
@@ -143,7 +140,7 @@ handle_init(void)
 static int
 handle_new(int use, const char *name, int fd, DIR *dirp)
 {
-       int i;
+       u_int i;
 
        for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) {
                if (handles[i].use == HANDLE_UNUSED) {
@@ -160,7 +157,7 @@ handle_new(int use, const char *name, int fd, DIR *dirp)
 static int
 handle_is_ok(int i, int type)
 {
-       return i >= 0 && i < sizeof(handles)/sizeof(Handle) &&
+       return i >= 0 && (u_int)i < sizeof(handles)/sizeof(Handle) &&
            handles[i].use == type;
 }
 
@@ -431,7 +428,7 @@ process_read(void)
        len = get_int();
 
        TRACE("read id %u handle %d off %llu len %d", id, handle,
-           (u_int64_t)off, len);
+           (unsigned long long)off, len);
        if (len > sizeof buf) {
                len = sizeof buf;
                logit("read change len %d", len);
@@ -472,7 +469,7 @@ process_write(void)
        data = get_string(&len);
 
        TRACE("write id %u handle %d off %llu len %d", id, handle,
-           (u_int64_t)off, len);
+           (unsigned long long)off, len);
        fd = handle_to_fd(handle);
        if (fd >= 0) {
                if (lseek(fd, off, SEEK_SET) < 0) {
@@ -481,10 +478,10 @@ process_write(void)
                } else {
 /* XXX ATOMICIO ? */
                        ret = write(fd, data, len);
-                       if (ret == -1) {
+                       if (ret < 0) {
                                error("process_write: write failed");
                                status = errno_to_portable(errno);
-                       } else if (ret == len) {
+                       } else if ((size_t)ret == len) {
                                status = SSH2_FX_OK;
                        } else {
                                logit("nothing at all written");
@@ -949,7 +946,7 @@ process(void)
                return;         /* Incomplete message. */
        cp = buffer_ptr(&iqueue);
        msg_len = GET_32BIT(cp);
-       if (msg_len > 256 * 1024) {
+       if (msg_len > SFTP_MAX_MSG_LENGTH) {
                error("bad message ");
                exit(11);
        }
@@ -1040,6 +1037,9 @@ main(int ac, char **av)
        int in, out, max;
        ssize_t len, olen, set_size;
 
+       /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
+       sanitise_stdfd();
+
        /* XXX should use getopt */
 
        __progname = ssh_get_progname(av[0]);
This page took 0.0440970000000001 seconds and 4 git commands to generate.