diff options
-rw-r--r-- | src/Hooks/abrt-pyhook-helper.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/Hooks/abrt-pyhook-helper.cpp b/src/Hooks/abrt-pyhook-helper.cpp index 4ac6ada6..7ad605f3 100644 --- a/src/Hooks/abrt-pyhook-helper.cpp +++ b/src/Hooks/abrt-pyhook-helper.cpp @@ -92,44 +92,48 @@ int main(int argc, char** argv) struct arguments arguments; argp_parse (&argp, argc, argv, 0, 0, &arguments); - char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/pyhook-%ld-%s", DEBUG_DUMPS_DIR, - (long)time(NULL), arguments.pid); - - CDebugDump dd; - dd.Create(path, geteuid()); - dd.SaveText(FILENAME_ANALYZER, "Python"); - if (arguments.executable) - dd.SaveText(FILENAME_EXECUTABLE, arguments.executable); - if (arguments.cmdline) - dd.SaveText("cmdline", arguments.cmdline); - if (arguments.uuid) - dd.SaveText("uuid", arguments.uuid); - if (arguments.loginuid) - dd.SaveText("uid", arguments.loginuid); - // Read the backtrace from stdin. int c; int capacity = 1024; char *bt = (char*)malloc(capacity); + if (!bt) + { + printf("Error while allocating memory for backtrace.\n"); + return 1; + } char *btptr = bt; while ((c = getchar()) != EOF) { - if (c >= 0 && c <= 255) - *btptr++ = (char)c; + *btptr++ = (char)c; if (btptr - bt >= capacity - 1) { capacity *= 2; bt = (char*)realloc(bt, capacity); if (!bt) { - printf("Error while allocating memory for backtrace."); + printf("Error while allocating memory for backtrace.\n"); return 1; } } } *btptr = '\0'; + // Create directory with the debug dump. + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/pyhook-%ld-%s", DEBUG_DUMPS_DIR, + (long)time(NULL), arguments.pid); + + CDebugDump dd; + dd.Create(path, geteuid()); + dd.SaveText(FILENAME_ANALYZER, "Python"); + if (arguments.executable) + dd.SaveText(FILENAME_EXECUTABLE, arguments.executable); + if (arguments.cmdline) + dd.SaveText("cmdline", arguments.cmdline); + if (arguments.uuid) + dd.SaveText("uuid", arguments.uuid); + if (arguments.loginuid) + dd.SaveText("uid", arguments.loginuid); dd.SaveText("backtrace", bt); free(bt); dd.Close(); |