Bug #27290 handle_connections_sockets Error inside UDF
Submitted: 20 Mar 2007 13:57 Modified: 30 May 2007 8:09
Reporter: Pablo Calder?n Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S1 (Critical)
Version:5.0.27 OS:Any (susse 10)
Assigned to: CPU Architecture:Any

[20 Mar 2007 13:57] Pablo Calder?n
Description:
mysql server restarted regularly And show this errors codes:

0x817c123 handle_connections_sockets + 691
0x8164a91 _ZN12Field_string5resetEv + 49
0x80ed987 _ZN15Item_cache_real7val_strEP6String + 7
0x82a2838 _Z45sp_cache_routines_and_add_tables_for_triggersP3THDP6st_lexP13st_table_list + 344
0x82a6e06 srv_set_io_thread_op_info + 70
0x829e65e _ZN11sp_pcontext11find_cursorEP13st_lex_stringPjc + 1006
0x829e919 _ZN9sp_cursor5fetchEP3THDP4ListI11sp_variableE + 185
0x829eabe _ZN11sp_rcontext12find_handlerEjN11MYSQL_ERROR18enum_warning_levelE + 142
0x82a1b65 _Z17db_create_routineP3THDiP7sp_head + 565
0x82a3928 _Z26sql_create_definition_filePK13st_lex_stringS1_S1_PcP11File_optionj + 888
0x8117fdb _ZNK13Item_func_log9func_nameEv + 11
0x811b775 _ZN18Item_func_get_lockD0Ev + 5
0x80ed948 _ZN9Item_uint5printEP6String + 40
0x81bcad8 _Z22close_temporary_tablesP3THD + 1272
0x81ecdaf _Z22mysql_sql_stmt_prepareP3THD + 351
0x81989f2 _Z21mysql_execute_commandP3THD + 38978
0x829e7b1 _ZN11sp_rcontext13get_case_exprEi + 1
0x829e919 _ZN9sp_cursor5fetchEP3THDP4ListI11sp_variableE + 185
0x82a2453 _Z36sp_cache_routines_and_add_tables_auxP3THDP6st_lexP19Sroutine_hash_entrybPb + 659
0x82a1b65 _Z17db_create_routineP3THDiP7sp_head + 565
0x82a3112 _Z17sql_parse_preparePK13st_lex_stringP11st_mem_rootb + 386
0x82acb46 innobase_start_or_create_for_mysql + 4326
0x81f6c4e _Z18find_uniq_filenamePc + 190
0x8197d1e _Z21mysql_execute_commandP3THD + 35694
0x829e7b1 _ZN11sp_rcontext13get_case_exprEi + 1
0x829e919 _ZN9sp_cursor5fetchEP3THDP4ListI11sp_variableE + 185
0x82a2453 _Z36sp_cache_routines_and_add_tables_auxP3THDP6st_lexP19Sroutine_hash_entrybPb + 659
0x82a1b65 _Z17db_create_routineP3THDiP7sp_head + 565
0x82a3112 _Z17sql_parse_preparePK13st_lex_stringP11st_mem_rootb + 386
0x82acb46 innobase_start_or_create_for_mysql + 4326
0x81f6c4e _Z18find_uniq_filenamePc + 190
0x8197d1e _Z21mysql_execute_commandP3THD + 35694
0x829e7b1 _ZN11sp_rcontext13get_case_exprEi + 1
0x829e919 _ZN9sp_cursor5fetchEP3THDP4ListI11sp_variableE + 185
0x82a2453 _Z36sp_cache_routines_and_add_tables_auxP3THDP6st_lexP19Sroutine_hash_entrybPb + 659
0x82a1b65 _Z17db_create_routineP3THDiP7sp_head + 565
0x82a3112 _Z17sql_parse_preparePK13st_lex_stringP11st_mem_rootb + 386
0x82acb46 innobase_start_or_create_for_mysql + 4326
0x81e9322 _ZN6I_ListI14delayed_insertE6appendEPS0_ + 2
0x81ed11e _Z20mysql_sql_stmt_closeP3THD + 62
0x81989f2 _Z21mysql_execute_commandP3THD + 38978
0x829e7b1 _ZN11sp_rcontext13get_case_exprEi + 1
0x829e919 _ZN9sp_cursor5fetchEP3THDP4ListI11sp_variableE + 185
0x82a2453 _Z36sp_cache_routines_and_add_tables_auxP3THDP6st_lexP19Sroutine_hash_entrybPb + 659
0x82a1b65 _Z17db_create_routineP3THDiP7sp_head + 565
0x82a3112 _Z17sql_parse_preparePK13st_lex_stringP11st_mem_rootb + 386
0x82acb46 innobase_start_or_create_for_mysql + 4326
0x81e9322 _ZN6I_ListI14delayed_insertE6appendEPS0_ + 2
0x81ed11e _Z20mysql_sql_stmt_closeP3THD + 62
0x81989f2 _Z21mysql_execute_commandP3THD + 38978
0x819c6b1 _Z10MYSQLparsePv + 641
0x819cce6 _Z10MYSQLparsePv + 2230
0x819ed0c _Z10MYSQLparsePv + 10460
0xb7ee234b _end + -1348520333
0xb7d2165e _end + -1350358650

How to repeat:
create Udf and testing

Suggested fix:
UDF CODE:

#ifdef STANDARD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#else
#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>		// To get strmov()
#endif
#include <mysql.h>
#include <ctype.h>
#include <time.h>
#include <map.h>

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#ifdef HAVE_DLOPEN
extern "C" 
{
	my_bool getDireccion2_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
	void getDireccion2_deinit(UDF_INIT *initid);
	char *getDireccion2(UDF_INIT *initid, UDF_ARGS *args, char *result,unsigned long *length, char *is_null, char *error);
}

my_bool getDireccion2_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{

	if (args->arg_count != 4) 
	{
		strcpy(message,"getDirecccion takes 4 parameters.");
		return 1;
	}
	if(args->arg_type[0] !=REAL_RESULT)
	{
		strcpy(message,"Wrong parameter (1).");
		return 1;
	}
	if(args->arg_type[1]!=REAL_RESULT)
	{
		strcpy(message,"Wrong parameter (2).");
		return 1;
	}
	if(args->arg_type[2]!= STRING_RESULT)
	{
		strcpy(message,"Wrong parameter (3).");
		return 1;
	}
	if(args->arg_type[3]!= INT_RESULT)
	{
		strcpy(message,"Wrong parameter (4).");
		return 1;
	}
	

	return 0;
}

void getDireccion2_deinit(UDF_INIT *initid)
{
	if(initid->ptr)
		free(initid->ptr);
}

char *getDireccion2(UDF_INIT *initid, UDF_ARGS *args, char *result,unsigned long *res_length, char *null_value, char *error)
{
	int sockfd, portno, n;
	struct sockaddr_in serv_addr;
	struct hostent *server;

	char buffer[256];
	portno =  *((int*) args->args[3]);
	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (sockfd < 0)
	{
		(*error)=1;
		(*null_value)=1;
		return NULL;	
	}
	server = gethostbyname(args->args[2]);
	if (server == NULL) 
	{
		(*error)=1;
		(*null_value)=1;
		close(sockfd);
		return NULL;
	}
	bzero((char *) &serv_addr, sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	bcopy((char *)server->h_addr,(char *)&serv_addr.sin_addr.s_addr,server->h_length);
	serv_addr.sin_port = htons(portno);
	if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0)
	{
		(*error)=1;
		(*null_value)=1;
		close(sockfd);
		return NULL;
	}
	bzero(buffer,256);
//	char sp[100];
	double x,y;
	x = *((double*) args->args[0]);
	y = *((double*) args->args[1]);
	sprintf(buffer, "%.10f %.10f",x,y);
	n = write(sockfd,buffer,strlen(buffer));
	if (n < 0)
	{
		(*error)=1;
		(*null_value)=1;
		close(sockfd);
		return NULL;	
	}
	
	bzero(result,255);
	(*res_length)=recv(sockfd,result,255,0);
	if((*res_length)<0)
	{
		(*error)=1;
		(*null_value)=1;
		close(sockfd);
		return NULL;
	}
	close(sockfd);
	return result;
}
#endif
[21 Mar 2007 9:12] Valeriy Kravchuk
Thank you for a problem report. Please, try to repeat with a newer version, 5.0.37, and inform about the results.
[21 Apr 2007 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[30 Apr 2007 8:09] Valeriy Kravchuk
Feedback is still needed.
[30 May 2007 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".