Skip to content

Commit e26e0d2

Browse files
committed
patch 8.0.1620: reading spell file has no good EOF detection
Problem: Reading spell file has no good EOF detection. Solution: Check for EOF at every character read for a length field.
1 parent 81c3c89 commit e26e0d2

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/misc2.c

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6148,59 +6148,83 @@ filewritable(char_u *fname)
61486148
#if defined(FEAT_SPELL) || defined(FEAT_PERSISTENT_UNDO) || defined(PROTO)
61496149
/*
61506150
* Read 2 bytes from "fd" and turn them into an int, MSB first.
6151+
* Returns -1 when encountering EOF.
61516152
*/
61526153
int
61536154
get2c(FILE *fd)
61546155
{
6155-
int n;
6156+
int c, n;
61566157

61576158
n = getc(fd);
6158-
n = (n << 8) + getc(fd);
6159-
return n;
6159+
if (n == EOF) return -1;
6160+
c = getc(fd);
6161+
if (c == EOF) return -1;
6162+
return (n << 8) + c;
61606163
}
61616164

61626165
/*
61636166
* Read 3 bytes from "fd" and turn them into an int, MSB first.
6167+
* Returns -1 when encountering EOF.
61646168
*/
61656169
int
61666170
get3c(FILE *fd)
61676171
{
6168-
int n;
6172+
int c, n;
61696173

61706174
n = getc(fd);
6171-
n = (n << 8) + getc(fd);
6172-
n = (n << 8) + getc(fd);
6173-
return n;
6175+
if (n == EOF) return -1;
6176+
c = getc(fd);
6177+
if (c == EOF) return -1;
6178+
n = (n << 8) + c;
6179+
c = getc(fd);
6180+
if (c == EOF) return -1;
6181+
return (n << 8) + c;
61746182
}
61756183

61766184
/*
61776185
* Read 4 bytes from "fd" and turn them into an int, MSB first.
6186+
* Returns -1 when encountering EOF.
61786187
*/
61796188
int
61806189
get4c(FILE *fd)
61816190
{
6191+
int c;
61826192
/* Use unsigned rather than int otherwise result is undefined
61836193
* when left-shift sets the MSB. */
61846194
unsigned n;
61856195

6186-
n = (unsigned)getc(fd);
6187-
n = (n << 8) + (unsigned)getc(fd);
6188-
n = (n << 8) + (unsigned)getc(fd);
6189-
n = (n << 8) + (unsigned)getc(fd);
6196+
c = getc(fd);
6197+
if (c == EOF) return -1;
6198+
n = (unsigned)c;
6199+
c = getc(fd);
6200+
if (c == EOF) return -1;
6201+
n = (n << 8) + (unsigned)c;
6202+
c = getc(fd);
6203+
if (c == EOF) return -1;
6204+
n = (n << 8) + (unsigned)c;
6205+
c = getc(fd);
6206+
if (c == EOF) return -1;
6207+
n = (n << 8) + (unsigned)c;
61906208
return (int)n;
61916209
}
61926210

61936211
/*
61946212
* Read 8 bytes from "fd" and turn them into a time_T, MSB first.
6213+
* Returns -1 when encountering EOF.
61956214
*/
61966215
time_T
61976216
get8ctime(FILE *fd)
61986217
{
6218+
int c;
61996219
time_T n = 0;
62006220
int i;
62016221

62026222
for (i = 0; i < 8; ++i)
6203-
n = (n << 8) + getc(fd);
6223+
{
6224+
c = getc(fd);
6225+
if (c == EOF) return -1;
6226+
n = (n << 8) + c;
6227+
}
62046228
return n;
62056229
}
62066230

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ static char *(features[]) =
766766

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1620,
769771
/**/
770772
1619,
771773
/**/

0 commit comments

Comments
 (0)