2009-04-24 Jeff johnston <jjohnstn@redhat.com>

* libc/stdio/fgetc.c: Make sure sfp lock is acquired before the
        file lock and released before the file lock to avoid a deadlock
        scenario.
        * libc/stdio/fgets.c: Ditto.
        * libc/stdio/fgetwc.c: Ditto.
        * libc/stdio/fgetws.c: Ditto.
        * libc/stdio/fread.c: Ditto.
        * libc/stdio/fseek.c: Ditto.
        * libc/stdio/getc.c: Ditto.
        * libc/stdio/getdelim.c: Ditto.
        * libc/stdio/gets.c: Ditto.
This commit is contained in:
Jeff Johnston 2009-04-24 22:52:52 +00:00
parent 35f31b6a98
commit bcde129400
10 changed files with 53 additions and 0 deletions

View File

@ -1,3 +1,17 @@
2009-04-24 Jeff johnston <jjohnstn@redhat.com>
* libc/stdio/fgetc.c: Make sure sfp lock is acquired before the
file lock and released before the file lock to avoid a deadlock
scenario.
* libc/stdio/fgets.c: Ditto.
* libc/stdio/fgetwc.c: Ditto.
* libc/stdio/fgetws.c: Ditto.
* libc/stdio/fread.c: Ditto.
* libc/stdio/fseek.c: Ditto.
* libc/stdio/getc.c: Ditto.
* libc/stdio/getdelim.c: Ditto.
* libc/stdio/gets.c: Ditto.
2009-04-24 Jeff johnston <jjohnstn@redhat.com>
* configure.in: Add configuration test for long double equals dbl

View File

@ -93,9 +93,11 @@ _DEFUN(fgetc, (fp),
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
int result;
CHECK_INIT(_REENT, fp);
__sfp_lock_acquire ();
_flockfile (fp);
result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
__sfp_lock_release ();
return result;
#else
return _fgetc_r (_REENT, fp);

View File

@ -98,6 +98,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
CHECK_INIT(ptr, fp);
__sfp_lock_acquire ();
_flockfile (fp);
#ifdef __SCLE
if (fp->_flags & __SCLE)
@ -113,10 +114,12 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
if (c == EOF && s == buf)
{
_funlockfile (fp);
__sfp_lock_release ();
return NULL;
}
*s = 0;
_funlockfile (fp);
__sfp_lock_release ();
return buf;
}
#endif
@ -135,6 +138,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
if (s == buf)
{
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
break;
@ -160,6 +164,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
_CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
s[len] = 0;
_funlockfile (fp);
__sfp_lock_release ();
return (buf);
}
fp->_r -= len;
@ -170,6 +175,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
while ((n -= len) != 0);
*s = 0;
_funlockfile (fp);
__sfp_lock_release ();
return buf;
}

View File

@ -164,10 +164,12 @@ _DEFUN(_fgetwc_r, (ptr, fp),
{
wint_t r;
__sfp_lock_acquire ();
_flockfile (fp);
ORIENT(fp, 1);
r = __fgetwc (ptr, fp);
_funlockfile (fp);
__sfp_lock_release ();
return r;
}

View File

@ -93,6 +93,7 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
const char *src;
unsigned char *nl;
__sfp_lock_acquire ();
_flockfile (fp);
ORIENT (fp, 1);
@ -143,10 +144,12 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
goto error;
*wsp++ = L'\0';
_funlockfile (fp);
__sfp_lock_release ();
return ws;
error:
_funlockfile (fp);
__sfp_lock_release ();
return NULL;
}

View File

@ -146,6 +146,7 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
CHECK_INIT(ptr, fp);
__sfp_lock_acquire ();
_flockfile (fp);
ORIENT (fp, -1);
if (fp->_r < 0)
@ -196,10 +197,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
__sfp_lock_release ();
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
}
#endif
_funlockfile (fp);
__sfp_lock_release ();
return (total - resid) / size;
}
}
@ -221,10 +224,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
__sfp_lock_release ();
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
}
#endif
_funlockfile (fp);
__sfp_lock_release ();
return (total - resid) / size;
}
}
@ -238,10 +243,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
__sfp_lock_release ();
return crlf_r(ptr, fp, buf, total, 0) / size;
}
#endif
_funlockfile (fp);
__sfp_lock_release ();
return count;
}

View File

@ -138,6 +138,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
CHECK_INIT (ptr, fp);
__sfp_lock_acquire ();
_flockfile (fp);
/* If we've been doing some writing, and we're in append mode
@ -155,6 +156,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
{
ptr->_errno = ESPIPE; /* ??? */
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
@ -180,6 +182,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
if (curoff == -1L)
{
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
}
@ -205,6 +208,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
default:
ptr->_errno = EINVAL;
_funlockfile (fp);
__sfp_lock_release ();
return (EOF);
}
@ -263,6 +267,8 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
if ((long)target != target)
{
ptr->_errno = EOVERFLOW;
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
@ -319,6 +325,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
fp->_flags &= ~__SEOF;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}
@ -349,6 +356,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
}
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
/*
@ -361,6 +369,7 @@ dumb:
|| seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
{
_funlockfile (fp);
__sfp_lock_release ();
return EOF;
}
/* success: clear EOF indicator and discard ungetc() data */
@ -379,6 +388,7 @@ dumb:
fp->_flags &= ~__SNPT;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
__sfp_lock_release ();
return 0;
}

View File

@ -92,9 +92,11 @@ _DEFUN(_getc_r, (ptr, fp),
{
int result;
CHECK_INIT (ptr, fp);
__sfp_lock_acquire ();
_flockfile (fp);
result = __sgetc_r (ptr, fp);
_funlockfile (fp);
__sfp_lock_release ();
return result;
}
@ -106,9 +108,11 @@ _DEFUN(getc, (fp),
{
int result;
CHECK_INIT (_REENT, fp);
__sfp_lock_acquire ();
_flockfile (fp);
result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
__sfp_lock_release ();
return result;
}

View File

@ -81,6 +81,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
CHECK_INIT (_REENT, fp);
__sfp_lock_acquire ();
_flockfile (fp);
numbytes = *n;
@ -130,6 +131,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
}
_funlockfile (fp);
__sfp_lock_release ();
/* if no input data, return failure */
if (ptr == buf)

View File

@ -79,12 +79,14 @@ _DEFUN(_gets_r, (ptr, buf),
register int c;
register char *s = buf;
__sfp_lock_acquire ();
_flockfile (stdin);
while ((c = __sgetc_r (ptr, stdin)) != '\n')
if (c == EOF)
if (s == buf)
{
_funlockfile (stdin);
__sfp_lock_release ();
return NULL;
}
else
@ -93,6 +95,7 @@ _DEFUN(_gets_r, (ptr, buf),
*s++ = c;
*s = 0;
_funlockfile (stdin);
__sfp_lock_release ();
return buf;
}