Segfault in mysql_real_escape_string

2004-09-06 Thread Ruben Safir Secretary NYLXS
Hello

I'm getting a segmentation fault in the mysql function mysql_real_escape_string
and I don't have a clue why.  What am I missing?

#include mysql.h /* Headers for MySQL usage */
#include stdio.h
#include stdlib.h
#include string.h

// #define INSERT_STATEMENT INSERT INTO patient (idno,first,last,medrec) 
VALUES(NULL,?,?,?)

static MYSQL clinical_db;
/* static MYSQL_STMT *stmt; */
/* static MYSQL_BIND cols[3]; */
static my_ulonglong affected_rows;
/*static int param_count; */
static unsigned long str_length;
char str_data[1024];
/* static my_bool is_null; */


int main(int argc, char **argv){
  int insert_id;
  char *encdata, *query, *end, *value;
  int datasize;
  int param_count;
  
  MYSQL_RES *res; /* To be used to fetch information into */
  MYSQL_ROW row;

  mysql_init(clinical_db);

  if(mysql_real_connect(clinical_db, localhost, pharmacy, show22case, 
clinical, 0, NULL, 0)){
  fprintf(stderr, No Connection: %s\n, mysql_error(clinical_db));
  exit(0);
  }
  printf (Hey this worked\n);
  
/* Prepared statements not supported in this version of MYSQL */  
 
/*  stmt = mysql_stmt_init(clinical_db);  */
 
//  if(!stmt){
//   fprintf(stderr, mysql_stmt_init(), out of memory\n);
//   exit(0);
// }
 
//  if(mysql_stmt_prepare(stmt, INSERT_STATEMENT, strlen(INSERT_STATEMENT))){
//  fprintf(stderr, mysql_stmt_prepare(), INSERT failed\n);
//   fprintf(stderr, %s\n, mysql_stmt_error(stmt));
//  }   

/* Get parameter count and hope it is right */
//param_count = mysql_stmt_param_count(stmt);
//fprintf(stdout, total params are %d\n, param_count);

  /* Let's try to add something to the database */

query = malloc(2048);
value = malloc(2048);
encdata = malloc(2048);
strcpy(query,INSERT INTO patient VALUES (NULL,);
str_length = strlen(query);
end = query + str_length + 1;
printf(\nFirst Name ==);
fgets( value, 26, stdin);
mysql_real_escape_string(clinical_db,encdata,value,strlen(value)); === 
Segmenetation Fault
/*end += mysql_real_escape_string(clinical_db,end,value,strlen(value));*/
*end++ = ',';
printf(\nLast Name ==);
fgets( value, 26, stdin);
end += mysql_real_escape_string(clinical_db, end,value,strlen(value) - 1);
*end++ = ',';
printf(\nMedical Record Number==);
fgets(value,12,stdin);
end += mysql_real_escape_string(clinical_db, end,value,strlen(value) - 1);
end++;
strcpy(end,));

printf(\nResulting Query %s, query);



return 0;
} /* End of main() */


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



segfault in mysql_real_escape_string

2001-09-10 Thread Guillaume Morin

Hi folks,

I've the main developer of nss-mysql. I've found out a very strange
problem.

On a Debian potato, mysql 3.23.38 and glibc 2.1.3

This bit of code segfault on the last line. The string useris correct
(printed correctly in log).


/* we escape the user string */
secure_user = malloc(strlen(user) * 2 + 1);
if ( secure_user == NULL ) {
_nss_mysql_log(LOG_ERR,initgroups: not enough memory to escape the 
user string);
*errnop = EAGAIN;
return NSS_STATUS_TRYAGAIN;
}

mysql_real_escape_string(mysql_auth,secure_user,user,strlen(user));

This part is taken from the initgroups function and segfaults everytime
when called from Apache.  I've noticed that upgrading libc to 2.2.4
fixes the problem. I guess this is a problem in the client lib.

Any hints will be welcome.

-- 
Guillaume Morin [EMAIL PROTECTED]

Justice is lost, Justice is raped, Justice is done. (Metallica)

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php