Re: [PATCH] svfwscanf: Simplify _sungetwc_r to eliminate apparent buffer overflow
Keith Packard <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Keith Packard <[email protected]> writes: > A reasonable alternative would be to have the wchar_t version call the > char version multiple times, instead of just doing it inline; that would > avoid any semantic difference, which seems like a feature. I'll post a > patch that does it this way shortly and see which you prefer. Never mind -- the wchar_t function cannot simply call the char version as that would require converting to multi-byte so that EOF is handled correctly, *and* would end up breaking the getchar function which assumes that the unget buffer has wchar_t values, not multibyte values. After looking at the code further and discovering numerous other bugs in this path, I think we should just use the patch as submitted; I cannot imagine a case where POSIX would change the semantics of scanf to ever re-write the input with different characters. other bugs: 1. Assumes wchar_t is 2 bytes by setting the bytes remaining (_r) to 2. 2. Computes the pointer value by subtracting the wchar_t size from the _ubuf size, resulting in an unaligned pointer. Then uses this pointer directly in both getwc and ungetwc, which will cause a bus error on processors unable to access unaligned data. We could also simplify the matching code path in vfscanf.c at some point. -- -keith
signature.asc
(application/pgp-signature, 832 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAmEdOkEACgkQ2yIaaQAA ABEkHRAAgH6HkIFRx6/KPcIPh5iG2x2I14tpjeCLEHCARcKbg+BwCh50T9mPE/oI 5v97gur0D6p2tvs2jMVK9swb8Bq25mdgM45AcqX9KyZ8AM7pmrof/g1IKzc1Xn9/ LKepIRZa3uY5354nbECIUurxwmrD5xgPSPgg/0a+DV3rt37iQZBEG2CZuc4E4TRl 7u57kNOSPK8pkPoXCPhjf6JYeoJFn8mPkYJgEFYQVwOm3Hb/gKFmvcjWGASDpNEj T85rKdSGKyWVZXWYYcX+prdmBpiExsdGDH7JVMEV1JFLtSvwfuRe4s1xtHbC+lSC dRPHNdfdESNyWIW2DIANzN69PmXGyQxdSdJ+xIf75WGsQ6AZHz12NYvliE7Rv4+K ruJifZXO/8OHa9Z6h280mwqZjmCi2e+GNbgFJqQpjIGC9FmoRxIj1acFa5JiTmKT zF3KL6QWPIM1UmsLk9k09LMXL7vzrYH5M4cIiZX7JVzf9V41aJK9WvTmJfCYe9qW 8esa2nNYxtldzgIYGCsy61qqeqHsYnmllejFHeUPy5acsccHomYAQ9N9Ypyi8MPD ObkNffY4hmaYBwtoqqiAo7FWUkQ68McQZPSnnE3OqY3D/I+0nelSq2Ir6CULwLg4 KvhignTcU4gJt5/857Rd7g2R++TN0Xnq8gcGIB3v8nBhOy8kc4Y= =em67 -----END PGP SIGNATURE-----