From 96432fc6655fe035d0e66e593ffaf58856e1a826 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 8 Mar 2016 16:18:26 -0800 Subject: [PATCH] liblog: add __android_log_config_*_close() Add __android_log_config_read_close() and __android_log_config_write_close(). Fortify the list macros to detect for list corruption, looking for entries pointing to themselves, deleted entries in list. Test: gTest liblog-unit-tests Bug: 27405083 Change-Id: I33e8a0cae7e202f1989ddd7c2a96752b44c8e746 --- liblog/config_read.c | 12 ++++++++++++ liblog/config_read.h | 25 +++++++++++++++++-------- liblog/config_write.c | 14 ++++++++++++++ liblog/config_write.h | 21 +++++++++++++++------ 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/liblog/config_read.c b/liblog/config_read.c index 1f54152b0..a4232f412 100644 --- a/liblog/config_read.c +++ b/liblog/config_read.c @@ -60,3 +60,15 @@ LIBLOG_HIDDEN void __android_log_config_read() { __android_log_add_transport(&__android_log_persist_read, &pmsgLoggerRead); #endif } + +LIBLOG_HIDDEN void __android_log_config_read_close() { + struct android_log_transport_read *transport; + struct listnode *n; + + read_transport_for_each_safe(transport, n, &__android_log_transport_read) { + list_remove(&transport->node); + } + read_transport_for_each_safe(transport, n, &__android_log_persist_read) { + list_remove(&transport->node); + } +} diff --git a/liblog/config_read.h b/liblog/config_read.h index 49a3b7526..892e80dca 100644 --- a/liblog/config_read.h +++ b/liblog/config_read.h @@ -28,22 +28,31 @@ extern LIBLOG_HIDDEN struct listnode __android_log_persist_read; #define read_transport_for_each(transp, transports) \ for ((transp) = node_to_item((transports)->next, \ - struct android_log_transport_read, node); \ - ((transp) != node_to_item(transports, \ - struct android_log_transport_read, node)); \ + struct android_log_transport_read, node); \ + ((transp) != node_to_item((transports), \ + struct android_log_transport_read, \ + node)) && \ + ((transp) != node_to_item((transp)->node.next, \ + struct android_log_transport_read, \ + node)); \ (transp) = node_to_item((transp)->node.next, \ - struct android_log_transport_read, node)) \ + struct android_log_transport_read, node)) #define read_transport_for_each_safe(transp, n, transports) \ for ((transp) = node_to_item((transports)->next, \ - struct android_log_transport_read, node), \ + struct android_log_transport_read, node), \ (n) = (transp)->node.next; \ - ((transp) != node_to_item(transports, \ - struct android_log_transport_read, node)); \ - (transp) = node_to_item(n, struct android_log_transport_read, node), \ + ((transp) != node_to_item((transports), \ + struct android_log_transport_read, \ + node)) && \ + ((transp) != node_to_item((n), struct android_log_transport_read, \ + node)); \ + (transp) = node_to_item((n), struct android_log_transport_read, \ + node), \ (n) = (transp)->node.next) LIBLOG_HIDDEN void __android_log_config_read(); +LIBLOG_HIDDEN void __android_log_config_read_close(); __END_DECLS diff --git a/liblog/config_write.c b/liblog/config_write.c index d689f631b..0aaaea6e4 100644 --- a/liblog/config_write.c +++ b/liblog/config_write.c @@ -64,3 +64,17 @@ LIBLOG_HIDDEN void __android_log_config_write() { __android_log_add_transport(&__android_log_transport_write, &fakeLoggerWrite); #endif } + +LIBLOG_HIDDEN void __android_log_config_write_close() { + struct android_log_transport_write *transport; + struct listnode *n; + + write_transport_for_each_safe(transport, n, &__android_log_transport_write) { + transport->logMask = 0; + list_remove(&transport->node); + } + write_transport_for_each_safe(transport, n, &__android_log_persist_write) { + transport->logMask = 0; + list_remove(&transport->node); + } +} diff --git a/liblog/config_write.h b/liblog/config_write.h index 3b01a9a80..882541130 100644 --- a/liblog/config_write.h +++ b/liblog/config_write.h @@ -29,21 +29,30 @@ extern LIBLOG_HIDDEN struct listnode __android_log_persist_write; #define write_transport_for_each(transp, transports) \ for ((transp) = node_to_item((transports)->next, \ struct android_log_transport_write, node); \ - ((transp) != node_to_item(transports, \ - struct android_log_transport_write, node)); \ + ((transp) != node_to_item((transports), \ + struct android_log_transport_write, \ + node)) && \ + ((transp) != node_to_item((transp)->node.next, \ + struct android_log_transport_write, \ + node)); \ (transp) = node_to_item((transp)->node.next, \ - struct android_log_transport_write, node)) \ + struct android_log_transport_write, node)) #define write_transport_for_each_safe(transp, n, transports) \ for ((transp) = node_to_item((transports)->next, \ struct android_log_transport_write, node), \ (n) = (transp)->node.next; \ - ((transp) != node_to_item(transports, \ - struct android_log_transport_write, node)); \ - (transp) = node_to_item(n, struct android_log_transport_write, node), \ + ((transp) != node_to_item((transports), \ + struct android_log_transport_write, \ + node)) && \ + ((transp) != node_to_item((n), struct android_log_transport_write, \ + node)); \ + (transp) = node_to_item((n), struct android_log_transport_write, \ + node), \ (n) = (transp)->node.next) LIBLOG_HIDDEN void __android_log_config_write(); +LIBLOG_HIDDEN void __android_log_config_write_close(); __END_DECLS