1
0
Fork 0

Bug 899: Fix size handling in FTP directory listings

This fixes parse_ftp_number to use off_t instead of long to store its
(intermediate) result and return type. It also introduces an OFFT_MAX type
"limit" that is used for validating the size of the parsed number.

A test-case for was added in 37c9bf3f75 to
test-ftp-parser and the patch has been confirmed to fix the test-case by
adamg and me.  This closes bug 899, which is a duplicate of debian bug
403139.
This commit is contained in:
Jonas Fonseca 2006-12-18 18:50:47 +01:00
parent a1fe5cf975
commit 7589d4457a
4 changed files with 31 additions and 9 deletions

View File

@ -53,6 +53,28 @@
#endif
#endif
#if defined(HAVE_LONG_LONG) && !defined(LLONG_MAX)
#ifdef MAXLLONG
#define LLONG_MAX MAXLLONG
#elif SIZEOF_LONG_LONG == 8
#define LLONG_MAX 9223372036854775807LL
#elif SIZEOF_LONG_LONG == 4
#define LLONG_MAX LONG_MAX
#endif
#endif
#ifndef OFFT_MAX
#if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T == SIZEOF_LONG_LONG
#define OFFT_MAX LLONG_MAX
#elif SIZEOF_OFF_T == SIZEOF_LONG
#define OFFT_MAX LONG_MAX
#elif SIZEOF_OFF_T == SIZEOF_INT
#define OFFT_MAX INT_MAX
#elif SIZEOF_OFF_T == SIZEOF_SHORT
#define OFFT_MAX SHRT_MAX
#endif
#endif
#ifndef HAVE_UINT16_T
#if SIZEOF_CHAR == 2
typedef unsigned char uint16_t;

View File

@ -1091,7 +1091,7 @@ display_dir_entry(struct cache_entry *cached, off_t *pos, int *tries,
add_to_string(&string, " 1 ftp ftp ");
if (ftp_info->size != FTP_SIZE_UNKNOWN) {
add_format_to_string(&string, "%12lu ", ftp_info->size);
add_format_to_string(&string, "%12" OFF_T_FORMAT " ", ftp_info->size);
} else {
add_to_string(&string, " - ");
}

View File

@ -41,10 +41,10 @@
#define skip_nonspace_end(src, end) \
do { while ((src) < (end) && *(src) != ' ') (src)++; } while (0)
static long
parse_ftp_number(unsigned char **src, unsigned char *end, long from, long to)
static off_t
parse_ftp_number(unsigned char **src, unsigned char *end, off_t from, off_t to)
{
long number = 0;
off_t number = 0;
unsigned char *pos = *src;
for (; pos < end && isdigit(*pos); pos++)
@ -104,7 +104,7 @@ parse_ftp_eplf_response(struct ftp_file_info *info, unsigned char *src, int len)
case FTP_EPLF_SIZE:
if (src >= pos) break;
info->size = parse_ftp_number(&src, pos, 0, LONG_MAX);
info->size = parse_ftp_number(&src, pos, 0, OFFT_MAX);
break;
case FTP_EPLF_MTIME:
@ -278,7 +278,7 @@ parse_ftp_unix_response(struct ftp_file_info *info, unsigned char *src, int len)
break;
}
info->size = parse_ftp_number(&src, pos, 0, LONG_MAX);
info->size = parse_ftp_number(&src, pos, 0, OFFT_MAX);
break;
case FTP_UNIX_DAY:
@ -543,7 +543,7 @@ parse_ftp_winnt_response(struct ftp_file_info *info, unsigned char *src, int len
memset(&mtime, 0, sizeof(mtime));
mtime.tm_isdst = -1;
mtime.tm_mon = parse_ftp_number(&src, end, 1, 12);
mtime.tm_mon = (int) parse_ftp_number(&src, end, 1, 12);
if (src + 2 >= end || *src != '-')
return NULL;
@ -587,7 +587,7 @@ parse_ftp_winnt_response(struct ftp_file_info *info, unsigned char *src, int len
} else if (isdigit(*src)) {
info->type = FTP_FILE_PLAINFILE;
info->size = parse_ftp_number(&src, end, 0, LONG_MAX);
info->size = parse_ftp_number(&src, end, 0, OFFT_MAX);
info->permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
} else {

View File

@ -19,7 +19,7 @@ struct ftp_file_info {
enum ftp_file_type type; /* File type */
struct string name; /* File name */
struct string symlink; /* Link to which file points */
long size; /* File size. -1 if unknown. */
off_t size; /* File size. -1 if unknown. */
time_t mtime; /* Modification time */
unsigned int local_time_zone:1; /* What format the mtime is in */
mode_t permissions; /* File permissions */