Package: proftpd-basic
Severity: minor
Tags: upstream patch

Hi!

proftpd prints the wrong unit prefix if you put "%f" in your welcome
message, it's always an order of magnitude too large, e.g., 500TB
instead of 500GB.

The culprit is format_size_str() in src/display.c, the i variable is
always off by one. Note that you could also do a "i--;" after the while
loop, however, for the corner case of filesystems smaller than 1KB, this
would result in "i == -1" which would be "MAX_INT" given its current
"unsigned declaration".

I hence took the liberty to convert it to signed, start at -1 and
increment it in every iteration, so the index into the units[] array
remains correct.

I also dropped the "register" qualifier, the compiler would choose it
anyway if appropriate.

Please forward this patch to upstream, I don't want to deal with its
bugtracker. I assume that the Debian package maintainer is already in
permament contact with upstream. ;)


Cheers

-- System Information:
Debian Release: 7.0
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.7.4 (SMP w/8 CPU cores; PREEMPT)
Locale: LANG=C, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to 
en_US.UTF-8)
Shell: /bin/sh linked to /bin/dash
From: Adrian Knoth <a...@drcomp.erfurt.thur.de>
Description: Fix unit prefix in reported filesystem size
 The format_size_str() function contains an off-by-one error when
 calculating the proper Kilo/Mega/Giga... prefix.
--- a/src/display.c
+++ b/src/display.c
@@ -34,13 +34,13 @@ static const char *prev_msg = NULL;
 
 static void format_size_str(char *buf, size_t buflen, off_t size) {
   char units[] = {'K', 'M', 'G', 'T', 'P'};
-  register unsigned int i = 0;
+  int i = -1;
 
   /* Determine the appropriate units label to use. */
-  while (size > 1024) {
+  do {
     size /= 1024;
     i++;
-  }
+  } while (size > 1024);
 
   /* Now, prepare the buffer. */
   snprintf(buf, buflen, "%.3" PR_LU "%cB", (pr_off_t) size, units[i]);

Reply via email to