Skip to content

Commit 531671c

Browse files
committedOct 27, 2014
log: fix use-after-free in 47dfcb7
Causes pettycoin to segv (generator logs). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 4941699 commit 531671c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed
 

‎log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static void add_entry(struct log *log, struct log_entry *l)
145145

146146
static struct log_entry *new_log_entry(struct log *log, enum log_level level)
147147
{
148-
struct log_entry *l = tal(log, struct log_entry);
148+
struct log_entry *l = tal(log->lr, struct log_entry);
149149

150150
l->time = time_now();
151151
l->level = level;

‎test/run-06-log.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,13 @@ int main(void)
122122
wait(&status);
123123
assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
124124

125+
/* Make sure log record survives freeing of log. */
126+
tal_free(log);
127+
125128
/* This cleans us out! */
129+
log = new_log(ctx, lr, "PREFIX2:");
126130
log_debug(log, "Overflow!");
127-
131+
128132
/* Make child write log, be sure it's correct. */
129133
pipe(fds);
130134
switch (fork()) {
@@ -147,8 +151,8 @@ int main(void)
147151
assert(tal_strreg(p, p,
148152
"([0-9]*) bytes, Sun Nov 10 06:27:35 2013\n"
149153
"\\.\\.\\. 4 skipped\\.\\.\\.\n"
150-
"\\+0.000000004 PREFIX:DEBUG: Overflow!\n"
151-
"\\+0.000000004 PREFIX:DEBUG: Log pruned 4 entries \\(mem ([0-9]*) -> ([0-9]*)\\)\n\n", &mem1, &mem2, &mem3));
154+
"\\+0.000000004 PREFIX2:DEBUG: Overflow!\n"
155+
"\\+0.000000004 PREFIX2:DEBUG: Log pruned 4 entries \\(mem ([0-9]*) -> ([0-9]*)\\)\n\n", &mem1, &mem2, &mem3));
152156
assert(atoi(mem1) < maxmem);
153157
assert(atoi(mem2) >= maxmem);
154158
assert(atoi(mem3) < maxmem);

0 commit comments

Comments
 (0)
Please sign in to comment.