Lines 1-71
Link Here
|
1 |
--- src/cdf.c.orig 2019-10-22 21:52:28 UTC |
|
|
2 |
+++ src/cdf.c |
3 |
@@ -35,7 +35,7 @@ |
4 |
#include "file.h" |
5 |
|
6 |
#ifndef lint |
7 |
-FILE_RCSID("@(#)$File: cdf.c,v 1.114 2019/02/20 02:35:27 christos Exp $") |
8 |
+FILE_RCSID("@(#)$File: cdf.c,v 1.116 2019/08/26 14:31:39 christos Exp $") |
9 |
#endif |
10 |
|
11 |
#include <assert.h> |
12 |
@@ -53,6 +53,10 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.114 2019/02/20 02:35: |
13 |
#define EFTYPE EINVAL |
14 |
#endif |
15 |
|
16 |
+#ifndef SIZE_T_MAX |
17 |
+#define SIZE_T_MAX CAST(size_t, ~0ULL) |
18 |
+#endif |
19 |
+ |
20 |
#include "cdf.h" |
21 |
|
22 |
#ifdef CDF_DEBUG |
23 |
@@ -405,7 +409,12 @@ cdf_read_sector(const cdf_info_t *info, void *buf, siz |
24 |
const cdf_header_t *h, cdf_secid_t id) |
25 |
{ |
26 |
size_t ss = CDF_SEC_SIZE(h); |
27 |
- size_t pos = CDF_SEC_POS(h, id); |
28 |
+ size_t pos; |
29 |
+ |
30 |
+ if (SIZE_T_MAX / ss < CAST(size_t, id)) |
31 |
+ return -1; |
32 |
+ |
33 |
+ pos = CDF_SEC_POS(h, id); |
34 |
assert(ss == len); |
35 |
return cdf_read(info, CAST(off_t, pos), RCAST(char *, buf) + offs, len); |
36 |
} |
37 |
@@ -415,7 +424,12 @@ cdf_read_short_sector(const cdf_stream_t *sst, void *b |
38 |
size_t len, const cdf_header_t *h, cdf_secid_t id) |
39 |
{ |
40 |
size_t ss = CDF_SHORT_SEC_SIZE(h); |
41 |
- size_t pos = CDF_SHORT_SEC_POS(h, id); |
42 |
+ size_t pos; |
43 |
+ |
44 |
+ if (SIZE_T_MAX / ss < CAST(size_t, id)) |
45 |
+ return -1; |
46 |
+ |
47 |
+ pos = CDF_SHORT_SEC_POS(h, id); |
48 |
assert(ss == len); |
49 |
if (pos + len > CDF_SEC_SIZE(h) * sst->sst_len) { |
50 |
DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %" |
51 |
@@ -1013,8 +1027,9 @@ cdf_read_property_info(const cdf_stream_t *sst, const |
52 |
goto out; |
53 |
} |
54 |
nelements = CDF_GETUINT32(q, 1); |
55 |
- if (nelements == 0) { |
56 |
- DPRINTF(("CDF_VECTOR with nelements == 0\n")); |
57 |
+ if (nelements > CDF_ELEMENT_LIMIT || nelements == 0) { |
58 |
+ DPRINTF(("CDF_VECTOR with nelements == %" |
59 |
+ SIZE_T_FORMAT "u\n", nelements)); |
60 |
goto out; |
61 |
} |
62 |
slen = 2; |
63 |
@@ -1056,8 +1071,6 @@ cdf_read_property_info(const cdf_stream_t *sst, const |
64 |
goto out; |
65 |
inp += nelem; |
66 |
} |
67 |
- DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n", |
68 |
- nelements)); |
69 |
for (j = 0; j < nelements && i < sh.sh_properties; |
70 |
j++, i++) |
71 |
{ |