* [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks
@ 2021-07-14 11:05 Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 01/16] gdbus: annotate printf-like functions as accepting format Krzysztof Kozlowski
` (15 more replies)
0 siblings, 16 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Hi,
This is a third series of my patches, built on top of
https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski@canonical.com/T/#t
The ASAN detected several leaks in the unit tests which lead me to
investigate such leaks through neard. The patchset fixes few easier
ones.
Best regards,
Krzysztof
Krzysztof Kozlowski (16):
gdbus: annotate printf-like functions as accepting format
nfctool: annotate printf-like functions as accepting format
mifare: use unsigned int to suppress compiler -Wstrict-overflow
build: enable -Wformat=2 warnings
build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2
warnings
TODO: remove finished tasks
ci: build also on Ubuntu Hirsute in non-maintainer mode
ci: simplify getting test logs
build: fix missing usage of PIE check result
build: add support for GCC sanitizers (asan, lsan and ubsan)
ndef: make freeing near_ndef_message reusable
snep-send: fix near_ndef_message memory leak
unit: fix memory leaks in test-ndef-parse
tag: do not open-code freeing ndef message
unit: do not open-code freeing ndef message
ci: add build with sanitizers (asan, lsan and ubsan)
.github/workflows/ci.yml | 58 +++++++++++++++++++++++++++++++++-------
HACKING | 5 +++-
TODO | 12 ---------
accflags.m4 | 12 +++++++--
acinclude.m4 | 36 +++++++++++++++++++++++++
ci/debian.sanitizers.sh | 18 +++++++++++++
ci/ubuntu.sanitizers.sh | 1 +
configure.ac | 47 +++++++++++++++++++++++++++++++-
gdbus/gdbus.h | 15 +++++++----
include/ndef.h | 1 +
plugins/mifare.c | 6 ++---
src/adapter.c | 1 +
src/ndef.c | 56 +++++++++++++++++++-------------------
src/tag.c | 6 ++---
tools/nfctool/sniffer.c | 8 +++---
tools/snep-send.c | 2 ++
unit/test-ndef-parse.c | 39 ++++-----------------------
unit/test-snep-read.c | 3 +--
18 files changed, 221 insertions(+), 105 deletions(-)
create mode 100755 ci/debian.sanitizers.sh
create mode 120000 ci/ubuntu.sanitizers.sh
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 01/16] gdbus: annotate printf-like functions as accepting format
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 02/16] nfctool: " Krzysztof Kozlowski
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Printf-like functions should have the "format" argument annotated to:
1. Help in detection of format string vulnerabilities (and mistakes).
2. Satisfy -Wformat-nonliteral (-Wformat=2) warning.
This fixes clang warnings like:
gdbus/object.c:1416:31: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
vsnprintf(str, sizeof(str), format, args);
^~~~~~
src/adapter.c:255:7: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
strerror(err));
^~~~~~~~~~~~~
src/adapter.c:255:7: note: treat the string as an argument to avoid this
strerror(err));
^
"%s",
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
gdbus/gdbus.h | 15 ++++++++++-----
src/adapter.c | 1 +
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index d99c2549d056..e9ffd029e178 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -239,13 +239,15 @@ void g_dbus_pending_error(DBusConnection *connection,
__attribute__((format(printf, 4, 5)));
void g_dbus_pending_error_valist(DBusConnection *connection,
GDBusPendingReply pending, const char *name,
- const char *format, va_list args);
+ const char *format, va_list args)
+ __attribute__ ((format (printf, 4, 0)));
DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
const char *format, ...)
__attribute__((format(printf, 3, 4)));
DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
- const char *format, va_list args);
+ const char *format, va_list args)
+ __attribute__ ((format (printf, 3, 0)));
DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
int type, va_list args);
@@ -259,7 +261,8 @@ gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
__attribute__((format(printf, 4, 5)));
gboolean g_dbus_send_error_valist(DBusConnection *connection,
DBusMessage *message, const char *name,
- const char *format, va_list args);
+ const char *format, va_list args)
+ __attribute__ ((format (printf, 4, 0)));
gboolean g_dbus_send_reply(DBusConnection *connection,
DBusMessage *message, int type, ...);
gboolean g_dbus_send_reply_valist(DBusConnection *connection,
@@ -294,9 +297,11 @@ void g_dbus_remove_all_watches(DBusConnection *connection);
void g_dbus_pending_property_success(GDBusPendingPropertySet id);
void g_dbus_pending_property_error_valist(GDBusPendingReply id,
- const char *name, const char *format, va_list args);
+ const char *name, const char *format, va_list args)
+ __attribute__ ((format (printf, 3, 0)));
void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
- const char *format, ...);
+ const char *format, ...)
+ __attribute__((format(printf, 3, 4)));
void g_dbus_emit_property_changed(DBusConnection *connection,
const char *path, const char *interface,
const char *name);
diff --git a/src/adapter.c b/src/adapter.c
index 420127f4f396..e0ab8c5d6055 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -252,6 +252,7 @@ static void set_powered(GDBusPendingPropertySet id, dbus_bool_t powered,
g_dbus_pending_property_error(id,
NFC_ERROR_INTERFACE ".Failed",
+ "%s",
strerror(err));
return;
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 02/16] nfctool: annotate printf-like functions as accepting format
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 01/16] gdbus: annotate printf-like functions as accepting format Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 03/16] mifare: use unsigned int to suppress compiler -Wstrict-overflow Krzysztof Kozlowski
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Printf-like functions should have the "format" argument annotated to:
1. Help in detection of format string vulnerabilities (and mistakes).
2. Satisfy -Wformat-nonliteral (-Wformat=2) warning.
This fixes clang warnings like:
tools/nfctool/sniffer.c:206:18: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
sprintf(line, fmt, offset);
^~~
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
tools/nfctool/sniffer.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/nfctool/sniffer.c b/tools/nfctool/sniffer.c
index 3d1d230a50c5..6a38a213c74d 100644
--- a/tools/nfctool/sniffer.c
+++ b/tools/nfctool/sniffer.c
@@ -168,7 +168,6 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
gchar *hexa = NULL, *human = NULL;
guint8 offset_len;
guint8 human_offset;
- gchar *fmt;
if (len == 0)
return;
@@ -185,11 +184,9 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
if (output_len > 0xFFFF) {
offset_len = 8;
human_offset = HUMAN_READABLE_OFFSET + 4;
- fmt = "%08X: ";
} else {
offset_len = 4;
human_offset = HUMAN_READABLE_OFFSET;
- fmt = "%04X: ";
}
if (print_len) {
@@ -203,7 +200,10 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
if (digits == 0) {
memset(line, ' ', human_offset);
- sprintf(line, fmt, offset);
+ if (offset_len == 8)
+ sprintf(line, "%08X: ", offset);
+ else
+ sprintf(line, "%04X: ", offset);
offset += 16;
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 03/16] mifare: use unsigned int to suppress compiler -Wstrict-overflow
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 01/16] gdbus: annotate printf-like functions as accepting format Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 02/16] nfctool: " Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 04/16] build: enable -Wformat=2 warnings Krzysztof Kozlowski
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
GCC v7.5 (Ubuntu Bionic) with optimizations has trouble spotting lack of
possible overflow of a signed integer. There is no overflow possible
so this is a false positive which can be suppressed by simply using
unsigned integer. Unsigned also has more sense in that context.
This fixes GCC 7.5 warning:
plugins/mifare.c: In function 'mifare_process_MADs':
plugins/mifare.c:626:5: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
if (global_tag_size == 0) {
^
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
plugins/mifare.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/plugins/mifare.c b/plugins/mifare.c
index a4e4ba443995..f42007d5dfd7 100644
--- a/plugins/mifare.c
+++ b/plugins/mifare.c
@@ -560,7 +560,7 @@ static int mifare_process_MADs(void *data)
struct mifare_cookie *mf_ck = data;
int err;
int i;
- int global_tag_size = 0;
+ unsigned int global_tag_size = 0;
int ioffset;
uint8_t *tag_data;
size_t data_size;
@@ -626,13 +626,13 @@ done_mad:
if (global_tag_size == 0) {
/* no NFC sectors - mark tag as blank */
- near_error("TAG Global size: [%d], not valid NFC tag.",
+ near_error("TAG Global size: [%u], not valid NFC tag.",
global_tag_size);
return -ENODEV;
}
/* n sectors, each sector is 3 blocks, each block is 16 bytes */
- DBG("TAG Global size: [%d]", global_tag_size);
+ DBG("TAG Global size: [%u]", global_tag_size);
mf_ck->tag = near_tag_get_tag(mf_ck->adapter_idx, mf_ck->target_idx);
if (!mf_ck->tag) {
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 04/16] build: enable -Wformat=2 warnings
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (2 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 03/16] mifare: use unsigned int to suppress compiler -Wstrict-overflow Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 05/16] build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2 warnings Krzysztof Kozlowski
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
The -Wformat=2 compiler warning can detect potentials errors when using
printf-like functions. It is supported by GCC and clang.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
accflags.m4 | 1 +
1 file changed, 1 insertion(+)
diff --git a/accflags.m4 b/accflags.m4
index e4df62c13cf3..57cc48beecc2 100644
--- a/accflags.m4
+++ b/accflags.m4
@@ -14,6 +14,7 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [
CFLAGS="$CFLAGS -Wmissing-declarations"
CFLAGS="$CFLAGS -Wredundant-decls"
CFLAGS="$CFLAGS -Wcast-align"
+ CFLAGS="$CFLAGS -Wformat=2"
CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"
AX_CHECK_COMPILE_FLAG([-Wdouble-promotion], [CFLAGS="$CFLAGS -Wdouble-promotion"])
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 05/16] build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2 warnings
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (3 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 04/16] build: enable -Wformat=2 warnings Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 06/16] TODO: remove finished tasks Krzysztof Kozlowski
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Enable basic overflow in optimization checks (portability related) and
missed loop optimizations. The latter (-Wunsafe-loop-optimizations)
does not work well with GCC v7.5 so simply skip it there.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
accflags.m4 | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/accflags.m4 b/accflags.m4
index 57cc48beecc2..0030ac339c86 100644
--- a/accflags.m4
+++ b/accflags.m4
@@ -24,6 +24,7 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [
AX_CHECK_COMPILE_FLAG([-Wjump-misses-init], [CFLAGS="$CFLAGS -Wjump-misses-init"])
AX_CHECK_COMPILE_FLAG([-Wpointer-arith], [CFLAGS="$CFLAGS -Wpointer-arith"])
AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"])
+ AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=2], [CFLAGS="$CFLAGS -Wstrict-overflow=2"])
# GCC v5.0
AX_CHECK_COMPILE_FLAG([-Wformat-signedness], [CFLAGS="$CFLAGS -Wformat-signedness"])
@@ -36,10 +37,16 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [
AX_CHECK_COMPILE_FLAG([-Walloc-zero], [CFLAGS="$CFLAGS -Walloc-zero"])
# GCC v8.0
AX_CHECK_COMPILE_FLAG([-Wstringop-truncation], [CFLAGS="$CFLAGS -Wstringop-truncation"])
+
+ # GCC v7.5 from Ubuntu Bionic incorrectly assumes several loops can overflow, so enable
+ # -Wunsafe-loop-optimizations only on newer GCC.
+ CC_VERSION=`$CC --version | head -n 1 | sed -e 's/.*\ \(@<:@0-9@:>@\+\.@<:@0-9@:>@\+\.@<:@0-9@:>@\+\)\(-@<:@0-9@:>@\+\)\?$/\1/'`
+ AX_COMPARE_VERSION([$CC_VERSION],[ge],[8.0.0],
+ [AX_CHECK_COMPILE_FLAG([-Wunsafe-loop-optimizations], [CFLAGS="$CFLAGS -Wunsafe-loop-optimizations"])], [])
fi
if (test "$USE_MAINTAINER_MODE" = "pedantic"); then
- AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=3], [CFLAGS="$CFLAGS -Wstrict-overflow=3"])
AX_CHECK_COMPILE_FLAG([-Wcast-qual], [CFLAGS="$CFLAGS -Wcast-qual"])
- AX_CHECK_COMPILE_FLAG([-Wunsafe-loop-optimizations], [CFLAGS="$CFLAGS -Wunsafe-loop-optimizations"])
+ # Instead of -Wstrict-overflow=2
+ AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=3], [CFLAGS="$CFLAGS -Wstrict-overflow=3"])
fi
])
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 06/16] TODO: remove finished tasks
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (4 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 05/16] build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2 warnings Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 07/16] ci: build also on Ubuntu Hirsute in non-maintainer mode Krzysztof Kozlowski
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Continuous Integration is ready with cross compile and clang. clang
warnings were fixed.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
TODO | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/TODO b/TODO
index 1d5294519c3b..8d63f3571c85 100644
--- a/TODO
+++ b/TODO
@@ -11,18 +11,6 @@ Background
Core
====
-- Add more Continuous Integration builds (32-bit x86, cross compile, clang).
- Priority: High
- Complexity: C2
-
-- Add clang builds in Continuous Integration.
- Priority: High
- Complexity: C2
-
-- Fix clang build errors.
- Priority: High
- Complexity: C2
-
- Add more GCC/clang warnings and fix them.
Priority: High
Complexity: C4
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 07/16] ci: build also on Ubuntu Hirsute in non-maintainer mode
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (5 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 06/16] TODO: remove finished tasks Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 08/16] ci: simplify getting test logs Krzysztof Kozlowski
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Increase the coverage.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
.github/workflows/ci.yml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a9335e100fb4..6ecd38177bde 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -153,6 +153,12 @@ jobs:
CC: gcc
MODE: maintainer
+ - container: "ubuntu:hirsute"
+ env:
+ ARCH: x86-64
+ CC: gcc
+ MODE: no-maintainer
+
- container: "ubuntu:focal"
env:
ARCH: x86-64
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 08/16] ci: simplify getting test logs
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (6 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 07/16] ci: build also on Ubuntu Hirsute in non-maintainer mode Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 09/16] build: fix missing usage of PIE check result Krzysztof Kozlowski
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
make check-TESTS stores the logs in one file, so no need to get them one
by one.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
.github/workflows/ci.yml | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6ecd38177bde..14cc4306de23 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -259,13 +259,7 @@ jobs:
if: ${{ (matrix.env['ARCH'] == 'x86-64') || (matrix.env['ARCH'] == 'i386') }}
- name: Get unit tests logs
- run: |
- for i in unit/*log
- do
- echo "#######################"
- echo "LOG: $i"
- cat $i
- done
+ run: cat test-suite.log
if: ${{ always() && ((steps.unit_tests.outcome == 'failure') ||
(steps.unit_tests.outcome == 'success')) }}
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 09/16] build: fix missing usage of PIE check result
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (7 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 08/16] ci: simplify getting test logs Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 10/16] build: add support for GCC sanitizers (asan, lsan and ubsan) Krzysztof Kozlowski
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
The test whether compiler accepts -fPIE in acinclude.m4 is stored as
neard_cv_prog_cc_pie variable. Refering wrong name in test for
accepting '--enable-pie' configure argument caused PIE to be never
enabled (unless by default by compiler).
Fixes: 10c7e4a3cec3 ("build: Namespace local macros with NEARD_ instead of AC_ or nothing")
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index b9419c1fad74..1ec6f4eb30ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,7 +89,7 @@ AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],
AC_ARG_ENABLE(pie, AS_HELP_STRING([--enable-pie],
[enable position independent executables flag]), [
if (test "${enableval}" = "yes" &&
- test "${ac_cv_prog_cc_pie}" = "yes"); then
+ test "${neard_cv_prog_cc_pie}" = "yes"); then
CFLAGS="$CFLAGS -fPIE"
LDFLAGS="$LDFLAGS -pie"
fi
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 10/16] build: add support for GCC sanitizers (asan, lsan and ubsan)
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (8 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 09/16] build: fix missing usage of PIE check result Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 11/16] ndef: make freeing near_ndef_message reusable Krzysztof Kozlowski
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Add support for GCC sanitizers: address (asan), leak (lsan) and
undefined behavior (ubsan). These can be toggled in ./configure with
--enable-asan, --enable-lsan and --enable-ubsan.
The autoconf code for this derived from ell (mostly authored by Mat
Martineau <mathew.j.martineau@linux.intel.com>):
https://git.kernel.org/pub/scm/libs/ell/ell.git
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
acinclude.m4 | 36 ++++++++++++++++++++++++++++++++++++
configure.ac | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git a/acinclude.m4 b/acinclude.m4
index a12b93972cfa..e9ad0d63cc8c 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -9,3 +9,39 @@ AC_DEFUN([NEARD_PROG_CC_PIE], [
rm -rf conftest*
])
])
+
+AC_DEFUN([NEARD_PROG_CC_ASAN], [
+AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=address], neard_cv_prog_cc_asan, [
+ echo 'void f(){}' > conftest.c
+ if test -z "`${CC-cc} -fsanitize=address -c conftest.c 2>&1`"; then
+ neard_cv_prog_cc_asan=yes
+ else
+ neard_cv_prog_cc_asan=no
+ fi
+ rm -rf conftest*
+])
+])
+
+AC_DEFUN([NEARD_PROG_CC_LSAN], [
+AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=leak], neard_cv_prog_cc_lsan, [
+ echo 'void f(){}' > conftest.c
+ if test -z "`${CC-cc} -fsanitize=leak -c conftest.c 2>&1`"; then
+ neard_cv_prog_cc_lsan=yes
+ else
+ neard_cv_prog_cc_lsan=no
+ fi
+ rm -rf conftest*
+])
+])
+
+AC_DEFUN([NEARD_PROG_CC_UBSAN], [
+AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=undefined], neard_cv_prog_cc_ubsan, [
+ echo 'void f(){}' > conftest.c
+ if test -z "`${CC-cc} -fsanitize=undefined -c conftest.c 2>&1`"; then
+ neard_cv_prog_cc_ubsan=yes
+ else
+ neard_cv_prog_cc_ubsan=no
+ fi
+ rm -rf conftest*
+])
+])
diff --git a/configure.ac b/configure.ac
index 1ec6f4eb30ea..c1fdc44ae02d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,9 @@ AC_LANG([C])
AC_PROG_CC
NEARD_PROG_CC_PIE
+NEARD_PROG_CC_ASAN
+NEARD_PROG_CC_LSAN
+NEARD_PROG_CC_UBSAN
AC_PROG_INSTALL
AC_PROG_MKDIR_P
@@ -98,6 +101,48 @@ AC_ARG_ENABLE(pie, AS_HELP_STRING([--enable-pie],
AC_CHECK_LIB(dl, dlopen, dummy=yes,
AC_MSG_ERROR(dynamic linking loader is required))
+save_LIBS=$LIBS
+AC_CHECK_LIB(asan, _init)
+LIBS=$save_LIBS
+
+AC_ARG_ENABLE(asan, AC_HELP_STRING([--enable-asan],
+ [enable linking with address sanitizer]), [
+ if (test "${enableval}" = "yes" &&
+ test "${ac_cv_lib_asan__init}" = "yes" &&
+ test "${neard_cv_prog_cc_asan}" = "yes"); then
+ CFLAGS="$CFLAGS -fsanitize=address";
+ LDFLAGS="$LDFLAGS -fsanitize=address"
+ fi
+])
+
+save_LIBS=$LIBS
+AC_CHECK_LIB(lsan, _init)
+LIBS=$save_LIBS
+
+AC_ARG_ENABLE(lsan, AC_HELP_STRING([--enable-lsan],
+ [enable linking with leak sanitizer]), [
+ if (test "${enableval}" = "yes" &&
+ test "${ac_cv_lib_lsan__init}" = "yes" &&
+ test "${neard_cv_prog_cc_lsan}" = "yes"); then
+ CFLAGS="$CFLAGS -fsanitize=leak";
+ LDFLAGS="$LDFLAGS -fsanitize=leak"
+ fi
+])
+
+save_LIBS=$LIBS
+AC_CHECK_LIB(ubsan, _init)
+LIBS=$save_LIBS
+
+AC_ARG_ENABLE(ubsan, AC_HELP_STRING([--enable-ubsan],
+ [enable linking with undefined behavior sanitizer]), [
+ if (test "${enableval}" = "yes" &&
+ test "${ac_cv_lib_ubsan__init}" = "yes" &&
+ test "${neard_cv_prog_cc_ubsan}" = "yes"); then
+ CFLAGS="$CFLAGS -fsanitize=undefined";
+ LDFLAGS="$LDFLAGS -fsanitize=undefined"
+ fi
+])
+
GLIB_DEPS="glib-2.0 >= 2.28"
PKG_CHECK_MODULES(GLIB, [${GLIB_DEPS}], dummy=yes,
AC_MSG_ERROR(GLib >= 2.28 is required))
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 11/16] ndef: make freeing near_ndef_message reusable
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (9 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 10/16] build: add support for GCC sanitizers (asan, lsan and ubsan) Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 12/16] snep-send: fix near_ndef_message memory leak Krzysztof Kozlowski
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
In few places the ndef record/message (struct near_ndef_message) is
allocated and not freed leading to memory leaks. In few places it is
also open-coded. Rename free_ndef_message() to near_ndef_msg_free()
and allow other parts to use it. No functional change, except global
symbol.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
include/ndef.h | 1 +
src/ndef.c | 56 +++++++++++++++++++++++++-------------------------
2 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/include/ndef.h b/include/ndef.h
index 5abdf343ee07..a21eed2654e9 100644
--- a/include/ndef.h
+++ b/include/ndef.h
@@ -44,6 +44,7 @@ GList *near_ndef_parse_msg(uint8_t *ndef_data, size_t ndef_length,
struct near_ndef_message **reply);
void near_ndef_records_free(GList *records);
+void near_ndef_msg_free(struct near_ndef_message *record);
struct near_ndef_message *near_ndef_prepare_text_record(char *encoding,
char *language_code, char *text);
diff --git a/src/ndef.c b/src/ndef.c
index 66faf7867399..3dd8838ef9e6 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -832,15 +832,6 @@ static void free_ndef_record(struct near_ndef_record *record)
g_free(record);
}
-static void free_ndef_message(struct near_ndef_message *msg)
-{
- if (!msg)
- return;
-
- g_free(msg->data);
- g_free(msg);
-}
-
void __near_ndef_record_free(struct near_ndef_record *record)
{
g_dbus_unregister_interface(connection, record->path,
@@ -1752,7 +1743,7 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name,
fail:
near_error("ndef message struct allocation failed");
- free_ndef_message(msg);
+ near_ndef_msg_free(msg);
return NULL;
}
@@ -2015,8 +2006,8 @@ static int near_ndef_prepare_ac_and_cfg_records(enum record_type type,
g_free(local_carrier);
if (!*cfg || !*ac) {
- free_ndef_message(*ac);
- free_ndef_message(*cfg);
+ near_ndef_msg_free(*ac);
+ near_ndef_msg_free(*cfg);
return -ENOMEM;
}
@@ -2028,7 +2019,7 @@ static void free_ndef_list(gpointer data)
{
struct near_ndef_message *msg = data;
- free_ndef_message(msg);
+ near_ndef_msg_free(msg);
}
static struct near_ndef_message *prepare_handover_message_header(char *type,
@@ -2149,13 +2140,13 @@ static struct near_ndef_message *near_ndef_prepare_empty_hs_message(void)
if (hs_msg->offset > hs_msg->length)
goto fail;
- free_ndef_message(ac_msg);
+ near_ndef_msg_free(ac_msg);
return hs_msg;
fail:
- free_ndef_message(ac_msg);
- free_ndef_message(hs_msg);
+ near_ndef_msg_free(ac_msg);
+ near_ndef_msg_free(hs_msg);
return NULL;
}
@@ -2272,7 +2263,7 @@ fail:
g_list_free_full(ac_msgs, free_ndef_list);
g_list_free_full(cfg_msgs, free_ndef_list);
- free_ndef_message(hs_msg);
+ near_ndef_msg_free(hs_msg);
return NULL;
}
@@ -2406,7 +2397,7 @@ near_ndef_prepare_ho_message(enum record_type type, GSList *carriers)
DBG("Handover message preparation is done");
- free_ndef_message(cr_msg);
+ near_ndef_msg_free(cr_msg);
g_list_free_full(ac_msgs, free_ndef_list);
g_list_free_full(cfg_msgs, free_ndef_list);
@@ -2417,8 +2408,8 @@ fail:
g_list_free_full(ac_msgs, free_ndef_list);
g_list_free_full(cfg_msgs, free_ndef_list);
- free_ndef_message(cr_msg);
- free_ndef_message(ho_msg);
+ near_ndef_msg_free(cr_msg);
+ near_ndef_msg_free(ho_msg);
return NULL;
}
@@ -2999,6 +2990,15 @@ void near_ndef_records_free(GList *records)
g_list_free(records);
}
+void near_ndef_msg_free(struct near_ndef_message *msg)
+{
+ if (!msg)
+ return;
+
+ g_free(msg->data);
+ g_free(msg);
+}
+
/*
* Compute ndef records length, even though the submitted frame is incomplete.
* This code is used in the handover read function, as we have to "guess" the
@@ -3166,7 +3166,7 @@ struct near_ndef_message *near_ndef_prepare_text_record(char *encoding,
fail:
near_error("text record preparation failed");
- free_ndef_message(msg);
+ near_ndef_msg_free(msg);
return NULL;
}
@@ -3205,7 +3205,7 @@ struct near_ndef_message *near_ndef_prepare_uri_record(uint8_t identifier,
fail:
near_error("uri record preparation failed");
- free_ndef_message(msg);
+ near_ndef_msg_free(msg);
return NULL;
}
@@ -3234,15 +3234,15 @@ near_ndef_prepare_smartposter_record(uint8_t uri_identifier,
if (msg->offset > msg->length)
goto fail;
- free_ndef_message(uri);
+ near_ndef_msg_free(uri);
return msg;
fail:
near_error("smartposter record preparation failed");
- free_ndef_message(uri);
- free_ndef_message(msg);
+ near_ndef_msg_free(uri);
+ near_ndef_msg_free(msg);
return NULL;
}
@@ -3908,7 +3908,7 @@ struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg)
if (!ndef_message_append(ndef, record))
goto err;
- free_ndef_message(record);
+ near_ndef_msg_free(record);
next:
if (end)
break;
@@ -3918,8 +3918,8 @@ struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg)
exit:
return ndef;
err:
- free_ndef_message(ndef);
- free_ndef_message(record);
+ near_ndef_msg_free(ndef);
+ near_ndef_msg_free(record);
ndef = NULL;
goto exit;
}
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 12/16] snep-send: fix near_ndef_message memory leak
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (10 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 11/16] ndef: make freeing near_ndef_message reusable Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 13/16] unit: fix memory leaks in test-ndef-parse Krzysztof Kozlowski
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
The result of near_ndef_prepare_text_record() should be freed, otherwise
it leaks making ASAN and valgrind unhappy.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
tools/snep-send.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/snep-send.c b/tools/snep-send.c
index 5bb153210d30..53f53250b1ae 100644
--- a/tools/snep-send.c
+++ b/tools/snep-send.c
@@ -91,6 +91,7 @@ int main(int argc, char *argv[])
frame = g_try_malloc0(frame_length);
if (!frame) {
close(fd);
+ near_ndef_msg_free(ndef);
near_error("Could not allocate SNEP frame");
return -1;
}
@@ -100,6 +101,7 @@ int main(int argc, char *argv[])
frame->length = GUINT_TO_BE(ndef->length);
memcpy(frame->ndef, ndef->data, ndef->length);
+ near_ndef_msg_free(ndef);
len = send(fd, (uint8_t *)frame, frame_length, 0);
if (len < 0) {
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 13/16] unit: fix memory leaks in test-ndef-parse
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (11 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 12/16] snep-send: fix near_ndef_message memory leak Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 14/16] tag: do not open-code freeing ndef message Krzysztof Kozlowski
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
test-ndef-parse.c was not freeing fully the ndef records it got.
Replace the open-coded freeing with usage of near_ndef_records_free() to
solve libasan errors like:
Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x7f678a64b518 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
#1 0x557597045e89 in parse_sp_payload src/ndef.c:1468
#2 0x557597045e89 in near_ndef_parse_msg src/ndef.c:2921
and valgring errors like:
2 bytes in 1 blocks are definitely lost in loss record 2 of 52
at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
by 0x48E4B3D: g_strndup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
by 0x11C9F6: parse_record_header (ndef.c:1131)
by 0x11C9F6: parse_record_header (ndef.c:1038)
by 0x11E3D9: near_ndef_parse_msg (ndef.c:2855)
by 0x121E6B: test_ndef_uri (test-ndef-parse.c:213)
by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
by 0x10F61A: main (test-ndef-parse.c:467)
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
unit/test-ndef-parse.c | 39 +++++----------------------------------
1 file changed, 5 insertions(+), 34 deletions(-)
diff --git a/unit/test-ndef-parse.c b/unit/test-ndef-parse.c
index 0bc53eeac125..743bfa638d24 100644
--- a/unit/test-ndef-parse.c
+++ b/unit/test-ndef-parse.c
@@ -196,15 +196,6 @@ static uint8_t ho_hs_bt[] = {0x91, 0x02, 0x0A, 0x48, 0x73, 0x12, 0xD1, 0x02,
0x09, 0x44, 0x65, 0x79, 0x69, 0x63, 0x65, 0x4e,
0x61, 0x6d, 0x65};
-static void test_ndef_free_record(struct near_ndef_record *record)
-{
- g_free(record->header);
- g_free(record->type);
- g_free(record->data);
- g_free(record);
-
-}
-
static void test_ndef_uri(void)
{
GList *records;
@@ -229,9 +220,7 @@ static void test_ndef_uri(void)
if (g_test_verbose())
g_print("NDEF URI field: %s\n", record->uri->field);
- g_free(record->uri->field);
- g_free(record->uri);
- test_ndef_free_record(record);
+ near_ndef_records_free(records);
}
static void test_ndef_text_encoding(uint8_t *text, size_t len, const char *encoding, const char *expected)
@@ -262,11 +251,7 @@ static void test_ndef_text_encoding(uint8_t *text, size_t len, const char *encod
record->text->language_code);
}
- g_free(record->text->data);
- g_free(record->text->encoding);
- g_free(record->text->language_code);
- g_free(record->text);
- test_ndef_free_record(record);
+ near_ndef_records_free(records);
}
static void test_ndef_text(void)
@@ -318,10 +303,7 @@ static void test_ndef_single_sp(void)
g_print("NDEF SP URI field: %.*s\n", (int)uri->field_length,
(char *) uri->field);
- g_free(uri->field);
- g_free(uri);
- g_free(record->sp);
- test_ndef_free_record(record);
+ near_ndef_records_free(records);
}
static void test_ndef_title_sp(void)
@@ -372,16 +354,7 @@ static void test_ndef_title_sp(void)
g_print("NDEF SP Title Language: %s\n", text->language_code);
}
- g_free(uri->field);
- g_free(uri);
-
- g_free(text->data);
- g_free(text->encoding);
- g_free(text->language_code);
- g_free(text);
-
- g_free(record->sp);
- test_ndef_free_record(record);
+ near_ndef_records_free(records);
}
static void test_ndef_aar(void)
@@ -408,9 +381,7 @@ static void test_ndef_aar(void)
if (g_test_verbose())
g_print("NDEF AAR package: %s\n", record->aar->package);
- g_free(record->aar->package);
- g_free(record->aar);
- test_ndef_free_record(record);
+ near_ndef_records_free(records);
}
static void test_ndef_ho_hs_bt(void)
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 14/16] tag: do not open-code freeing ndef message
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (12 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 13/16] unit: fix memory leaks in test-ndef-parse Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 15/16] unit: " Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 16/16] ci: add build with sanitizers (asan, lsan and ubsan) Krzysztof Kozlowski
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Use near_ndef_msg_free() instead of open-coding it.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
src/tag.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/tag.c b/src/tag.c
index 520368b1552c..ce8c477d9527 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -459,14 +459,12 @@ static DBusMessage *write_ndef(DBusConnection *conn,
break;
default:
- g_free(ndef->data);
- g_free(ndef);
+ near_ndef_msg_free(ndef);
return __near_error_failed(msg, EOPNOTSUPP);
}
- g_free(ndef->data);
- g_free(ndef);
+ near_ndef_msg_free(ndef);
tag->write_ndef = ndef_with_header;
err = __near_tag_write(tag, ndef_with_header, write_cb);
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 15/16] unit: do not open-code freeing ndef message
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (13 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 14/16] tag: do not open-code freeing ndef message Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 16/16] ci: add build with sanitizers (asan, lsan and ubsan) Krzysztof Kozlowski
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Use near_ndef_msg_free() instead of open-coding it.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
unit/test-snep-read.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 414b801a5e71..0a2010a677e1 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -896,8 +896,7 @@ static void test_snep_response_put_get_ndef(gpointer context,
g_free(req);
g_free(resp);
- g_free(ndef->data);
- g_free(ndef);
+ near_ndef_msg_free(ndef);
}
int main(int argc, char **argv)
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [linux-nfc] [neard][PATCH 16/16] ci: add build with sanitizers (asan, lsan and ubsan)
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
` (14 preceding siblings ...)
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 15/16] unit: " Krzysztof Kozlowski
@ 2021-07-14 11:05 ` Krzysztof Kozlowski
15 siblings, 0 replies; 17+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-14 11:05 UTC (permalink / raw)
To: linux-nfc; +Cc: Krzysztof Kozlowski
Check the results if sanitizers were correctly linked.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
.github/workflows/ci.yml | 44 ++++++++++++++++++++++++++++++++++++++--
HACKING | 5 ++++-
ci/debian.sanitizers.sh | 18 ++++++++++++++++
ci/ubuntu.sanitizers.sh | 1 +
4 files changed, 65 insertions(+), 3 deletions(-)
create mode 100755 ci/debian.sanitizers.sh
create mode 120000 ci/ubuntu.sanitizers.sh
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 14cc4306de23..7c2eb3cb13f4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -66,6 +66,13 @@ jobs:
CC: gcc
MODE: maintainer
+ - container: "debian:stable"
+ env:
+ ARCH: x86-64
+ CC: gcc
+ VARIANT: sanitizers
+ MODE: maintainer
+
- container: "debian:stable"
env:
ARCH: x86-64
@@ -78,6 +85,13 @@ jobs:
CC: gcc
MODE: maintainer
+ - container: "debian:testing"
+ env:
+ ARCH: x86-64
+ CC: gcc
+ VARIANT: sanitizers
+ MODE: maintainer
+
- container: "debian:testing"
env:
ARCH: x86-64
@@ -153,6 +167,13 @@ jobs:
CC: gcc
MODE: maintainer
+ - container: "ubuntu:hirsute"
+ env:
+ ARCH: x86-64
+ CC: gcc
+ VARIANT: sanitizers
+ MODE: maintainer
+
- container: "ubuntu:hirsute"
env:
ARCH: x86-64
@@ -165,6 +186,13 @@ jobs:
CC: gcc
MODE: maintainer
+ - container: "ubuntu:focal"
+ env:
+ ARCH: x86-64
+ CC: gcc
+ VARIANT: sanitizers
+ MODE: maintainer
+
- container: "ubuntu:focal"
env:
ARCH: x86-64
@@ -235,9 +263,14 @@ jobs:
- name: Configure
run: |
echo "Bootstraping in mode: $MODE"
+ CONFIGURE_ARGS=""
+ if [ "$VARIANT" = "sanitizers" ]; then
+ CONFIGURE_ARGS="--enable-asan --enable-lsan --enable-ubsan --enable-pie"
+ fi
if [ "$MODE" = "maintainer" ]; then
./bootstrap-configure \
- --disable-silent-rules
+ --disable-silent-rules \
+ $CONFIGURE_ARGS
else
./bootstrap && \
./configure \
@@ -246,7 +279,8 @@ jobs:
--prefix=/usr \
--enable-ese \
--sysconfdir=/etc \
- --enable-tools
+ --enable-tools \
+ $CONFIGURE_ARGS
fi
- name: Compile
@@ -277,6 +311,12 @@ jobs:
esac
echo "Checking for built matching architecture: $ARCH_CHECK"
file src/neard | grep "$ARCH_CHECK"
+ if [ "$VARIANT" = "sanitizers" ]; then
+ echo "Checking for linking against sanitizer libraries"
+ ldd src/neard | grep libasan.so
+ # liblsan won't appear if asan is used
+ ldd src/neard | grep libubsan.so
+ fi
- name: Install
run: make install
diff --git a/HACKING b/HACKING
index 7326242506a6..40bde2fb3c8b 100644
--- a/HACKING
+++ b/HACKING
@@ -51,8 +51,11 @@ like this:
# git clone git://git.kernel.org/pub/scm/network/.../neard.git
# cd neard
- Configure and build
+ Configure (choose only one)
# ./bootstrap-configure
+ # ./bootstrap-configure --enable-asan --enable-lsan --enable-ubsan
+
+ Build
# make
Check installation
diff --git a/ci/debian.sanitizers.sh b/ci/debian.sanitizers.sh
new file mode 100755
index 000000000000..40dc1f44b55a
--- /dev/null
+++ b/ci/debian.sanitizers.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (c) 2021 Canonical Ltd.
+# Author: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
+# <krzk@kernel.org>
+#
+
+set -ex
+
+apt install -y --no-install-recommends \
+ liblsan0 \
+ libubsan1
+
+apt install -y --no-install-recommends libasan6 || \
+ apt install -y --no-install-recommends libasan5
+
+echo "Install finished: $0"
diff --git a/ci/ubuntu.sanitizers.sh b/ci/ubuntu.sanitizers.sh
new file mode 120000
index 000000000000..53cd9418ed35
--- /dev/null
+++ b/ci/ubuntu.sanitizers.sh
@@ -0,0 +1 @@
+debian.sanitizers.sh
\ No newline at end of file
--
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
^ permalink raw reply related [flat|nested] 17+ messages in thread
end of thread, other threads:[~2021-07-14 11:05 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 11:05 [linux-nfc] [neard][PATCH 00/16] -Wformat=2 and few memory leaks Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 01/16] gdbus: annotate printf-like functions as accepting format Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 02/16] nfctool: " Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 03/16] mifare: use unsigned int to suppress compiler -Wstrict-overflow Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 04/16] build: enable -Wformat=2 warnings Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 05/16] build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2 warnings Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 06/16] TODO: remove finished tasks Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 07/16] ci: build also on Ubuntu Hirsute in non-maintainer mode Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 08/16] ci: simplify getting test logs Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 09/16] build: fix missing usage of PIE check result Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 10/16] build: add support for GCC sanitizers (asan, lsan and ubsan) Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 11/16] ndef: make freeing near_ndef_message reusable Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 12/16] snep-send: fix near_ndef_message memory leak Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 13/16] unit: fix memory leaks in test-ndef-parse Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 14/16] tag: do not open-code freeing ndef message Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 15/16] unit: " Krzysztof Kozlowski
2021-07-14 11:05 ` [linux-nfc] [neard][PATCH 16/16] ci: add build with sanitizers (asan, lsan and ubsan) Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).