summaryrefslogtreecommitdiffstats
path: root/src/Hooks
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-10-31 04:35:02 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-10-31 04:35:02 +0100
commit887d928a39fc9793df6f3d69a89cb48f4a85679c (patch)
tree185e15f924bd33d4652ac3062bee01f5e41a2118 /src/Hooks
parentb75a8f795fc1ea7a4604c09d65d91a75ddbbbbea (diff)
downloadabrt-887d928a39fc9793df6f3d69a89cb48f4a85679c.tar.gz
abrt-887d928a39fc9793df6f3d69a89cb48f4a85679c.tar.xz
abrt-887d928a39fc9793df6f3d69a89cb48f4a85679c.zip
fix a bug where after realloc we may scribble over uninitialized memory
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src/Hooks')
-rw-r--r--src/Hooks/abrt-pyhook-helper.cpp47
1 files changed, 15 insertions, 32 deletions
diff --git a/src/Hooks/abrt-pyhook-helper.cpp b/src/Hooks/abrt-pyhook-helper.cpp
index 7a4ffc8b..eebda55f 100644
--- a/src/Hooks/abrt-pyhook-helper.cpp
+++ b/src/Hooks/abrt-pyhook-helper.cpp
@@ -19,12 +19,12 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <argp.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+/* We can easily get rid of abrtlib (libABRTUtils.so) usage in this file,
+ * but DebugDump will pull it in anyway */
+#include "abrtlib.h"
#include "DebugDump.h"
#if HAVE_CONFIG_H
-#include <config.h>
+# include <config.h>
#endif
const char *argp_program_version = "abrt-pyhook-helper " VERSION;
@@ -51,7 +51,7 @@ struct arguments
};
static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
+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. */
@@ -87,46 +87,29 @@ parse_opt (int key, char *arg, struct argp_state *state)
/* Our argp parser. */
static struct argp argp = { options, parse_opt, 0, doc };
+#define MAX_BT_SIZE (1024*1024)
+
int main(int argc, char** argv)
{
struct arguments arguments;
argp_parse (&argp, argc, argv, 0, 0, &arguments);
// Read the backtrace from stdin.
- int c;
- int capacity = 1024;
- char *bt = (char*)malloc(capacity);
- if (!bt)
+ char *bt = (char*)xmalloc(MAX_BT_SIZE);
+ ssize_t len = full_read(STDIN_FILENO, bt, MAX_BT_SIZE-1);
+ if (len < 0)
{
- fprintf(stderr, "Error while allocating memory for backtrace.\n");
- return 1;
+ perror_msg_and_die("Read error");
}
- char *btptr = bt;
- while ((c = getchar()) != EOF)
+ bt[len] = '\0';
+ if (len == MAX_BT_SIZE-1)
{
- *btptr++ = (char)c;
- if (btptr - bt >= capacity - 1)
- {
- capacity *= 2;
- if (capacity > 1048576) // > 1 MB
- {
- fprintf(stderr, "Backtrace size limit exceeded. Trimming to 1 MB.\n");
- break;
- }
-
- bt = (char*)realloc(bt, capacity);
- if (!bt)
- {
- fprintf(stderr, "Error while allocating memory for backtrace.\n");
- return 1;
- }
- }
+ error_msg("Backtrace size limit exceeded, trimming to 1 MB");
}
- *btptr = '\0';
// 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), DEBUG_DUMPS_DIR"/pyhook-%ld-%s",
(long)time(NULL), arguments.pid);
CDebugDump dd;