mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 7.4.1955
Problem: Using 32-bit Perl with 64-bit time_t causes memory corruption. (Christian Brabandt) Solution: Use time_T instead of time_t for global variables. (Ken Takata)
This commit is contained in:
@@ -2850,7 +2850,7 @@ write_viminfo_barlines(vir_T *virp, FILE *fp_out)
|
|||||||
* Return the current time in seconds. Calls time(), unless test_settime()
|
* Return the current time in seconds. Calls time(), unless test_settime()
|
||||||
* was used.
|
* was used.
|
||||||
*/
|
*/
|
||||||
time_t
|
time_T
|
||||||
vim_time(void)
|
vim_time(void)
|
||||||
{
|
{
|
||||||
# ifdef FEAT_EVAL
|
# ifdef FEAT_EVAL
|
||||||
|
@@ -1608,7 +1608,7 @@ EXTERN int xsmp_icefd INIT(= -1); /* The actual connection */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* For undo we need to know the lowest time possible. */
|
/* For undo we need to know the lowest time possible. */
|
||||||
EXTERN time_t starttime;
|
EXTERN time_T starttime;
|
||||||
|
|
||||||
#ifdef STARTUPTIME
|
#ifdef STARTUPTIME
|
||||||
EXTERN FILE *time_fd INIT(= NULL); /* where to write startup timing */
|
EXTERN FILE *time_fd INIT(= NULL); /* where to write startup timing */
|
||||||
@@ -1640,7 +1640,7 @@ EXTERN int did_add_timer INIT(= FALSE);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
EXTERN time_t time_for_testing INIT(= 0);
|
EXTERN time_T time_for_testing INIT(= 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
22
src/misc2.c
22
src/misc2.c
@@ -6070,12 +6070,12 @@ get4c(FILE *fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read 8 bytes from "fd" and turn them into a time_t, MSB first.
|
* Read 8 bytes from "fd" and turn them into a time_T, MSB first.
|
||||||
*/
|
*/
|
||||||
time_t
|
time_T
|
||||||
get8ctime(FILE *fd)
|
get8ctime(FILE *fd)
|
||||||
{
|
{
|
||||||
time_t n = 0;
|
time_T n = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 8; ++i)
|
for (i = 0; i < 8; ++i)
|
||||||
@@ -6137,11 +6137,11 @@ put_bytes(FILE *fd, long_u nr, int len)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write time_t to file "fd" in 8 bytes.
|
* Write time_T to file "fd" in 8 bytes.
|
||||||
* Returns FAIL when the write failed.
|
* Returns FAIL when the write failed.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
put_time(FILE *fd, time_t the_time)
|
put_time(FILE *fd, time_T the_time)
|
||||||
{
|
{
|
||||||
char_u buf[8];
|
char_u buf[8];
|
||||||
|
|
||||||
@@ -6150,26 +6150,26 @@ put_time(FILE *fd, time_t the_time)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write time_t to "buf[8]".
|
* Write time_T to "buf[8]".
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
time_to_bytes(time_t the_time, char_u *buf)
|
time_to_bytes(time_T the_time, char_u *buf)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
int i;
|
int i;
|
||||||
int bi = 0;
|
int bi = 0;
|
||||||
time_t wtime = the_time;
|
time_T wtime = the_time;
|
||||||
|
|
||||||
/* time_t can be up to 8 bytes in size, more than long_u, thus we
|
/* time_T can be up to 8 bytes in size, more than long_u, thus we
|
||||||
* can't use put_bytes() here.
|
* can't use put_bytes() here.
|
||||||
* Another problem is that ">>" may do an arithmetic shift that keeps the
|
* Another problem is that ">>" may do an arithmetic shift that keeps the
|
||||||
* sign. This happens for large values of wtime. A cast to long_u may
|
* sign. This happens for large values of wtime. A cast to long_u may
|
||||||
* truncate if time_t is 8 bytes. So only use a cast when it is 4 bytes,
|
* truncate if time_T is 8 bytes. So only use a cast when it is 4 bytes,
|
||||||
* it's safe to assume that long_u is 4 bytes or more and when using 8
|
* it's safe to assume that long_u is 4 bytes or more and when using 8
|
||||||
* bytes the top bit won't be set. */
|
* bytes the top bit won't be set. */
|
||||||
for (i = 7; i >= 0; --i)
|
for (i = 7; i >= 0; --i)
|
||||||
{
|
{
|
||||||
if (i + 1 > (int)sizeof(time_t))
|
if (i + 1 > (int)sizeof(time_T))
|
||||||
/* ">>" doesn't work well when shifting more bits than avail */
|
/* ">>" doesn't work well when shifting more bits than avail */
|
||||||
buf[bi++] = 0;
|
buf[bi++] = 0;
|
||||||
else
|
else
|
||||||
|
@@ -17,7 +17,7 @@ int viminfo_readline(vir_T *virp);
|
|||||||
char_u *viminfo_readstring(vir_T *virp, int off, int convert);
|
char_u *viminfo_readstring(vir_T *virp, int off, int convert);
|
||||||
void viminfo_writestring(FILE *fd, char_u *p);
|
void viminfo_writestring(FILE *fd, char_u *p);
|
||||||
int barline_writestring(FILE *fd, char_u *s, int remaining_start);
|
int barline_writestring(FILE *fd, char_u *s, int remaining_start);
|
||||||
time_t vim_time(void);
|
time_T vim_time(void);
|
||||||
void do_fixdel(exarg_T *eap);
|
void do_fixdel(exarg_T *eap);
|
||||||
void print_line_no_prefix(linenr_T lnum, int use_number, int list);
|
void print_line_no_prefix(linenr_T lnum, int use_number, int list);
|
||||||
void print_line(linenr_T lnum, int use_number, int list);
|
void print_line(linenr_T lnum, int use_number, int list);
|
||||||
|
@@ -103,11 +103,11 @@ int emsgn(char_u *s, long n);
|
|||||||
int get2c(FILE *fd);
|
int get2c(FILE *fd);
|
||||||
int get3c(FILE *fd);
|
int get3c(FILE *fd);
|
||||||
int get4c(FILE *fd);
|
int get4c(FILE *fd);
|
||||||
time_t get8ctime(FILE *fd);
|
time_T get8ctime(FILE *fd);
|
||||||
char_u *read_string(FILE *fd, int cnt);
|
char_u *read_string(FILE *fd, int cnt);
|
||||||
int put_bytes(FILE *fd, long_u nr, int len);
|
int put_bytes(FILE *fd, long_u nr, int len);
|
||||||
int put_time(FILE *fd, time_t the_time);
|
int put_time(FILE *fd, time_T the_time);
|
||||||
void time_to_bytes(time_t the_time, char_u *buf);
|
void time_to_bytes(time_T the_time, char_u *buf);
|
||||||
int has_non_ascii(char_u *s);
|
int has_non_ascii(char_u *s);
|
||||||
void parse_queued_messages(void);
|
void parse_queued_messages(void);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -113,7 +113,7 @@ typedef struct xfilemark
|
|||||||
fmark_T fmark;
|
fmark_T fmark;
|
||||||
char_u *fname; /* file name, used when fnum == 0 */
|
char_u *fname; /* file name, used when fnum == 0 */
|
||||||
#ifdef FEAT_VIMINFO
|
#ifdef FEAT_VIMINFO
|
||||||
time_t time_set;
|
time_T time_set;
|
||||||
#endif
|
#endif
|
||||||
} xfmark_T;
|
} xfmark_T;
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ struct u_header
|
|||||||
int uh_flags; /* see below */
|
int uh_flags; /* see below */
|
||||||
pos_T uh_namedm[NMARKS]; /* marks before undo/after redo */
|
pos_T uh_namedm[NMARKS]; /* marks before undo/after redo */
|
||||||
visualinfo_T uh_visual; /* Visual areas before undo/after redo */
|
visualinfo_T uh_visual; /* Visual areas before undo/after redo */
|
||||||
time_t uh_time; /* timestamp when the change was made */
|
time_T uh_time; /* timestamp when the change was made */
|
||||||
long uh_save_nr; /* set when the file was saved after the
|
long uh_save_nr; /* set when the file was saved after the
|
||||||
changes in this block */
|
changes in this block */
|
||||||
#ifdef U_DEBUG
|
#ifdef U_DEBUG
|
||||||
@@ -1816,7 +1816,7 @@ struct file_buffer
|
|||||||
long b_u_seq_last; /* last used undo sequence number */
|
long b_u_seq_last; /* last used undo sequence number */
|
||||||
long b_u_save_nr_last; /* counter for last file write */
|
long b_u_save_nr_last; /* counter for last file write */
|
||||||
long b_u_seq_cur; /* hu_seq of header below which we are now */
|
long b_u_seq_cur; /* hu_seq of header below which we are now */
|
||||||
time_t b_u_time_cur; /* uh_time of header below which we are now */
|
time_T b_u_time_cur; /* uh_time of header below which we are now */
|
||||||
long b_u_save_nr_cur; /* file write nr after which we are now */
|
long b_u_save_nr_cur; /* file write nr after which we are now */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -753,6 +753,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1955,
|
||||||
/**/
|
/**/
|
||||||
1954,
|
1954,
|
||||||
/**/
|
/**/
|
||||||
|
11
src/vim.h
11
src/vim.h
@@ -1761,6 +1761,17 @@ typedef struct timeval proftime_T;
|
|||||||
typedef int proftime_T; /* dummy for function prototypes */
|
typedef int proftime_T; /* dummy for function prototypes */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When compiling with 32 bit Perl time_t is 32 bits in the Perl code but 64
|
||||||
|
* bits elsewhere. That causes memory corruption. Define time_T and use it
|
||||||
|
* for global variables to avoid that.
|
||||||
|
*/
|
||||||
|
#ifdef WIN3264
|
||||||
|
typedef __time64_t time_T;
|
||||||
|
#else
|
||||||
|
typedef time_t time_T;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
typedef __int64 sock_T;
|
typedef __int64 sock_T;
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user