Skip to content

Commit 5f45979

Browse files
Alexey Izbyshevmethane
Alexey Izbyshev
authored andcommitted
bpo-35194: cjkcodec: check the encoded value is not truncated (GH-10432)
1 parent 9e30fba commit 5f45979

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Modules/cjkcodecs/cjkcodecs.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,40 +149,42 @@ static const struct dbcs_map *mapping_list;
149149
writer->pos += 2; \
150150
} while (0)
151151

152-
#define OUTBYTE1(c) \
153-
do { ((*outbuf)[0]) = (c); } while (0)
154-
#define OUTBYTE2(c) \
155-
do { ((*outbuf)[1]) = (c); } while (0)
156-
#define OUTBYTE3(c) \
157-
do { ((*outbuf)[2]) = (c); } while (0)
158-
#define OUTBYTE4(c) \
159-
do { ((*outbuf)[3]) = (c); } while (0)
152+
#define OUTBYTEI(c, i) \
153+
do { \
154+
assert((unsigned char)(c) == (c)); \
155+
((*outbuf)[i]) = (c); \
156+
} while (0)
157+
158+
#define OUTBYTE1(c) OUTBYTEI(c, 0)
159+
#define OUTBYTE2(c) OUTBYTEI(c, 1)
160+
#define OUTBYTE3(c) OUTBYTEI(c, 2)
161+
#define OUTBYTE4(c) OUTBYTEI(c, 3)
160162

161163
#define WRITEBYTE1(c1) \
162164
do { \
163165
REQUIRE_OUTBUF(1); \
164-
(*outbuf)[0] = (c1); \
166+
OUTBYTE1(c1); \
165167
} while (0)
166168
#define WRITEBYTE2(c1, c2) \
167169
do { \
168170
REQUIRE_OUTBUF(2); \
169-
(*outbuf)[0] = (c1); \
170-
(*outbuf)[1] = (c2); \
171+
OUTBYTE1(c1); \
172+
OUTBYTE2(c2); \
171173
} while (0)
172174
#define WRITEBYTE3(c1, c2, c3) \
173175
do { \
174176
REQUIRE_OUTBUF(3); \
175-
(*outbuf)[0] = (c1); \
176-
(*outbuf)[1] = (c2); \
177-
(*outbuf)[2] = (c3); \
177+
OUTBYTE1(c1); \
178+
OUTBYTE2(c2); \
179+
OUTBYTE3(c3); \
178180
} while (0)
179181
#define WRITEBYTE4(c1, c2, c3, c4) \
180182
do { \
181183
REQUIRE_OUTBUF(4); \
182-
(*outbuf)[0] = (c1); \
183-
(*outbuf)[1] = (c2); \
184-
(*outbuf)[2] = (c3); \
185-
(*outbuf)[3] = (c4); \
184+
OUTBYTE1(c1); \
185+
OUTBYTE2(c2); \
186+
OUTBYTE3(c3); \
187+
OUTBYTE4(c4); \
186188
} while (0)
187189

188190
#define _TRYMAP_ENC(m, assi, val) \

0 commit comments

Comments
 (0)