Prevent use of uninitialized file lock
The CHECK_INIT() is necessary before the _newlib_flockfile_start() since this would use otherwise acquire an uninitialized lock which gets initialized after this leading to a corrupt release. newlib/ChangeLog 2015-07-01 Sebastian Huber <sebastian.huber@embedded-brains.de> libc/stdio/fputs.c (_puts_r): Add missing CHECK_INIT(). libc/stdio/gets.c (_gets_r): Add missing _REENT_SMALL_CHECK_INIT() and CHECK_INIT(). Use _stdin_r() to get the file pointer instead of stdin. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
fc22f77503
commit
757c0871f7
|
@ -1,3 +1,9 @@
|
||||||
|
2015-07-01 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
||||||
|
|
||||||
|
* libc/stdio/fputs.c (_puts_r): Add missing CHECK_INIT().
|
||||||
|
* libc/stdio/gets.c (_gets_r): Add missing _REENT_SMALL_CHECK_INIT() and
|
||||||
|
CHECK_INIT(). Use _stdin_r() to get the file pointer instead of stdin.
|
||||||
|
|
||||||
2015-06-29 Jon Turney <jon.turney@dronecode.org.uk>
|
2015-06-29 Jon Turney <jon.turney@dronecode.org.uk>
|
||||||
|
|
||||||
* libc/ctype/Makefile.in: Regenerate.
|
* libc/ctype/Makefile.in: Regenerate.
|
||||||
|
|
|
@ -79,13 +79,17 @@ _DEFUN(_gets_r, (ptr, buf),
|
||||||
{
|
{
|
||||||
register int c;
|
register int c;
|
||||||
register char *s = buf;
|
register char *s = buf;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
_newlib_flockfile_start (stdin);
|
_REENT_SMALL_CHECK_INIT (ptr);
|
||||||
while ((c = __sgetc_r (ptr, stdin)) != '\n')
|
fp = _stdin_r (ptr);
|
||||||
|
CHECK_INIT (ptr, fp);
|
||||||
|
_newlib_flockfile_start (fp);
|
||||||
|
while ((c = __sgetc_r (ptr, fp)) != '\n')
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
if (s == buf)
|
if (s == buf)
|
||||||
{
|
{
|
||||||
_newlib_flockfile_exit (stdin);
|
_newlib_flockfile_exit (fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -93,7 +97,7 @@ _DEFUN(_gets_r, (ptr, buf),
|
||||||
else
|
else
|
||||||
*s++ = c;
|
*s++ = c;
|
||||||
*s = 0;
|
*s = 0;
|
||||||
_newlib_flockfile_end (stdin);
|
_newlib_flockfile_end (fp);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ _DEFUN(_puts_r, (ptr, s),
|
||||||
|
|
||||||
_REENT_SMALL_CHECK_INIT (ptr);
|
_REENT_SMALL_CHECK_INIT (ptr);
|
||||||
fp = _stdout_r (ptr);
|
fp = _stdout_r (ptr);
|
||||||
|
CHECK_INIT (ptr, fp);
|
||||||
_newlib_flockfile_start (fp);
|
_newlib_flockfile_start (fp);
|
||||||
ORIENT (fp, -1);
|
ORIENT (fp, -1);
|
||||||
result = (__sfvwrite_r (ptr, fp, &uio) ? EOF : '\n');
|
result = (__sfvwrite_r (ptr, fp, &uio) ? EOF : '\n');
|
||||||
|
@ -107,6 +108,7 @@ _DEFUN(_puts_r, (ptr, s),
|
||||||
_REENT_SMALL_CHECK_INIT (ptr);
|
_REENT_SMALL_CHECK_INIT (ptr);
|
||||||
|
|
||||||
fp = _stdout_r (ptr);
|
fp = _stdout_r (ptr);
|
||||||
|
CHECK_INIT (ptr, fp);
|
||||||
_newlib_flockfile_start (fp);
|
_newlib_flockfile_start (fp);
|
||||||
ORIENT (fp, -1);
|
ORIENT (fp, -1);
|
||||||
/* Make sure we can write. */
|
/* Make sure we can write. */
|
||||||
|
|
Loading…
Reference in New Issue