diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-22 12:33:52 +0200 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-10-22 12:33:52 +0200 |
| commit | b74cfbee13b9d2723dd48fe3e2a049fc55129699 (patch) | |
| tree | 99c5418633e41a7b8c88f35dbe47521c0c226b76 /src/daemon/abrt-action-save-package-data.cpp | |
| parent | 6bfdfb30c1c9ad281999400287bebb5583f5b9cc (diff) | |
| download | abrt-b74cfbee13b9d2723dd48fe3e2a049fc55129699.tar.gz abrt-b74cfbee13b9d2723dd48fe3e2a049fc55129699.tar.xz abrt-b74cfbee13b9d2723dd48fe3e2a049fc55129699.zip | |
restore correct handling of argv[1] of scripts
Bad boy Karel "improved" it incorrectly, and did not revert it.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/daemon/abrt-action-save-package-data.cpp')
| -rw-r--r-- | src/daemon/abrt-action-save-package-data.cpp | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/src/daemon/abrt-action-save-package-data.cpp b/src/daemon/abrt-action-save-package-data.cpp index 4d397071..9c1c4c0b 100644 --- a/src/daemon/abrt-action-save-package-data.cpp +++ b/src/daemon/abrt-action-save-package-data.cpp @@ -27,12 +27,15 @@ /** * Returns the first full path argument in the command line or NULL. - * Skips options are in form "-XXX". - * Caller must delete the returned string using free(). + * Skips options (params of the form "-XXX"). + * Returns malloc'ed string. + * NB: the cmdline is delimited by (single, not multiple) spaces, not tabs! + * "abc def\t123" means there are two params: "abc", "def\t123". + * "abc def" means there are three params: "abc", "", "def". */ static char *get_argv1_if_full_path(const char* cmdline) { - const char *argv1 = strpbrk(cmdline, " \t"); + const char *argv1 = strchr(cmdline, ' '); while (argv1 != NULL) { /* we found space in cmdline, so it might contain @@ -40,28 +43,22 @@ static char *get_argv1_if_full_path(const char* cmdline) * /usr/bin/python [-XXX] /usr/bin/system-control-network */ argv1++; /* skip the space */ - if (*argv1 == '-') - { - /* looks like -XXX in "perl -XXX /usr/bin/script.pl", skip */ - argv1 = strpbrk(argv1, " \t"); - continue; - } - if (*argv1 == ' ' || *argv1 == '\t') /* skip multiple spaces */ - continue; - if (*argv1 != '/') - { - /* if the string following the space doesn't start - * with '/' it's probably not a full path to script - * and we can't use it to determine the package name - */ + if (*argv1 != '-') break; - } - - /* cut the rest of cmdline arguments */ - int len = strchrnul(argv1, ' ') - argv1; - return xstrndup(argv1, len); + /* looks like -XXX in "perl -XXX /usr/bin/script.pl", skipping */ + argv1 = strchr(argv1, ' '); } - return NULL; + + /* if the string following the space doesn't start + * with '/', it is not a full path to script + * and we can't use it to determine the package name + */ + if (*argv1 != '/') + return NULL; + + /* good, it has "/foo/bar" form, return it */ + int len = strchrnul(argv1, ' ') - argv1; + return xstrndup(argv1, len); } static bool is_path_blacklisted(const char *path) @@ -141,7 +138,7 @@ static int SavePackageDescriptionToDebugDump(const char *dump_dir_name) host[HOST_NAME_MAX] = '\0'; dd_save_text(dd, FILENAME_HOSTNAME, host); } - goto ret0; /* no error */ + goto ret0; /* no error */ } log("Executable '%s' doesn't belong to any package", executable); goto ret; /* return 1 (failure) */ |
