From: Sylvain Beucler <beuc@beuc.net>
Subject: Group skipped on buffer resize
Bug: https://sourceforge.net/p/libnss-mysql/bugs/13/
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=540399
Last-Update: 2009-08-07
Forwarded: yes

When the buffer is too small, libnss-mysql returns NSS_TRYAGAIN so
that the OS doubles the buffer size and call the function again.
However the MySQL resultset is not reset, so when the function is
called again, it uses the next row, and hence skips an entry.

This is a proof-of-concept patch that use mysql_row_tell and
mysql_row_seek to fix this issue.

[jing] rebase the patch on v1.6.1.
---
 src/nss_support.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/src/nss_support.c
+++ b/src/nss_support.c
@@ -302,6 +302,7 @@
   unsigned int num_fields;
 
   DENTER;
+  MYSQL_ROW_OFFSET save_pos = mysql_row_tell(mresult);
   retVal = _nss_mysql_fetch_row (&row, mresult);
   if (retVal != NSS_SUCCESS)
     DSRETURN (retVal);
@@ -341,6 +342,10 @@
                               errnop, _nss_mysql_load_memsbygid,
                               &mresult_grmem, "_nss_mysql_load_group");
 
+  if (retVal == NSS_TRYAGAIN && *errnop == ERANGE)
+    /* Revert to previous row, so we don't skip it next time */
+    mysql_row_seek(mresult, save_pos);
+
   DSRETURN (retVal);
 }
 
