Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys_eval() not freeing memory and can cause crashes #35

Open
montywi opened this issue Jan 13, 2023 · 0 comments
Open

sys_eval() not freeing memory and can cause crashes #35

montywi opened this issue Jan 13, 2023 · 0 comments

Comments

@montywi
Copy link

montywi commented Jan 13, 2023

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;
    
  •       initid->ptr= malloc(65535);
      return 0;
    
    } else {
    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;
}

neoclust added a commit to neoclust/lib_mysqludf_sys that referenced this issue Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant