On Mon, 2008-03-10 at 06:37 +0000, Nigel Kukard wrote:
> Might be a good idea to identify exactly which versions of MySQL are
> affected, as far as I can determine this is a MySQL issue and not a
> Policyd issue. ie. Doing a query and aborting it or having it timeout
> should also nuke the results for that query, not return them in a
> subsequent query. No harm in adding a work-around though.

I'm running mysql 5.0.51a, and the bug is present.

I wrote a simple C program to test it.  You will need to compile and run
it on your policyd database server.   For me, it outputs:

Long query returned 7662499
Long query returned -1
Short query returned 7662499
Short query returned 1

but it should output:

Long query returned 7662499
Long query returned -1
Short query returned 1
Short query returned 1

If the second "Long query" doesn't return -1, you will need to adjust
the long query to something that takes longer than 1 second on your
server.

Dan



/* Change MYSQLUSER and MYSQLPASS to match your info, then complie
   with something like:

   gcc -I/usr/local/include/mysql -L/usr/local/lib/mysql -lmysqlclient -o illustrate_bug illustrate_bug.c

*/

#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
#include <sys/signal.h>
#include <setjmp.h>

#define MYSQLUSER "postfix"
#define MYSQLPASS "p0stf1x"

MYSQL *mysql;
sigjmp_buf sjmp;

int run_long_query(int);
int run_short_query(void);
void sigalrm_handler(void); 

main ()
{

  mysql=mysql_init(NULL);

  mysql_real_connect(mysql, "127.0.0.1", MYSQLUSER, MYSQLPASS, "policyd", 3306, NULL, 0);

   int count;

   count=run_long_query(0);
   printf("Long query returned %d\n", count);
   count=run_long_query(1);
   printf("Long query returned %d\n", count);
   count=run_short_query();
   printf("Short query returned %d\n", count);
   count=run_short_query();
   printf("Short query returned %d\n", count);

}

int run_long_query(int timeout)
{
  
  if( sigsetjmp (sjmp, 1) ){
    alarm (0);
    signal (SIGALRM, SIG_DFL);
    return(-1);
  }

  signal (SIGALRM, (void *) sigalrm_handler);
  alarm(timeout);

  mysql_query(mysql, "SELECT COUNT(*) from triplet where _count=1");

  alarm (0);
  signal (SIGALRM, SIG_DFL);

  MYSQL_RES *res=mysql_store_result(mysql);
  MYSQL_ROW row=mysql_fetch_row(res);
  int count=atoi(*row);
  return count;
}

int run_short_query()
{

  mysql_query(mysql, "SELECT COUNT(*) from whitelist where _whitelist='127.0.0.1'");

  MYSQL_RES *res=mysql_store_result(mysql);
  if( ! res ){ return 0; }
  MYSQL_ROW row=mysql_fetch_row(res);
  int count=atoi(*row);
  return count;
}

void sigalrm_handler (void)
{
  alarm (0);                      /* reset alarm timer */
  siglongjmp (sjmp, 1);           /* jump back */
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
policyd-users mailing list
policyd-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/policyd-users

Reply via email to