Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit623f77e

Browse files
committed
Avoid possibly accessing off the end of memory in SJIS2004 conversion.
The code in shift_jis_20042euc_jis_2004() would fetch two bytes even whenonly one remained in the string. Since conversion functions aren'tsupposed to assume null-terminated input, this poses a small risk offetching past the end of memory and incurring SIGSEGV. No such crash hasbeen identified in the field, but we've certainly seen the equivalenthappen in other code paths, so patch this one all the way back.Report and patch by Noah Misch.
1 parent780a342 commit623f77e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎src/backend/utils/mb/conversion_procs/euc2004_sjis2004/euc2004_sjis2004.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ get_ten(int b, int *ku)
218218
staticvoid
219219
shift_jis_20042euc_jis_2004(constunsignedchar*sjis,unsignedchar*p,intlen)
220220
{
221-
intc1,
222-
c2;
221+
intc1;
223222
intku,
224223
ten,
225224
kubun;
@@ -229,7 +228,6 @@ shift_jis_20042euc_jis_2004(const unsigned char *sjis, unsigned char *p, int len
229228
while (len>0)
230229
{
231230
c1=*sjis;
232-
c2=sjis[1];
233231

234232
if (!IS_HIGHBIT_SET(c1))
235233
{
@@ -245,7 +243,7 @@ shift_jis_20042euc_jis_2004(const unsigned char *sjis, unsigned char *p, int len
245243

246244
l=pg_encoding_verifymb(PG_SHIFT_JIS_2004, (constchar*)sjis,len);
247245

248-
if (l<0)
246+
if (l<0||l>len)
249247
report_invalid_encoding(PG_SHIFT_JIS_2004,
250248
(constchar*)sjis,len);
251249

@@ -257,6 +255,8 @@ shift_jis_20042euc_jis_2004(const unsigned char *sjis, unsigned char *p, int len
257255
}
258256
elseif (l==2)
259257
{
258+
intc2=sjis[1];
259+
260260
plane=1;
261261
ku=1;
262262
ten=1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp