diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-31 03:38:39 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-31 03:38:39 +0100 |
commit | b75a8f795fc1ea7a4604c09d65d91a75ddbbbbea (patch) | |
tree | 0f6beb89b3e5000e4d41e231762792b8e6247c7b /src | |
parent | bc2da7891acc79a77de00e89f2fe39660dee228e (diff) | |
download | abrt-b75a8f795fc1ea7a4604c09d65d91a75ddbbbbea.tar.gz abrt-b75a8f795fc1ea7a4604c09d65d91a75ddbbbbea.tar.xz abrt-b75a8f795fc1ea7a4604c09d65d91a75ddbbbbea.zip |
src/CLI/*: fix an unterminated argv + simplifications
The fix is:
- const char *args[6];
- args[0] = editor;
- args[1] = path;
+ char *args[3];
+ args[0] = (char*)editor;
+ args[1] = (char*)path;
+ args[2] = NULL;
run_command(args);
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/CLI/CLI.cpp | 118 | ||||
-rw-r--r-- | src/CLI/dbus.cpp | 123 | ||||
-rw-r--r-- | src/CLI/report.cpp | 50 | ||||
-rw-r--r-- | src/CLI/run-command.cpp | 62 | ||||
-rw-r--r-- | src/CLI/run-command.h | 2 | ||||
-rw-r--r-- | src/Hooks/abrt-pyhook-helper.cpp | 12 |
6 files changed, 174 insertions, 193 deletions
diff --git a/src/CLI/CLI.cpp b/src/CLI/CLI.cpp index 18e99dcf..edc8df00 100644 --- a/src/CLI/CLI.cpp +++ b/src/CLI/CLI.cpp @@ -24,16 +24,16 @@ #include "report.h" #include "dbus.h" #if HAVE_CONFIG_H -#include <config.h> +# include <config.h> #endif #if HAVE_LOCALE_H -#include <locale.h> +# include <locale.h> #endif #if ENABLE_NLS -#include <libintl.h> -#define _(S) gettext(S) +# include <libintl.h> +# define _(S) gettext(S) #else -#define _(S) (S) +# define _(S) (S) #endif /* Program options */ @@ -56,31 +56,31 @@ static void print_crash_infos(vector_crash_infos_t& pCrashInfos, int pMode) map_crash_info_t& info = pCrashInfos[ii]; if (pMode == OPT_GET_LIST_FULL || info.find(CD_REPORTED)->second[CD_CONTENT] != "1") { - const char *timestr = info[CD_TIME][CD_CONTENT].c_str(); - long time = strtol(timestr, 0, 10); - if (time == 0) - error_msg_and_die("Error while converting time string."); - - char timeloc[256]; - int success = strftime(timeloc, 128, "%c", localtime(&time)); - if (!success) - error_msg_and_die("Error while converting time to string."); - - printf(_("%u.\n" - "\tUID : %s\n" - "\tUUID : %s\n" - "\tPackage : %s\n" - "\tExecutable : %s\n" - "\tCrash Time : %s\n" - "\tCrash Count: %s\n"), - ii, - info[CD_UID][CD_CONTENT].c_str(), - info[CD_UUID][CD_CONTENT].c_str(), - info[CD_PACKAGE][CD_CONTENT].c_str(), - info[CD_EXECUTABLE][CD_CONTENT].c_str(), - timeloc, - info[CD_COUNT][CD_CONTENT].c_str() - ); + const char *timestr = info[CD_TIME][CD_CONTENT].c_str(); + long time = strtol(timestr, NULL, 10); + if (time == 0) + error_msg_and_die("Error while converting time string."); + + char timeloc[256]; + int success = strftime(timeloc, 128, "%c", localtime(&time)); + if (!success) + error_msg_and_die("Error while converting time to string."); + + printf(_("%u.\n" + "\tUID : %s\n" + "\tUUID : %s\n" + "\tPackage : %s\n" + "\tExecutable : %s\n" + "\tCrash Time : %s\n" + "\tCrash Count: %s\n"), + ii, + info[CD_UID][CD_CONTENT].c_str(), + info[CD_UUID][CD_CONTENT].c_str(), + info[CD_PACKAGE][CD_CONTENT].c_str(), + info[CD_EXECUTABLE][CD_CONTENT].c_str(), + timeloc, + info[CD_COUNT][CD_CONTENT].c_str() + ); } } } @@ -111,21 +111,21 @@ static char *progname(char *argv0) /* Prints abrt-cli version and some help text. */ static void usage(char *argv0) { - char *name = progname(argv0); - printf("%s " VERSION "\n\n", name); - - /* Message has embedded tabs. */ - printf(_("Usage: %s [OPTION]\n\n" - "Startup:\n" - " -V, --version display the version of %s and exit\n" - " -?, --help print this help\n\n" - "Actions:\n" - " --get-list print list of crashes which are not reported yet\n" - " --get-list-full print list of all crashes\n" - " --report UUID create and send a report\n" - " --report-always UUID create and send a report without asking\n" - " --delete UUID remove crash\n"), - name, name); + char *name = progname(argv0); + printf("%s " VERSION "\n\n", name); + + /* Message has embedded tabs. */ + printf(_("Usage: %s [OPTION]\n\n" + "Startup:\n" + " -V, --version display the version of %s and exit\n" + " -?, --help print this help\n\n" + "Actions:\n" + " --get-list print list of crashes which are not reported yet\n" + " --get-list-full print list of all crashes\n" + " --report UUID create and send a report\n" + " --report-always UUID create and send a report without asking\n" + " --delete UUID remove crash\n"), + name, name); } int main(int argc, char** argv) @@ -154,21 +154,21 @@ int main(int argc, char** argv) case OPT_GET_LIST_FULL: if (op == -1) break; - error_msg(_("You must specify exactly one operation.")); + error_msg(_("You must specify exactly one operation.")); return 1; - case -1: /* end of options */ - if (op != -1) /* if some operation was specified... */ - break; + case -1: /* end of options */ + if (op != -1) /* if some operation was specified... */ + break; /* fall through */ default: - case '?': + case '?': case OPT_HELP: - usage(argv[0]); - return 1; + usage(argv[0]); + return 1; case 'V': - case OPT_VERSION: - printf("%s " VERSION "\n", progname(argv[0])); - return 0; + case OPT_VERSION: + printf("%s " VERSION "\n", progname(argv[0])); + return 0; } if (c == -1) break; @@ -195,11 +195,11 @@ int main(int argc, char** argv) break; } case OPT_REPORT: - report(uuid, false); - break; + report(uuid, false); + break; case OPT_REPORT_ALWAYS: - report(uuid, true); - break; + report(uuid, true); + break; case OPT_DELETE: { call_DeleteDebugDump(uuid); diff --git a/src/CLI/dbus.cpp b/src/CLI/dbus.cpp index 98fe9ac1..f59633ec 100644 --- a/src/CLI/dbus.cpp +++ b/src/CLI/dbus.cpp @@ -37,71 +37,70 @@ static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) { dbus_uint32_t serial; if (TRUE != dbus_connection_send(s_dbus_conn, msg, &serial)) - error_msg_and_die("Error sending DBus message"); + error_msg_and_die("Error sending DBus message"); dbus_message_unref(msg); - + while (true) { - DBusMessage *received = dbus_connection_pop_message(s_dbus_conn); - if (!received) - { - if (FALSE == dbus_connection_read_write(s_dbus_conn, -1)) - error_msg_and_die("Connection to ABRT daemon closed."); - - continue; - } - - /* Debugging*/ - /* - const char *sender = dbus_message_get_sender(received); - if (sender) - printf("sender: %s\n", sender); - const char *path = dbus_message_get_path(received); - if (path) - printf("path: %s\n", path); - const char *member = dbus_message_get_member(received); - if (member) - printf("member: %s\n", member); - const char *interface = dbus_message_get_interface(received); - if (interface) - printf("interface: %s\n", interface); - const char *destination = dbus_message_get_destination(received); - if (destination) - printf("destination: %s\n", destination); - */ - - DBusError err; - dbus_error_init(&err); - - if (dbus_message_is_signal(received, CC_DBUS_IFACE, "Update")) - { - const char *update_msg; - if (!dbus_message_get_args(received, &err, - DBUS_TYPE_STRING, &update_msg, - DBUS_TYPE_INVALID)) - { - error_msg_and_die("dbus Update message: arguments mismatch"); - } - printf(">> %s\n", update_msg); - } - else if (dbus_message_is_signal(received, CC_DBUS_IFACE, "Warning")) - { - const char *warning_msg; - if (!dbus_message_get_args(received, &err, - DBUS_TYPE_STRING, &warning_msg, - DBUS_TYPE_INVALID)) - { - error_msg_and_die("dbus Update message: arguments mismatch"); - } - printf(">! %s\n", warning_msg); - } - else if (dbus_message_get_type(received) == DBUS_MESSAGE_TYPE_METHOD_RETURN && - dbus_message_get_reply_serial(received) == serial) - { - return received; - } - - dbus_message_unref(received); + DBusMessage *received = dbus_connection_pop_message(s_dbus_conn); + if (!received) + { + if (FALSE == dbus_connection_read_write(s_dbus_conn, -1)) + error_msg_and_die("DBus connection closed"); + continue; + } + + /* Debugging */ + /* + const char *sender = dbus_message_get_sender(received); + if (sender) + printf("sender: %s\n", sender); + const char *path = dbus_message_get_path(received); + if (path) + printf("path: %s\n", path); + const char *member = dbus_message_get_member(received); + if (member) + printf("member: %s\n", member); + const char *interface = dbus_message_get_interface(received); + if (interface) + printf("interface: %s\n", interface); + const char *destination = dbus_message_get_destination(received); + if (destination) + printf("destination: %s\n", destination); + */ + + DBusError err; + dbus_error_init(&err); + + if (dbus_message_is_signal(received, CC_DBUS_IFACE, "Update")) + { + const char *update_msg; + if (!dbus_message_get_args(received, &err, + DBUS_TYPE_STRING, &update_msg, + DBUS_TYPE_INVALID)) + { + error_msg_and_die("dbus Update message: arguments mismatch"); + } + printf(">> %s\n", update_msg); + } + else if (dbus_message_is_signal(received, CC_DBUS_IFACE, "Warning")) + { + const char *warning_msg; + if (!dbus_message_get_args(received, &err, + DBUS_TYPE_STRING, &warning_msg, + DBUS_TYPE_INVALID)) + { + error_msg_and_die("dbus Update message: arguments mismatch"); + } + printf(">! %s\n", warning_msg); + } + else if (dbus_message_get_type(received) == DBUS_MESSAGE_TYPE_METHOD_RETURN && + dbus_message_get_reply_serial(received) == serial) + { + return received; + } + + dbus_message_unref(received); } } diff --git a/src/CLI/report.cpp b/src/CLI/report.cpp index b9a13914..ac80e481 100644 --- a/src/CLI/report.cpp +++ b/src/CLI/report.cpp @@ -21,13 +21,13 @@ #include "abrtlib.h" #include "DebugDump.h" // FILENAME_* defines #if HAVE_CONFIG_H -#include <config.h> +# include <config.h> #endif #if ENABLE_NLS -#include <libintl.h> -#define _(S) gettext(S) +# include <libintl.h> +# define _(S) gettext(S) #else -#define _(S) (S) +# define _(S) (S) #endif /* Field separator for the crash report file that is edited by user. */ @@ -45,7 +45,7 @@ char *trim(char *str) // Remove leading spaces. char *ibuf; for (ibuf = str; *ibuf && isspace(*ibuf); ++ibuf) - ; + continue; if (str != ibuf) memmove(str, ibuf, ibuf - str); @@ -79,7 +79,7 @@ static char *escape(const char *str) { if (*ptr == '#') ++count; - if (*ptr == '\\' && *(ptr + 1) == '#') + if (*ptr == '\\' && ptr[1] == '#') ++count; } @@ -89,9 +89,7 @@ static char *escape(const char *str) // Copy the input string to the resultant string, and escape all // occurences of \# and #. - char *result = (char*)malloc(strlen(str) + 1 + count); - if (!result) - error_msg_and_die("Memory error while escaping a field."); + char *result = (char*)xmalloc(strlen(str) + 1 + count); const char *src = str; char *dest = result; @@ -136,10 +134,9 @@ static void remove_comments_and_unescape(char *str) ++src; continue; } - else if (*src == '\\' && - (*(src + 1) == '#' || - (*(src + 1) == '\\' && *(src + 2) == '#'))) - { + if (*src == '\\' + && (src[1] == '#' || (src[1] == '\\' && src[2] == '#')) + ) { ++src; // Unescape escaped char. } } @@ -189,7 +186,7 @@ static void write_crash_report_field(FILE *fp, const map_crash_report_t &report, * If the report is successfully stored to the file, a zero value is returned. * On failure, nonzero value is returned. */ -static int write_crash_report(const map_crash_report_t &report, FILE *fp) +static void write_crash_report(const map_crash_report_t &report, FILE *fp) { fprintf(fp, "# Please check this report. Lines starting with '#' will be ignored.\n" "# Lines starting with '%%----' separate fields, please do not delete them.\n\n"); @@ -210,8 +207,6 @@ static int write_crash_report(const map_crash_report_t &report, FILE *fp) write_crash_report_field(fp, report, FILENAME_PACKAGE, _("# Package")); write_crash_report_field(fp, report, FILENAME_REASON, _("# Reason of crash")); write_crash_report_field(fp, report, FILENAME_RELEASE, _("# Release string of the operating system")); - - return 0; } /* @@ -303,7 +298,7 @@ static int read_crash_report(map_crash_report_t &report, const char *text) } /* Runs external editor. */ -int launch_editor(const char *path) +static int launch_editor(const char *path) { const char *editor, *terminal; @@ -323,9 +318,10 @@ int launch_editor(const char *path) if (!editor) editor = "vi"; - const char *args[6]; - args[0] = editor; - args[1] = path; + char *args[3]; + args[0] = (char*)editor; + args[1] = (char*)path; + args[2] = NULL; run_command(args); return 0; @@ -349,14 +345,14 @@ int report(const char *uuid, bool always) int fd = mkstemp(filename); if (fd == -1) { - error_msg("could not generate temporary file name"); + error_msg("can't generate temporary file name"); return 1; } FILE *fp = fdopen(fd, "w"); if (!fp) { - error_msg("could not open '%s' to save the crash report", filename); + error_msg("can't open '%s' to save the crash report", filename); return 1; } @@ -364,7 +360,7 @@ int report(const char *uuid, bool always) if (fclose(fp)) { - error_msg("could not close '%s'", filename); + error_msg("can't close '%s'", filename); return 2; } @@ -375,7 +371,7 @@ int report(const char *uuid, bool always) fp = fopen(filename, "r"); if (!fp) { - error_msg("could not open '%s' to read the crash report", filename); + error_msg("can't open '%s' to read the crash report", filename); return 1; } @@ -383,10 +379,10 @@ int report(const char *uuid, bool always) long size = ftell(fp); fseek(fp, 0, SEEK_SET); - char *text = (char*)malloc(size + 1); + char *text = (char*)xmalloc(size + 1); if (fread(text, 1, size, fp) != size) { - error_msg("could not read '%s'", filename); + error_msg("can't read '%s'", filename); return 1; } text[size] = '\0'; @@ -403,7 +399,7 @@ int report(const char *uuid, bool always) free(text); if (unlink(filename) != 0) // Delete the tempfile. - error_msg("could not unlink %s: %s", filename, strerror(errno)); + perror_msg("can't unlink %s", filename); // Report only if the user is sure. printf(_("Do you want to send the report? [y/N]: ")); diff --git a/src/CLI/run-command.cpp b/src/CLI/run-command.cpp index 80184cfa..8f9d63ec 100644 --- a/src/CLI/run-command.cpp +++ b/src/CLI/run-command.cpp @@ -23,65 +23,51 @@ http://git.kernel.org/?p=git/git.git;a=blob;f=run-command.c;hb=HEAD */ -struct child_process +static pid_t start_command(char **argv) { - const char **argv; - pid_t pid; -}; - -static int start_command(struct child_process *cmd) -{ - cmd->pid = fork(); - if (cmd->pid == 0) + pid_t pid = vfork(); + if (pid < 0) + { + perror_msg_and_die("Can't fork"); + } + if (pid == 0) { // new process - execvp(cmd->argv[0], (char *const*)cmd->argv); + execvp(argv[0], argv); exit(127); } - if (cmd->pid < 0) - { - error_msg_and_die("Unable to fork for %s: %s", cmd->argv[0], strerror(errno)); - return -1; - } - return 0; + return pid; } -static int finish_command(struct child_process *cmd) +static int finish_command(pid_t pid, char **argv) { pid_t waiting; - int status, code = -1; - while ((waiting = waitpid(cmd->pid, &status, 0)) < 0 && errno == EINTR) - ; /* nothing */ - + int status; + while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR) + continue; if (waiting < 0) - error_msg_and_die("waitpid for %s failed: %s", cmd->argv[0], strerror(errno)); - else if (waiting != cmd->pid) - error_msg_and_die("waitpid is confused (%s)", cmd->argv[0]); - else if (WIFSIGNALED(status)) + perror_msg_and_die("waitpid"); + + int code = -1; + if (WIFSIGNALED(status)) { code = WTERMSIG(status); - error_msg("%s died of signal %d", cmd->argv[0], code); + error_msg("'%s' killed by signal %d", argv[0], code); + code += 128; /* shells use this convention for deaths by signal */ } - else if (WIFEXITED(status)) + else /* if (WIFEXITED(status)) */ { code = WEXITSTATUS(status); if (code == 127) { - code = -1; - error_msg_and_die("cannot run %s: %s", cmd->argv[0], strerror(ENOENT)); + error_msg_and_die("Can't run '%s'", argv[0]); } } - else - error_msg_and_die("waitpid is confused (%s)", cmd->argv[0]); return code; } -int run_command(const char **argv) +int run_command(char **argv) { - struct child_process cmd; - cmd.argv = argv; - int code = start_command(&cmd); - if (code) - return code; - return finish_command(&cmd); + pid_t pid = start_command(argv); + return finish_command(pid, argv); } diff --git a/src/CLI/run-command.h b/src/CLI/run-command.h index 45a85af5..71391579 100644 --- a/src/CLI/run-command.h +++ b/src/CLI/run-command.h @@ -18,6 +18,6 @@ #ifndef ABRT_CLI_RUN_COMMAND_H #define ABRT_CLI_RUN_COMMAND_H -int run_command(const char **argv); +int run_command(char **argv); #endif diff --git a/src/Hooks/abrt-pyhook-helper.cpp b/src/Hooks/abrt-pyhook-helper.cpp index f8bda846..7a4ffc8b 100644 --- a/src/Hooks/abrt-pyhook-helper.cpp +++ b/src/Hooks/abrt-pyhook-helper.cpp @@ -1,5 +1,5 @@ /* - python-hook-writer.cpp - writes data to the /var/cache/abrt directory + python-hook-writer.cpp - writes data to the /var/cache/abrt directory with SUID bit Copyright (C) 2009 RedHat inc. @@ -26,7 +26,7 @@ #if HAVE_CONFIG_H #include <config.h> #endif - + const char *argp_program_version = "abrt-pyhook-helper " VERSION; const char *argp_program_bug_address = "<crash-catcher@lists.fedorahosted.org>"; @@ -56,7 +56,7 @@ parse_opt (int key, char *arg, struct argp_state *state) /* Get the input argument from argp_parse, which we know is a pointer to our arguments structure. */ struct arguments *arguments = (struct arguments*)state->input; - + switch (key) { case 'p': arguments->pid = arg; break; @@ -77,7 +77,7 @@ parse_opt (int key, char *arg, struct argp_state *state) exit(1); } break; - + default: return ARGP_ERR_UNKNOWN; } @@ -113,7 +113,7 @@ int main(int argc, char** argv) fprintf(stderr, "Backtrace size limit exceeded. Trimming to 1 MB.\n"); break; } - + bt = (char*)realloc(bt, capacity); if (!bt) { @@ -126,7 +126,7 @@ int main(int argc, char** argv) // Create directory with the debug dump. char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/pyhook-%ld-%s", DEBUG_DUMPS_DIR, + snprintf(path, sizeof(path), "%s/pyhook-%ld-%s", DEBUG_DUMPS_DIR, (long)time(NULL), arguments.pid); CDebugDump dd; |