Skip to content

Commit ac9fcb1

Browse files
mlaventurenalind
authored andcommitted
Prevent freeing a possible invalid pointer from journald
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
1 parent 21f3ea4 commit ac9fcb1

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

daemon/logger/journald/read.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ drain:
237237

238238
// free(NULL) is safe
239239
C.free(unsafe.Pointer(oldCursor))
240-
C.sd_journal_get_cursor(j, &cursor)
240+
if C.sd_journal_get_cursor(j, &cursor) != 0 {
241+
// ensure that we won't be freeing an address that's invalid
242+
cursor = nil
243+
}
241244
return cursor
242245
}
243246

@@ -271,7 +274,6 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
271274
s.readers.mu.Lock()
272275
delete(s.readers.readers, logWatcher)
273276
s.readers.mu.Unlock()
274-
C.sd_journal_close(j)
275277
close(logWatcher.Msg)
276278
}()
277279
// Wait until we're told to stop.
@@ -305,9 +307,9 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon
305307
following := false
306308
defer func(pfollowing *bool) {
307309
if !*pfollowing {
308-
C.sd_journal_close(j)
309310
close(logWatcher.Msg)
310311
}
312+
C.sd_journal_close(j)
311313
}(&following)
312314
// Remove limits on the size of data items that we'll retrieve.
313315
rc = C.sd_journal_set_data_threshold(j, C.size_t(0))

0 commit comments

Comments
 (0)