Changeset View
Changeset View
Standalone View
Standalone View
lib/libedit/read.c
Show First 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | case (size_t)-1: | ||||
cbuf[0] = cbuf[cbp - 1]; | cbuf[0] = cbuf[cbp - 1]; | ||||
cbp = 0; | cbp = 0; | ||||
break; | break; | ||||
} else { | } else { | ||||
/* Invalid byte, discard it. */ | /* Invalid byte, discard it. */ | ||||
cbp = 0; | cbp = 0; | ||||
goto again; | goto again; | ||||
} | } | ||||
case (size_t)-2: | case (size_t)-2: | ||||
/* | |||||
* We don't support other multibyte charsets. | |||||
* The second condition shouldn't happen | |||||
* and is here merely for additional safety. | |||||
*/ | |||||
if ((el->el_flags & CHARSET_IS_UTF8) == 0 || | |||||
cbp >= MB_LEN_MAX) { | |||||
errno = EILSEQ; | |||||
*cp = L'\0'; | |||||
return -1; | |||||
} | |||||
/* Incomplete sequence, read another byte. */ | /* Incomplete sequence, read another byte. */ | ||||
naito.yuichiro_gmail.com: hrs@ says that
(cbp >= MB_LEN_MAX) condition is necessary for checking invalid byte sequences. | |||||
goto again; | goto again; | ||||
default: | default: | ||||
/* Valid character, process it. */ | /* Valid character, process it. */ | ||||
return 1; | return 1; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 354 Lines • Show Last 20 Lines |
hrs@ says that
(cbp >= MB_LEN_MAX) condition is necessary for checking invalid byte sequences.
If malicious input was given, libedit would read byte sequences forever.