On 21/06/14 11:11 PM, Brad Smith wrote:
On 21/06/14 11:01 PM, Jérémie Courrèges-Anglas wrote:

(Redirecting this to ports@)

Could you folks test this patch against dovecot from -stable?  I only
did compile testing on -current.  I don't know how the allocator(s)
handle failures nor how would i_realloc handle pwbuf_size ==
old_pwbuf_size, but this looks safe.

I forgot about this. I had put this in just after the new allocation
style was added to Dovecot as a workaround until the libc functions
were fixed. This would be Ok for 5.5.

Oh my bad this wasn't what I had commited. It just looked similar when
I looked at it quickly.

As I just took a look back at what I had commited..

http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/ports/mail/dovecot/patches/patch-src_lib_ipwd_c?rev=1.4;content-type=text%2Fplain

I'm just wondering if it would be better to put that in instead.

$OpenBSD$

Hack: we avoid the actual ERANGE error case by always providing a large
enough buffer.

--- src/lib/ipwd.c.orig    Tue Nov 19 21:36:30 2013
+++ src/lib/ipwd.c    Sun Jun 22 04:31:43 2014
@@ -15,24 +15,26 @@ static size_t pwbuf_size, grbuf_size;
  static void pw_init(void)
  {
      size_t old_pwbuf_size = pwbuf_size;
+    size_t new_pwbuf_size;

-    if (pwbuf == NULL || errno == ERANGE) {
-        pwbuf_size = nearest_power(old_pwbuf_size + 1);
-        if (pwbuf_size < PWBUF_MIN_SIZE)
-            pwbuf_size = PWBUF_MIN_SIZE;
-        pwbuf = i_realloc(pwbuf, old_pwbuf_size, pwbuf_size);
+    if (pwbuf == NULL) {
+        new_pwbuf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
+        pwbuf = i_realloc(pwbuf, old_pwbuf_size, new_pwbuf_size);
+        if (pwbuf != NULL)
+            pwbuf_size = new_pwbuf_size;
      }
  }

  static void gr_init(void)
  {
      size_t old_grbuf_size = grbuf_size;
+    size_t new_grbuf_size;

-    if (grbuf == NULL || errno == ERANGE) {
-        grbuf_size = nearest_power(old_grbuf_size + 1);
-        if (grbuf_size < PWBUF_MIN_SIZE)
-            grbuf_size = PWBUF_MIN_SIZE;
-        grbuf = i_realloc(grbuf, old_grbuf_size, grbuf_size);
+    if (grbuf == NULL) {
+        new_grbuf_size = sysconf(_SC_GETGR_R_SIZE_MAX);
+        grbuf = i_realloc(grbuf, old_grbuf_size, new_grbuf_size);
+        if (grbuf != NULL)
+            grbuf_size = new_grbuf_size;
      }
  }

@@ -50,11 +52,6 @@ int i_getpwnam(const char *name, struct passwd *pwd_r)
      do {
          pw_init();
          errno = getpwnam_r(name, pwd_r, pwbuf, pwbuf_size, &result);
-#ifdef __OpenBSD__
-        /* OpenBSD returns 1 for all errors, assume it's ERANGE */
-        if (errno == 1)
-            errno = ERANGE;
-#endif
      } while (errno == ERANGE);
      if (result != NULL)
          return 1;
@@ -73,11 +70,6 @@ int i_getpwuid(uid_t uid, struct passwd *pwd_r)
      do {
          pw_init();
          errno = getpwuid_r(uid, pwd_r, pwbuf, pwbuf_size, &result);
-#ifdef __OpenBSD__
-        /* OpenBSD returns 1 for all errors, assume it's ERANGE */
-        if (errno == 1)
-            errno = ERANGE;
-#endif
      } while (errno == ERANGE);
      if (result != NULL)
          return 1;






--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Reply via email to