This is the official MySQL UDF Repository bug tracker. Please use it with care.
- Before submitting a new bug report, please make sure the bug is not already reported.
- Include the given error code, trace and any other debugging information supplied.
- Please leave your e-mail address, so we can get back to you if it is unclear how to reproduce the bug.
Thank you!
FS#11 - Signal 11 when using sys_eval more than once
Attached to Project:
lib_mysqludf_sys
Opened by 'bpoquillon-prosodiemail' - Monday, 26 January 2009, 22:37 GMT+2
Opened by 'bpoquillon-prosodiemail' - Monday, 26 January 2009, 22:37 GMT+2
|
DetailsWhen using sys_eval, a SIG 11 is raised:
select sys_eval('ls -l existing_file'); select sys_eval('ls -l non_existing_file'); The problem is that the malloc or realloc length is too short because result[outlen]=0 needs a length of outlen+1 There are also not tested returns of functions. And if result is null, the test !(*result) produces a core under Linux According to me, a better implementation would be : char* sys_eval( UDF_INIT *initid , UDF_ARGS *args , char* result , unsigned long* length , char *is_null , char *error ){ FILE *pipe; char line[1024]; unsigned long outlen, linelen; pipe = popen(args->args[0], "r"); if (pipe == NULL) { *is_null = 1; return NULL; } outlen = 0; result = NULL; while (fgets(line, sizeof(line), pipe) != NULL) { linelen = strlen(line); if (linelen > 0) { if (outlen == 0) result = malloc(linelen + 1); else result = realloc(result, outlen + linelen + 1); if (result == NULL) break; strncpy(result + outlen, line, linelen); outlen = outlen + linelen; } } pclose(pipe); if (result == NULL || !(*result)) { *is_null = 1; } else { result[outlen] = 0x00; *length = strlen(result); } return result; } Hope it helps. Bernard |
This task depends upon
Comment by
'edaly-nextwavemedia'
- Wednesday, 13 May 2009, 02:08 GMT+2
This code worked for me. As described above, the original crashed for me under mysql (Ver 14.12 Distrib 5.0.67, for redhat-linux-gnu (i686) using readline 5.1) when calling programs with no or multiline output.