[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>&nbsp;case POSIX_LOG_ENTRY_UID:</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp; {</tt>
<br><tt>#ifdef _POSIX_THREAD_SAFE_FUNCTIONS</tt>
<br><tt>&nbsp; struct passwd *pw, passwd;</tt>
<br><tt>&nbsp; size_t buflen;</tt>
<br><tt>&nbsp; char * buf;</tt>
<br><tt>&nbsp; /* If host is a rmt host - don't resolve the user name */</tt>
<br><tt>&nbsp; if ((entry->log_processor >> 16) != 0) goto _rmt_user_exit;</tt>
<br><tt>&nbsp; buflen = sysconf(_SC_GETPW_R_SIZE_MAX);</tt>
<br><tt>&nbsp; /* one should check the buflen value */</tt>
<br><tt>&nbsp; buf = (char *)malloc(buflen);</tt>
<br><tt>&nbsp; (void) getpwuid_r(entry->log_uid, &amp;passwd, buf,</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
buflen, &amp;pw);</tt>
<br><tt>#else</tt>
<br><tt>&nbsp; struct passwd *pw;</tt>
<br><tt>&nbsp; /* If host is a rmt host - don't resolve the user name */</tt>
<br><tt>&nbsp; if ((entry->log_processor >> 16) != 0) goto _rmt_user_exit;</tt>
<br><tt>&nbsp; pw = getpwuid(entry->log_uid);</tt>
<br><tt>#endif</tt>
<br><tt>&nbsp;if (pw) {</tt>
<br><tt>&nbsp;&nbsp; (void) strcpy(s, pw->pw_name);</tt>
<br><tt>&nbsp; } else {</tt>
<br><tt>&nbsp;&nbsp; (void) snprintf(s, sizeof(s), "%u", entry->log_uid);</tt>
<br><tt>&nbsp; }</tt>
<br><tt>#ifdef _POSIX_THREAD_SAFE_FUNCTIONS</tt>
<br><tt>&nbsp; free(buf);</tt>
<br><tt>#endif</tt>
<br><tt></tt>&nbsp;
<p>Bye,
<pre>--
Beno&icirc;t Guillon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [email protected]&nbsp;
</pre>
&nbsp;</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