[evlog-dev] Wrong use of _SC_GETPW_R_SIZE_MAX
Benoit Guillon <[email protected]> Tue, 20 Apr 2004 16:15:28 +0200
| Newsgroups | gmane.linux.kernel.event-logging |
|---|---|
| Message-ID | <[email protected]> |
--------------20DD0134750D401AA9E977A3
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: Quoted-Printable
Hello again,
In posix1.c (I haven't check the other files) _SC_GETPW_R_SIZE_MAX is
used as buffer size. Actually it is a variable name, not the size
itself. You should use sysconf() to have the real size.
It could give something like this:
case POSIX_LOG_ENTRY_UID:
{
#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
struct passwd *pw, passwd;
size_t buflen;
char * buf;
/* If host is a rmt host - don't resolve the user name */
if ((entry->log_processor >> 16) !=3D 0) goto _rmt_user_exit;
buflen =3D sysconf(_SC_GETPW_R_SIZE_MAX);
/* one should check the buflen value */
buf =3D (char *)malloc(buflen);
(void) getpwuid_r(entry->log_uid, &passwd, buf,
buflen, &pw);
#else
struct passwd *pw;
/* If host is a rmt host - don't resolve the user name */
if ((entry->log_processor >> 16) !=3D 0) goto _rmt_user_exit;
pw =3D getpwuid(entry->log_uid);
#endif
if (pw) {
(void) strcpy(s, pw->pw_name);
} else {
(void) snprintf(s, sizeof(s), "%u", entry->log_uid);
}
#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
free(buf);
#endif
Bye,
--
Beno=EEt Guillon [email protected]
--------------20DD0134750D401AA9E977A3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7Bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hello again,
<p>In posix1.c (I haven't check the other files) _SC_GETPW_R_SIZE_MAX is
used as buffer size. Actually it is a variable name, not the size itself.
You should use sysconf() to have the real size.
<p>It could give something like this:
<p><tt> case POSIX_LOG_ENTRY_UID:</tt>
<br><tt> {</tt>
<br><tt>#ifdef _POSIX_THREAD_SAFE_FUNCTIONS</tt>
<br><tt> struct passwd *pw, passwd;</tt>
<br><tt> size_t buflen;</tt>
<br><tt> char * buf;</tt>
<br><tt> /* If host is a rmt host - don't resolve the user name */</tt>
<br><tt> if ((entry->log_processor >> 16) != 0) goto _rmt_user_exit;</tt>
<br><tt> buflen = sysconf(_SC_GETPW_R_SIZE_MAX);</tt>
<br><tt> /* one should check the buflen value */</tt>
<br><tt> buf = (char *)malloc(buflen);</tt>
<br><tt> (void) getpwuid_r(entry->log_uid, &passwd, buf,</tt>
<br><tt>
buflen, &pw);</tt>
<br><tt>#else</tt>
<br><tt> struct passwd *pw;</tt>
<br><tt> /* If host is a rmt host - don't resolve the user name */</tt>
<br><tt> if ((entry->log_processor >> 16) != 0) goto _rmt_user_exit;</tt>
<br><tt> pw = getpwuid(entry->log_uid);</tt>
<br><tt>#endif</tt>
<br><tt> if (pw) {</tt>
<br><tt> (void) strcpy(s, pw->pw_name);</tt>
<br><tt> } else {</tt>
<br><tt> (void) snprintf(s, sizeof(s), "%u", entry->log_uid);</tt>
<br><tt> }</tt>
<br><tt>#ifdef _POSIX_THREAD_SAFE_FUNCTIONS</tt>
<br><tt> free(buf);</tt>
<br><tt>#endif</tt>
<br><tt></tt>
<p>Bye,
<pre>--
Benoît Guillon [email protected]
</pre>
</html>
--------------20DD0134750D401AA9E977A3--
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click