summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-08 18:51:47 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-08 18:51:47 +1100
commitb5082e90a13c9c9f96f1aed894f70f6f00737396 (patch)
tree188bbc53212f0e93f5ae6fe4a8f995c7052586ee /sftp.c
parent75694dbe77c56c127a2d2cfd443a0d591f441a55 (diff)
- dtucker@cvs.openbsd.org 2009/12/06 23:53:54
[sftp.c] fix potential divide-by-zero in sftp's "df" output when talking to a server that reports zero files on the filesystem (Unix filesystems always have at least the root inode). From Steve McClellan at radisys, ok djm@
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sftp.c b/sftp.c
index 2ce7cc1e1..1aa37423c 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.113 2009/11/22 13:18:00 halex Exp $ */ 1/* $OpenBSD: sftp.c,v 1.114 2009/12/06 23:53:54 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -846,19 +846,19 @@ do_df(struct sftp_conn *conn, char *path, int hflag, int iflag)
846 char s_avail[FMT_SCALED_STRSIZE]; 846 char s_avail[FMT_SCALED_STRSIZE];
847 char s_root[FMT_SCALED_STRSIZE]; 847 char s_root[FMT_SCALED_STRSIZE];
848 char s_total[FMT_SCALED_STRSIZE]; 848 char s_total[FMT_SCALED_STRSIZE];
849 unsigned long long ffree;
849 850
850 if (do_statvfs(conn, path, &st, 1) == -1) 851 if (do_statvfs(conn, path, &st, 1) == -1)
851 return -1; 852 return -1;
852 if (iflag) { 853 if (iflag) {
854 ffree = st.f_files ? (100 * (st.f_files - st.f_ffree) / st.f_files) : 0;
853 printf(" Inodes Used Avail " 855 printf(" Inodes Used Avail "
854 "(root) %%Capacity\n"); 856 "(root) %%Capacity\n");
855 printf("%11llu %11llu %11llu %11llu %3llu%%\n", 857 printf("%11llu %11llu %11llu %11llu %3llu%%\n",
856 (unsigned long long)st.f_files, 858 (unsigned long long)st.f_files,
857 (unsigned long long)(st.f_files - st.f_ffree), 859 (unsigned long long)(st.f_files - st.f_ffree),
858 (unsigned long long)st.f_favail, 860 (unsigned long long)st.f_favail,
859 (unsigned long long)st.f_ffree, 861 (unsigned long long)st.f_ffree, ffree);
860 (unsigned long long)(100 * (st.f_files - st.f_ffree) /
861 st.f_files));
862 } else if (hflag) { 862 } else if (hflag) {
863 strlcpy(s_used, "error", sizeof(s_used)); 863 strlcpy(s_used, "error", sizeof(s_used));
864 strlcpy(s_avail, "error", sizeof(s_avail)); 864 strlcpy(s_avail, "error", sizeof(s_avail));