Description
Here is a patch to the above issues with sys_evail()
I found the issues while checking the function with valgrind.
*** org/lib_mysqludf_sys-master/lib_mysqludf_sys.c Thu Feb 21 02:39:07 2013
--- ./lib_mysqludf_sys.c Fri Jan 13 15:31:45 2023
*** 54,60 ****
#define LIBVERSION "lib_mysqludf_sys version 0.0.3"
! #ifdef WIN
#define SETENV(name,value) SetEnvironmentVariable(name,value);
#else
#define SETENV(name,value) setenv(name,value,1);
--- 54,60 ----
#define LIBVERSION "lib_mysqludf_sys version 0.0.3"
! #ifdef WIN64
#define SETENV(name,value) SetEnvironmentVariable(name,value);
#else
#define SETENV(name,value) setenv(name,value,1);
*** 373,378 ****
--- 373,380 ----
unsigned int i=0;
if(args->arg_count == 1
&& args->arg_type[i]==STRING_RESULT){
-
initid->max_length= 65535;
-
} else {
initid->ptr= malloc(65535); return 0;
strcpy(
*** 385,390 ****
--- 387,394 ----
void sys_eval_deinit(
UDF_INIT *initid
){
- free(initid->ptr);
- initid->ptr= 0;
}
char* sys_eval(
UDF_INIT *initid
*** 395,424 ****
, char *error
){
FILE *pipe;
! char line[1024];
! unsigned long outlen, linelen;
! result = malloc(1);
! outlen = 0;
pipe = popen(args->args[0], "r");
while (fgets(line, sizeof(line), pipe) != NULL) {
! linelen = strlen(line);
! result = realloc(result, outlen + linelen);
! strncpy(result + outlen, line, linelen);
! outlen = outlen + linelen;
}
pclose(pipe);
! if (!(*result) || result == NULL) {
! *is_null = 1;
! } else {
! result[outlen] = 0x00;
! *length = strlen(result);
! }
!
return result;
}
--- 399,424 ----
, char *error
){
FILE *pipe;
! char line[1024], *out= result;
! unsigned long outlen;
! if (result == 0) /* Allocation failed */
! {
! *is_null = 1;
! return 0;
! }
-
outlen = 0;
pipe = popen(args->args[0], "r");while (fgets(line, sizeof(line), pipe) != NULL) {
! out= strnmov(out, line, initid->max_length - outlen);
! outlen = out - result;
}pclose(pipe);
! *length= outlen;
return result;
}