Skip to contentSkip to conversation

combined fixes - warnings, memory leaks, memory corruption

PATCH Applied Krzysztof Kozlowski 2 participants 80 messages Jul 19, 2021 – Aug 5, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover combined fixes - warnings, memory leaks, memory corruption

Hi,

Mark asked for resending fixes separate from setting up CI under Github Actions, so here is a combination of all my previously sent patches related only to the actual C code:

https://lore.kernel.org/linux-nfc/20210710033859.3989-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210714110518.104655-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210716100844.51360-1-krzysztof.kozlowski(a)canonical.com/T/#t

This includes fixes for GCC/clang warnings, memory leaks, memory corruption and few other minor fixes. The UTF-8 and UTF-16 is not entirely fixed and I removed the work-in-progress patches.

Changes since v1 are:
1. Group all patches based on prefix (unit file), instead of topic.
2. Put the build-related patches at the end.
3. Remove all CI-related patches.
4. Drop patch: ndef: fix parsing of UTF-16 text payload.
5. Fix commit msg in: nfctool: pass the format as string literal

Best regards,
Krzysztof

Krzysztof Kozlowski (73):
Drop empty NEWS
nfctool: fix adapter_get_devices() cast-function-type
nfctool: fix adapter_print_target() cast-function-type
nfctool: fix adapter_print_info() cast-function-type
nfctool: fix adapter_compare_idx() cast-function-type
nfctool: fix nfctool_send_dep_link_up() cast-function-type
nfctool: fix nfctool_print_and_remove_snl() cast-function-type
nfctool: use proper format for integers (-Wformat)
nfctool: pass the format as string literal
dbus: fix -Wformat in near_dbus_encode_string()
unit: pass real UTF-8 for testing text NDEF
ndef: check UTF-16 text payload length
ndef: silence clang -Wcast-align warning
ndef: use NDEF_TEXT_RECORD_UTF16_STATUS define
ndef: use proper format for integers (-Wformat)
ndef: make freeing near_ndef_message reusable
se: fix multiple apdu definitions
se: silence clang -Wcast-align warning
se: use proper format for integers (-Wformat)
adapter: adjust indentation of continued arguments
adapter: use proper format for integers (-Wformat)
gdbus: do not shadow global 'pending' variable (-Wshadow)
nciattach: fix poll.h include location
nciattach: do not shadow other local 'opt' variable (-Wshadow)
bluetooth: use proper format for integers (-Wformat)
nfctype2: use proper format for integers (-Wformat)
nfctype3: use proper format for integers (-Wformat)
nfctype5: use proper format for integers (-Wformat)
nfctype5: fix returning uninitialized stack value in

    t5_tag_is_ti_pro()

mifare: use proper format for integers (-Wformat)
mifare: use unsigned int to suppress compiler -Wstrict-overflow
p2p: use proper format for integers (-Wformat)
npp: use proper format for integers (-Wformat)
device: use proper format for integers (-Wformat)
manager: use proper format for integers (-Wformat)
netlink: use proper format for integers (-Wformat)
gdbus: annotate printf-like functions as accepting format
snep-send: fix near_ndef_message memory leak
tag: use proper format for integers (-Wformat)
tag: do not open-code freeing ndef message
snep: do not open-code freeing ndef message
snep: remove useless NULL-ify of local pointer variable
snep: fix double free of GSList
snep: fix fragmented response memory leaks
unit: use g_assert_cmpstr()
unit: use g_assert_cmpint() and g_assert_cmpuint()
unit: fix recv() and send() return types
unit: use g_assert_null()
unit: use g_assert_cmpmem()
unit: use proper pointer to uint8_t in test_snep_read_recv_fragments()
unit: do not shadow global 'text' variable (-Wshadow)
unit: do not shadow global 'uri' variable (-Wshadow)
unit: use proper format for integers (-Wformat)
unit: fix memory leaks in test-ndef-parse
unit: do not open-code freeing ndef message
unit: fix memory leaks in test-ndef-build
unit: fix memory leaks in test-snep-read error paths
unit: fix record memory leak in test-snep-read
unit: fix records GList memory leak in test-snep-read
unit: do not pass NULL to memcpy()
unit: do not search for headers locally where they do not exist
unit: remove duplicated invalid definitions in test-snep-read
unit: remove duplicated definitions in test-ndef-parse
unit: add few asserts in test-snep-read
HACKING: refine required packages
build: fix setting CFLAGS on dash shell (Alpine Linux)
build: add more compiler warnings
build: enable -Wshadow and -Wformat-signedness compiler warnings
build: enable -Wformat=2 warnings
build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2
warnings
build: fix missing usage of PIE check result
build: add support for GCC sanitizers (asan, lsan and ubsan)
AUTHORS: Mention Krzysztof Kozlowski's contributions

 AUTHORS                     |   1 +
 HACKING                     |  27 ++--
 Makefile.am                 |   2 +-
 NEWS                        |   0
 accflags.m4                 |  52 +++++++
 acinclude.m4                |  44 ++++--
 configure.ac                |  52 ++++++-
 gdbus/gdbus.h               |  15 +-
 gdbus/object.c              |  22 +--
 include/ndef.h              |   1 +
 plugins/mifare.c            |  14 +-
 plugins/nfctype2.c          |  12 +-
 plugins/nfctype3.c          |   2 +-
 plugins/nfctype5.c          |   8 +-
 plugins/npp.c               |   2 +-
 plugins/p2p.c               |   4 +-
 se/ace.c                    |  64 ++++++---
 se/apdu.c                   |   8 +-
 se/plugins/nfc.c            |   8 +-
 se/plugins/tizen.c          |   2 +-
 se/se.c                     |   6 +-
 se/seel.h                   |   2 +-
 src/adapter.c               |  41 +++---
 src/bluetooth.c             |   4 +-
 src/dbus.c                  |   2 +-
 src/device.c                |   6 +-
 src/manager.c               |   4 +-
 src/ndef-private.h          | 140 ++++++++++++++++++
 src/ndef.c                  | 217 ++++++----------------------
 src/netlink.c               |  16 +--
 src/snep.c                  |  14 +-
 src/tag.c                   |  14 +-
 tools/nciattach.c           |  10 +-
 tools/nfctool/adapter.c     |  20 +--
 tools/nfctool/adapter.h     |   2 +-
 tools/nfctool/llcp-decode.c |   4 +-
 tools/nfctool/main.c        |  30 ++--
 tools/nfctool/sniffer.c     |  10 +-
 tools/snep-send.c           |   2 +
 unit/test-ndef-build.c      |  24 ++--
 unit/test-ndef-parse.c      | 278 +++++++++++-------------------------
 unit/test-snep-read.c       | 117 ++++++++-------
 unit/test-utils.c           |   8 --
 unit/test-utils.h           |  83 +----------
 44 files changed, 691 insertions(+), 703 deletions(-)
 delete mode 100644 NEWS
 create mode 100644 accflags.m4
 create mode 100644 src/ndef-private.h
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 1/73 Drop empty NEWS

There are no news.

---
 NEWS | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 NEWS
NEWS deleted +0 -0
deleted file mode 100644
index e69de29bb2d1..000000000000
Signature · 1 line
2.27.0
#2 lore raw

PATCH v2 2/73 nfctool: fix adapter_get_devices() cast-function-type

In reply to Krzysztof Kozlowski

Fix on GCC v10:

tools/nfctool/adapter.c: In function ‘adapter_all_get_devices’:
tools/nfctool/adapter.c:55:28: error: cast between incompatible function types from ‘void (*)(struct nfc_adapter *)’ to ‘void (*)(void *, void *)’ [-Werror=cast-function-type]
55 | g_slist_foreach(adapters, (GFunc)adapter_get_devices, NULL);
| ^

---
 tools/nfctool/adapter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/nfctool/adapter.c +1 -1
index beaee53243ca..5a0c34a0f28b 100644
@@ -36,7 +36,7 @@ static GSList *adapters;
 
 static struct nfc_adapter *selected_adapter;
 
-static void adapter_get_devices(struct nfc_adapter *adapter)
+static void adapter_get_devices(struct nfc_adapter *adapter, gpointer user_data)
 {
 	if (adapter->rf_mode == NFC_RF_INITIATOR)
 		nl_get_targets(adapter);
Signature · 1 line
2.27.0
#3 lore raw

PATCH v2 3/73 nfctool: fix adapter_print_target() cast-function-type

In reply to Krzysztof Kozlowski

Fix on GCC v10:

tools/nfctool/adapter.c: In function ‘adpater_print_targets’:
tools/nfctool/adapter.c:69:33: error: cast between incompatible function types from ‘void (*)(guint32, gchar *)’ {aka ‘void (*)(unsigned int, char *)’} to ‘void (*)(void *, void *)’ [-Werror=cast-function-type]
69 | g_slist_foreach(adapter->tags, (GFunc)adapter_print_target, "tag");
| ^

---
 tools/nfctool/adapter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/nfctool/adapter.c +2 -2
index 5a0c34a0f28b..453c2c099009 100644
@@ -57,9 +57,9 @@ int adapter_all_get_devices(void)
 	return 0;
 }
 
-static void adapter_print_target(guint32 idx, gchar *type)
+static void adapter_print_target(gpointer idx, gchar *type)
 {
-	printf("%s%d ", type, idx);
+	printf("%s%d ", type, GPOINTER_TO_INT(idx));
 }
 
 void adpater_print_targets(struct nfc_adapter *adapter, gchar *prefix)
Signature · 1 line
2.27.0
#4 lore raw

PATCH v2 4/73 nfctool: fix adapter_print_info() cast-function-type

In reply to Krzysztof Kozlowski

Fix on GCC v10:

tools/nfctool/adapter.c: In function ‘adapter_idx_print_info’:
tools/nfctool/adapter.c:139:29: error: cast between incompatible function types from ‘void (*)(struct nfc_adapter *)’ to ‘void (*)(void *, void *)’ [-Werror=cast-function-type]
139 | g_slist_foreach(adapters, (GFunc)adapter_print_info, NULL);
| ^

---
 tools/nfctool/adapter.c | 4 ++--
 tools/nfctool/adapter.h | 2 +-
 tools/nfctool/main.c    | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
tools/nfctool/adapter.c +2 -2
index 453c2c099009..5e3bf41884d1 100644
@@ -78,7 +78,7 @@ void adpater_print_targets(struct nfc_adapter *adapter, gchar *prefix)
 	printf("]\n");
 }
 
-void adapter_print_info(struct nfc_adapter *adapter)
+void adapter_print_info(struct nfc_adapter *adapter, gpointer user_data)
 {
 	gchar *rf_mode_str;
 
@@ -134,7 +134,7 @@ void adapter_print_info(struct nfc_adapter *adapter)
 void adapter_idx_print_info(guint32 idx)
 {
 	if (idx != INVALID_ADAPTER_IDX)
-		adapter_print_info(adapter_get(idx));
+		adapter_print_info(adapter_get(idx), NULL);
 	else
 		g_slist_foreach(adapters, (GFunc)adapter_print_info, NULL);
 }
tools/nfctool/adapter.h +1 -1
index c22ded8ba34d..d2707ca1c107 100644
@@ -52,7 +52,7 @@ int adapter_all_get_devices(void);
 
 void adapter_idx_print_info(guint32 idx);
 
-void adapter_print_info(struct nfc_adapter *adapter);
+void adapter_print_info(struct nfc_adapter *adapter, gpointer user_data);
 
 void adpater_print_targets(struct nfc_adapter *adapter, gchar *prefix);
 
tools/nfctool/main.c +1 -1
index c9a236fe4122..c48bf0919657 100644
@@ -118,7 +118,7 @@ static int nfctool_set_params(void)
 
 	nl_get_params(adapter);
 
-	adapter_print_info(adapter);
+	adapter_print_info(adapter, NULL);
 
 exit:
 	return err;
Signature · 1 line
2.27.0
#5 lore raw

PATCH v2 5/73 nfctool: fix adapter_compare_idx() cast-function-type

In reply to Krzysztof Kozlowski

Fix on GCC v10:

tools/nfctool/adapter.c: In function ‘adapter_get’:
tools/nfctool/adapter.c:155:8: error: cast between incompatible function types from ‘gint (*)(struct nfc_adapter *, guint32)’ {aka ‘int (*)(struct nfc_adapter *, unsigned int)’} to ‘gint (*)(const void *, const void *)’ {aka ‘int (*)(const void *, const void *)’} [-Werror=cast-function-type]
155 | (GCompareFunc)adapter_compare_idx);
| ^

---
 tools/nfctool/adapter.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/nfctool/adapter.c +4 -2
index 5e3bf41884d1..343c4ab7d0ff 100644
@@ -139,9 +139,11 @@ void adapter_idx_print_info(guint32 idx)
 		g_slist_foreach(adapters, (GFunc)adapter_print_info, NULL);
 }
 
-static gint adapter_compare_idx(struct nfc_adapter *adapter, guint32 idx)
+static gint adapter_compare_idx(struct nfc_adapter *adapter, gpointer idx_ptr)
 {
-	return (gint)adapter->idx - (gint)idx;
+	gint idx = GPOINTER_TO_INT(idx_ptr);
+
+	return (gint)adapter->idx - idx;
 }
 
 struct nfc_adapter *adapter_get(guint32 idx)
Signature · 1 line
2.27.0
#6 lore raw

PATCH v2 6/73 nfctool: fix nfctool_send_dep_link_up() cast-function-type

In reply to Krzysztof Kozlowski

Fix on GCC v10:

tools/nfctool/main.c: In function ‘nfctool_targets_found’:
tools/nfctool/main.c:294:5: error: cast between incompatible function types from ‘void (*)(guint32, guint32)’ {aka ‘void (*)(unsigned int, unsigned int)’} to ‘void (*)(void *, void *)’ [-Werror=cast-function-type]
294 | (GFunc)nfctool_send_dep_link_up,
| ^

---
 tools/nfctool/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/nfctool/main.c +2 -2
index c48bf0919657..282df519fcc8 100644
@@ -259,9 +259,9 @@ static int nfctool_snl(void)
 	return nfctool_snl_send_request(adapter);
 }
 
-static void nfctool_send_dep_link_up(guint32 target_idx, guint32 adapter_idx)
+static void nfctool_send_dep_link_up(gpointer target_idx, gpointer adapter_idx)
 {
-	nl_send_dep_link_up(adapter_idx, target_idx);
+	nl_send_dep_link_up(GPOINTER_TO_INT(adapter_idx), GPOINTER_TO_INT(target_idx));
 }
 
 static int nfctool_targets_found(guint32 adapter_idx)
Signature · 1 line
2.27.0
#7 lore raw

PATCH v2 7/73 nfctool: fix nfctool_print_and_remove_snl() cast-function-type

In reply to Krzysztof Kozlowski

Fix on GCC v10:

tools/nfctool/main.c: In function ‘nfctool_snl_cb’:
tools/nfctool/main.c:352:30: error: cast between incompatible function types from ‘void (*)(struct nfc_snl *, guint32)’ {aka ‘void (*)(struct nfc_snl *, unsigned int)’} to ‘void (*)(void *, void *)’ [-Werror=cast-function-type]
352 | g_slist_foreach(sdres_list, (GFunc)nfctool_print_and_remove_snl,
| ^

---
 tools/nfctool/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/nfctool/main.c +2 -2
index 282df519fcc8..72a39de3ccbf 100644
@@ -325,13 +325,13 @@ static int nfctool_poll_cb(guint8 cmd, guint32 idx, gpointer data)
 }
 
 static void nfctool_print_and_remove_snl(struct nfc_snl *sdres,
-					 guint32 adapter_idx)
+					 gpointer adapter_idx)
 {
 	GSList *elem;
 
 	printf(" uri: %s - sap: %d\n", sdres->uri, sdres->sap);
 
-	if (adapter_idx == opts.adapter_idx) {
+	if (GPOINTER_TO_UINT(adapter_idx) == opts.adapter_idx) {
 		elem = g_slist_find_custom(opts.snl_list, sdres->uri,
 					   (GCompareFunc)g_strcmp0);
 
Signature · 1 line
2.27.0
#8 lore raw

PATCH v2 8/73 nfctool: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print igned and nsigned integers. This fixes warnings like:

In file included from tools/nfctool/main.c:37:
tools/nfctool/main.c: In function ‘nfctool_start_poll’:
tools/nfctool/main.c:73:15: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘guint32’ {aka ‘unsigned int’} [-Werror=format=]
73 | print_error("Invalid adapter index: %d", opts.adapter_idx);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
| |
| guint32 {aka unsigned int}
tools/nfctool/llcp-decode.c: In function ‘llcp_print_params’:
tools/nfctool/llcp-decode.c:276:27: error: format ‘%X’ expects argument of type ‘unsigned int’, but argument 3 has type ‘int’ [-Werror=format=]
276 | sprintf(param_str, "0x%X", param[2] & 0x03);
| ~^ ~~~~~~~~~~~~~~~
| | |
| unsigned int int
| %X
tools/nfctool/llcp-decode.c: In function ‘llcp_print_pdu’:
tools/nfctool/llcp-decode.c:553:27: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__time_t’ {aka ‘long int’} [-Werror=format=]
553 | sprintf(time_str, "%c%lu.%06lus", prefix, msg_timestamp.tv_sec,
| ~~^ ~~~~~~~~~~~~~~~~~~~~
| | |
| long unsigned int __time_t {aka long int}
| %lu

---
 tools/nfctool/adapter.c     |  4 ++--
 tools/nfctool/llcp-decode.c |  4 ++--
 tools/nfctool/main.c        | 20 ++++++++++----------
 tools/nfctool/sniffer.c     |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)
tools/nfctool/adapter.c +2 -2
index 343c4ab7d0ff..5e076782e373 100644
@@ -85,7 +85,7 @@ void adapter_print_info(struct nfc_adapter *adapter, gpointer user_data)
 	if (!adapter)
 		return;
 
-	printf("nfc%d:\n", adapter->idx);
+	printf("nfc%u:\n", adapter->idx);
 
 	adpater_print_targets(adapter, "          ");
 
@@ -164,7 +164,7 @@ struct nfc_adapter *adapter_get(guint32 idx)
 
 void adapter_add_target(struct nfc_adapter *adapter, guint8 type, guint32 idx)
 {
-	DBG("adapter_idx: %d, target_type: %d, target_idx: %d",
+	DBG("adapter_idx: %u, target_type: %u, target_idx: %u",
 	    adapter->idx, type, idx);
 
 	if (type == TARGET_TYPE_TAG)
tools/nfctool/llcp-decode.c +2 -2
index 13e7ba759218..3aa222f0f39e 100644
@@ -273,7 +273,7 @@ static void llcp_print_params(struct sniffer_packet *packet)
 			break;
 
 		case LLCP_PARAM_OPT:
-			sprintf(param_str, "0x%X", param[2] & 0x03);
+			sprintf(param_str, "0x%X", (unsigned int)param[2] & 0x03);
 			break;
 
 		case LLCP_PARAM_SDREQ:
@@ -550,7 +550,7 @@ int llcp_print_pdu(guint8 *data, guint32 data_len, struct timeval *timestamp)
 			prefix = '+';
 		}
 
-		sprintf(time_str,  "%c%lu.%06lus", prefix, msg_timestamp.tv_sec,
+		sprintf(time_str,  "%c%ld.%06lds", prefix, msg_timestamp.tv_sec,
 							msg_timestamp.tv_usec);
 	}
 
tools/nfctool/main.c +10 -10
index 72a39de3ccbf..65a0c15a9465 100644
@@ -70,7 +70,7 @@ static int nfctool_start_poll(void)
 	adapter = adapter_get(opts.adapter_idx);
 
 	if (!adapter) {
-		print_error("Invalid adapter index: %d", opts.adapter_idx);
+		print_error("Invalid adapter index: %u", opts.adapter_idx);
 
 		return -ENODEV;
 	}
@@ -81,7 +81,7 @@ static int nfctool_start_poll(void)
 	err = nl_start_poll(adapter, opts.poll_mode);
 
 	if (err == 0) {
-		printf("Start polling on nfc%d as %s\n\n",
+		printf("Start polling on nfc%u as %s\n\n",
 			adapter->idx, nfctool_poll_mode_str(opts.poll_mode));
 		return 0;
 	}
@@ -90,9 +90,9 @@ static int nfctool_start_poll(void)
 		return err;
 
 	if (adapter->rf_mode == NFC_RF_NONE)
-		printf("nfc%d already in polling mode\n\n", adapter->idx);
+		printf("nfc%u already in polling mode\n\n", adapter->idx);
 	else
-		printf("nfc%d already activated\n\n", adapter->idx);
+		printf("nfc%u already activated\n\n", adapter->idx);
 
 	/* Don't fail if there is a pending SNL request */
 	if (opts.snl)
@@ -201,7 +201,7 @@ static int nfctool_dep_link_up_cb(guint8 cmd, guint32 idx, gpointer data)
 {
 	struct nfc_adapter *adapter;
 
-	printf("Link is UP for adapter nfc%d\n\n", idx);
+	printf("Link is UP for adapter nfc%u\n\n", idx);
 
 	if (idx != opts.adapter_idx)
 		return -ENODEV;
@@ -220,7 +220,7 @@ static int nfctool_dep_link_down_cb(guint8 cmd, guint32 idx, gpointer data)
 	if (idx != opts.adapter_idx)
 		return -ENODEV;
 
-	printf("Link is DOWN for adapter nfc%d\n\n", idx);
+	printf("Link is DOWN for adapter nfc%u\n\n", idx);
 
 	opts.snl = false;
 
@@ -269,7 +269,7 @@ static int nfctool_targets_found(guint32 adapter_idx)
 	int err;
 	struct nfc_adapter *adapter;
 
-	DBG("adapter_idx: %d", adapter_idx);
+	DBG("adapter_idx: %u", adapter_idx);
 
 	if (adapter_idx == INVALID_ADAPTER_IDX)
 		return -ENODEV;
@@ -285,7 +285,7 @@ static int nfctool_targets_found(guint32 adapter_idx)
 		goto exit;
 	}
 
-	printf("Targets found for nfc%d\n", adapter_idx);
+	printf("Targets found for nfc%u\n", adapter_idx);
 	adpater_print_targets(adapter, "  ");
 	printf("\n");
 
@@ -308,7 +308,7 @@ static int nfctool_poll_cb(guint8 cmd, guint32 idx, gpointer data)
 	if (idx != opts.adapter_idx)
 		return 0;
 
-	DBG("cmd: %d, idx: %d", cmd, idx);
+	DBG("cmd: %u, idx: %u", cmd, idx);
 
 	switch (cmd) {
 	case NFC_EVENT_TARGETS_FOUND:
@@ -347,7 +347,7 @@ static int nfctool_snl_cb(guint8 cmd, guint32 idx, gpointer data)
 {
 	GSList *sdres_list = (GSList *)data;
 
-	printf("nfc%d: Service Name lookup:\n", idx);
+	printf("nfc%u: Service Name lookup:\n", idx);
 
 	g_slist_foreach(sdres_list, (GFunc)nfctool_print_and_remove_snl,
 			GINT_TO_POINTER(idx));
tools/nfctool/sniffer.c +1 -1
index 71ac612ea924..3d1d230a50c5 100644
@@ -369,7 +369,7 @@ int sniffer_init(void)
 	if (err)
 		goto exit;
 
-	printf("Start sniffer on nfc%d\n\n", opts.adapter_idx);
+	printf("Start sniffer on nfc%u\n\n", opts.adapter_idx);
 
 exit:
 	if (err)
Signature · 1 line
2.27.0
#9 lore raw

PATCH v2 9/73 nfctool: pass the format as string literal

In reply to Krzysztof Kozlowski

clang v11 has troubles detecting that sprintf() format is passed in sniffer_print_hexdump() as string literal. Remove the local "fmt" variable and call sprintf() in two branches of if, to satisfy clang and fix warnings like:

    tools/nfctool/sniffer.c:206:18: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
                        sprintf(line, fmt, offset);
                                      ^~~
---
 tools/nfctool/sniffer.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/nfctool/sniffer.c +4 -4
index 3d1d230a50c5..6a38a213c74d 100644
@@ -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;
 
Signature · 1 line
2.27.0
#10 lore raw

PATCH v2 10/73 dbus: fix -Wformat in near_dbus_encode_string()

In reply to Krzysztof Kozlowski

Fix GCC warning:

src/dbus.c: In function ‘near_dbus_encode_string’:
src/dbus.c:71:37: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘int’ [-Werror=format=]
71 | g_string_append_printf(str, "_%02x", tmp);
| ~~~^ ~~~
| | |
| | int
| unsigned int
| %02x

---
 src/dbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/dbus.c +1 -1
index 9c67a9eec89a..ed4570d951ed 100644
@@ -68,7 +68,7 @@ char *near_dbus_encode_string(const char *value)
 		const char tmp = value[i];
 		if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
 						(tmp < 'a' || tmp > 'z'))
-			g_string_append_printf(str, "_%02x", tmp);
+			g_string_append_printf(str, "_%02x", (unsigned int)tmp);
 		else
 			str = g_string_append_c(str, tmp);
 	}
Signature · 1 line
2.27.0
#11 lore raw

PATCH v2 11/73 unit: pass real UTF-8 for testing text NDEF

In reply to Krzysztof Kozlowski

Let's polish this UTF-8. :)

---
 unit/test-ndef-parse.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
unit/test-ndef-parse.c +5 -4
index 8cfdc8f2cb9d..d26f4c595d9a 100644
@@ -145,9 +145,10 @@ struct near_ndef_ac_payload {
 static uint8_t uri[] = {0xd1, 0x1, 0xa, 0x55, 0x1, 0x69, 0x6e, 0x74,
 			0x65, 0x6c, 0x2e, 0x63, 0x6f, 0x6d};
 
-/* 'hello' - UTF-8 - en-US Text NDEF */
-static uint8_t text[] = {0xd1, 0x1, 0xb, 0x54, 0x5,  0x65, 0x6e, 0x2d,
-			 0x55, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x6f};
+/* 'hello żółw' - UTF-8 - en-US Text NDEF */
+static uint8_t text[] = {0xd1, 0x1, 0x13, 0x54, 0x5, 0x65, 0x6e, 0x2d,
+			 0x55, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0xc5,
+			 0xbc, 0xc3, 0xb3, 0xc5, 0x82, 0x77};
 
 /* Smart poster with a http://intel.com URI record */
 static uint8_t single_sp[] = {0xd1, 0x2, 0xe, 0x53, 0x70, 0xd1, 0x1, 0xa,
@@ -234,7 +235,7 @@ static void test_ndef_text(void)
 	g_assert(record->header->me == 1);
 
 	g_assert(record->text);
-	g_assert(strcmp(record->text->data, "hello") == 0);
+	g_assert(strcmp(record->text->data, "hello żółw") == 0);
 	g_assert(strcmp(record->text->encoding, "UTF-8") == 0);
 	g_assert(strcmp(record->text->language_code, "en-US") == 0);
 
Signature · 1 line
2.27.0
#12 lore raw

PATCH v2 12/73 ndef: check UTF-16 text payload length

In reply to Krzysztof Kozlowski

UTF-16 is supposed to be consisting of 16-bit codes (16-bit or 2x16-bit per character) and parsing anything else is not safe because of cast to gunichar2.

---
 src/ndef.c             |  5 +++++
 unit/test-ndef-parse.c | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)
src/ndef.c +5 -0
index 3d8815634d46..fdd44b467027 100644
@@ -1189,6 +1189,11 @@ parse_text_payload(uint8_t *payload, uint32_t length)
 
 	len = length - lang_length - 1;
 
+	if (status && (len % 2)) {
+		DBG("Payload not valid UTF-16 (length %d does not match)", len);
+		goto fail;
+	}
+
 	if (len > 0) {
 		txt = (char *)(payload + offset);
 
unit/test-ndef-parse.c +19 -0
index d26f4c595d9a..6c62c7a928c7 100644
@@ -150,6 +150,15 @@ static uint8_t text[] = {0xd1, 0x1, 0x13, 0x54, 0x5, 0x65, 0x6e, 0x2d,
 			 0x55, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0xc5,
 			 0xbc, 0xc3, 0xb3, 0xc5, 0x82, 0x77};
 
+/* 'hello żółw' - UTF-16 - en-US Text NDEF UTF-16 malformed*/
+static uint8_t text_utf16_invalid[] = {0xd1, 0x1, 0x19, 0x54, 0x85,
+			/* en-US */
+			0x65, 0x6e, 0x2d, 0x55, 0x53,
+			/* hello żółw */
+			0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00,
+			/* Missing last byte */
+			0x20, 0x00, 0x7c, 0x01, 0xf3, 0x00, 0x42, 0x01, 0x77};
+
 /* Smart poster with a http://intel.com URI record */
 static uint8_t single_sp[] = {0xd1, 0x2, 0xe, 0x53, 0x70, 0xd1, 0x1, 0xa,
 			      0x55, 0x3, 0x69, 0x6e, 0x74, 0x65, 0x6c, 0x2e,
@@ -253,6 +262,15 @@ static void test_ndef_text(void)
 	test_ndef_free_record(record);
 }
 
+static void test_ndef_text_invalid_utf16(void)
+{
+	GList *records;
+
+	records = near_ndef_parse_msg(text_utf16_invalid, sizeof(text_utf16_invalid), NULL);
+
+	g_assert_null(records);
+}
+
 static void test_ndef_single_sp(void)
 {
 	GList *records;
@@ -422,6 +440,7 @@ int main(int argc, char **argv)
 
 	g_test_add_func("/testNDEF-parse/Test URI NDEF", test_ndef_uri);
 	g_test_add_func("/testNDEF-parse/Test Text NDEF", test_ndef_text);
+	g_test_add_func("/testNDEF-parse/Test Text NDEF UTF-16 malformed", test_ndef_text_invalid_utf16);
 	g_test_add_func("/testNDEF-parse/Test Single record SmartPoster NDEF",
 							test_ndef_single_sp);
 	g_test_add_func("/testNDEF-parse/Test Title record SmartPoster NDEF",
Signature · 1 line
2.27.0
#13 lore raw

PATCH v2 13/73 ndef: silence clang -Wcast-align warning

In reply to Krzysztof Kozlowski

Fix clang warning:

    src/ndef.c:1196:28: error: cast from 'char *' to 'gunichar2 *' (aka 'unsigned short *') increases required alignment from 1 to 2 [-Werror,-Wcast-align]
                            g_str = g_utf16_to_utf8((gunichar2 *)txt, len, NULL,
                                                    ^~~~~~~~~~~~~~~~

The case is safe as length of string is an even number.

---
 src/ndef.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/ndef.c +2 -1
index fdd44b467027..13e3356c2c4c 100644
@@ -1198,7 +1198,8 @@ parse_text_payload(uint8_t *payload, uint32_t length)
 		txt = (char *)(payload + offset);
 
 		if (status)
-			g_str = g_utf16_to_utf8((gunichar2 *)txt, len, NULL,
+			/* Cast to void to silence the 1-to-2 alignment warning */
+			g_str = g_utf16_to_utf8((gunichar2 *)(void *)txt, len, NULL,
 						NULL, NULL);
 		else
 			g_str = txt;
Signature · 1 line
2.27.0
#14 lore raw

PATCH v2 14/73 ndef: use NDEF_TEXT_RECORD_UTF16_STATUS define

In reply to Krzysztof Kozlowski

Don't hard-code 0x80 because there is a define for it. No functional change.

---
 src/ndef.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/ndef.c +2 -2
index 13e3356c2c4c..928e6a10a999 100644
@@ -1164,8 +1164,8 @@ parse_text_payload(uint8_t *payload, uint32_t length)
 	if (!text_payload)
 		return NULL;
 
-	/* 0x80 is used to get 7th bit value (0th bit is LSB) */
-	status = ((payload[offset] & 0x80) >> 7);
+	/* 0th bit is LSB */
+	status = ((payload[offset] & NDEF_TEXT_RECORD_UTF16_STATUS) >> 7);
 
 	text_payload->encoding = (status == 0) ?
 					g_strdup("UTF-8") : g_strdup("UTF-16");
Signature · 1 line
2.27.0
#15 lore raw

PATCH v2 15/73 ndef: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    ./include/near/log.h:45:14: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~
    src/ndef.c:1084:2: note: in expansion of macro ‘DBG’
     1084 |  DBG("payload length %d", rec_header->payload_len);
          |  ^~~
---
 src/ndef.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
src/ndef.c +6 -6
index 928e6a10a999..790655a279ba 100644
@@ -503,8 +503,8 @@ static gboolean property_get_uri(const GDBusPropertyTable *property,
 
 	DBG("URI prefix %s", prefix);
 
-	value = g_strdup_printf("%s%.*s", prefix, uri->field_length,
-							 uri->field);
+	value = g_strdup_printf("%s%.*s", prefix, (int)uri->field_length,
+				uri->field);
 
 	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &value);
 
@@ -585,7 +585,7 @@ static gboolean property_get_size(const GDBusPropertyTable *property,
 {
 	struct near_ndef_record *record = user_data;
 
-	DBG("%d", record->sp->size);
+	DBG("%u", record->sp->size);
 
 	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &record->sp->size);
 
@@ -1042,7 +1042,7 @@ static struct near_ndef_record_header *parse_record_header(uint8_t *rec,
 	uint8_t *type = NULL;
 	uint32_t header_len = 0;
 
-	DBG("length %d", length);
+	DBG("length %u", length);
 
 	if (!rec || offset >= length)
 		return NULL;
@@ -1081,7 +1081,7 @@ static struct near_ndef_record_header *parse_record_header(uint8_t *rec,
 			goto fail;
 	}
 
-	DBG("payload length %d", rec_header->payload_len);
+	DBG("payload length %u", rec_header->payload_len);
 
 	if (rec_header->il == 1) {
 		rec_header->il_length = rec[offset++];
@@ -1274,7 +1274,7 @@ parse_uri_payload(uint8_t *payload, uint32_t length)
 	}
 
 	DBG("Identifier  '0X%X'", uri_payload->identifier);
-	DBG("Field  '%.*s'", uri_payload->field_length, uri_payload->field);
+	DBG("Field  '%.*s'", (int)uri_payload->field_length, uri_payload->field);
 
 	return uri_payload;
 
Signature · 1 line
2.27.0
#16 lore raw

PATCH v2 16/73 ndef: make freeing near_ndef_message reusable

In reply to 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.

---
 include/ndef.h |  1 +
 src/ndef.c     | 56 +++++++++++++++++++++++++-------------------------
 2 files changed, 29 insertions(+), 28 deletions(-)
include/ndef.h +1 -0
index 5abdf343ee07..a21eed2654e9 100644
@@ -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);
src/ndef.c +28 -28

150 lines not on this page · raw message

Signature · 1 line
2.27.0
#17 lore raw

PATCH v2 17/73 se: fix multiple apdu definitions

In reply to Krzysztof Kozlowski

Fixes:

/usr/bin/ld: se/seeld-manager.o:se/seel.h:31: multiple definition of apdu'; se/seeld-main.o:se/seel.h:31: first defined here /usr/bin/ld: se/seeld-se.o:se/seel.h:31: multiple definition of apdu'; se/seeld-main.o:se/seel.h:31: first defined here /usr/bin/ld: se/seeld-driver.o:se/seel.h:31: multiple definition of apdu'; se/seeld-main.o:se/seel.h:31: first defined here /usr/bin/ld: se/seeld-apdu.o:se/seel.h:31: multiple definition of apdu'; se/seeld-main.o:se/seel.h:31: first defined here /usr/bin/ld: se/seeld-channel.o:se/seel.h:31: multiple definition of apdu'; se/seeld-main.o:se/seel.h:31: first defined here /usr/bin/ld: se/seeld-ace.o:se/seel.h:31: multiple definition of apdu'; se/seeld-main.o:se/seel.h:31: first defined here

---
 se/seel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
se/seel.h +1 -1
index 24cd0011ffb7..ea89e1519764 100644
@@ -28,7 +28,7 @@
 struct seel_se;
 struct seel_channel;
 struct seel_ace;
-struct seel_apdu *apdu;
+struct seel_apdu;
 
 int __seel_manager_init(DBusConnection *conn);
 void __seel_manager_cleanup(void);
Signature · 1 line
2.27.0
#18 lore raw

PATCH v2 18/73 se: silence clang -Wcast-align warning

In reply to Krzysztof Kozlowski

Fix clang warnings:

    se/ace.c:147:15: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'struct seel_ace_apdu_rule *' increases required alignment from 1 to 4 [-Werror,-Wcast-align]
                    apdu_rule = (struct seel_ace_apdu_rule *)rule->apdu_rules;
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    se/ace.c:790:18: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
            apdu_header = *((uint32_t *) apdu);
                            ^~~~~~~~~~~~~~~~~
    se/ace.c:791:14: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'struct seel_ace_apdu_rule *' increases required alignment from 1 to 4 [-Werror,-Wcast-align]
            apdu_rule = (struct seel_ace_apdu_rule *)rule->apdu_rules;
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Increasing alignment should be fine for most of the platforms (maybe except some performance penalty), although there are such which might not handle it and raise CPU exception. I am not sure whether the code is actually safe, but proper fixing would require bigger changes.

---
 se/ace.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
se/ace.c +27 -3
index c1561abae8c1..ef0e7e15fbf7 100644
@@ -144,7 +144,18 @@ static void dump_rule(gpointer data, gpointer user_data)
 		uint8_t *header, *mask;
 		size_t n_rules;
 
-		apdu_rule = (struct seel_ace_apdu_rule *)rule->apdu_rules;
+		/*
+		 * (void *) to silence -Wcast-align. Code should be safe
+		 * (assuming platform handles unaliagned access) as iterations
+		 * go up to n_rules.
+		 *
+		 * TODO: Fix the problem instead of silencing with cast, so
+		 * the code would be porable.
+		 */
+		if (rule->apdu_rules_len % sizeof(struct seel_ace_apdu_rule *)) {
+			DBG("  APDU: wrong alignment (Bug, code needs fixing)");
+		}
+		apdu_rule = (struct seel_ace_apdu_rule *)(void *)rule->apdu_rules;
 		n_rules = rule->apdu_rules_len /
 				sizeof(struct seel_ace_apdu_rule);
 
@@ -787,8 +798,21 @@ static bool apdu_allowed(struct seel_ace_rule *rule,
 
 	n_rules = rule->apdu_rules_len /
 				sizeof(struct seel_ace_apdu_rule);
-	apdu_header = *((uint32_t *) apdu);
-	apdu_rule = (struct seel_ace_apdu_rule *)rule->apdu_rules;
+	/*
+	 * FIXME: apdu comes from message and where is checking for apdu_len?
+	 * The (void *) is to fix -Wcast-align but the actual problem is
+	 * whether the apdu contains enough of data.
+	 */
+	apdu_header = *((uint32_t *)(void *) apdu);
+	/*
+	 * (void *) to silence -Wcast-align. Code should be safe
+	 * (assuming platform handles unaliagned access) as iterations
+	 * go up to n_rules.
+	 *
+	 * TODO: Fix the problem instead of silencing with cast, so
+	 * the code would be porable.
+	 */
+	apdu_rule = (struct seel_ace_apdu_rule *)(void *)rule->apdu_rules;
 
 	for (i = 0; i < n_rules; i++) {
 		if ((apdu_header & apdu_rule->mask) == apdu_rule->header)
Signature · 1 line
2.27.0
#19 lore raw

PATCH v2 19/73 se: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    In file included from se/plugins/nfc.c:37:
    se/plugins/nfc.c: In function ‘nfc_netlink_event_se’:
    ./include/near/log.h:45:14: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~
    se/plugins/nfc.c:200:2: note: in expansion of macro ‘DBG’
      200 |  DBG("NFC %d SE %d", nfc_idx, se_idx);
          |  ^~~

    se/plugins/nfc.c:270:2: note: in expansion of macro ‘DBG’
      270 |  DBG("NFC %d SE %d APDU len %zd", nfc_idx, se_idx, apdu_len);
          |  ^~~
    ./include/near/log.h:45:14: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 6 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~

    In file included from se/../src/near.h:36,
                     from se/seel.h:29,
                     from se/se.c:34:
    se/se.c: In function ‘io_cb’:
    ./include/near/log.h:45:14: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~
    se/se.c:119:2: note: in expansion of macro ‘DBG’
      119 |  DBG("%zd %d", apdu_length, err);
          |  ^~~
    se/se.c: In function ‘se_path’:
    se/se.c:250:43: error: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
      250 |  return g_strdup_printf("%s/se/%s%d_%s_se%d", SEEL_PATH,
          |                                          ~^
          |                                           |
          |                                           int
          |                                          %d
      251 |      ctrl, ctrl_idx, type, se_idx);
          |                            ~~~~~~
          |                            |
          |                            uint32_t {aka unsigned int}
---
 se/ace.c           | 34 +++++++++++++++++-----------------
 se/apdu.c          |  8 ++++----
 se/plugins/nfc.c   |  8 ++++----
 se/plugins/tizen.c |  2 +-
 se/se.c            |  6 +++---
 5 files changed, 29 insertions(+), 29 deletions(-)
se/ace.c +17 -17
index ef0e7e15fbf7..f8d492f423af 100644
@@ -126,7 +126,7 @@ static void dump_rule(gpointer data, gpointer user_data)
 		for (i = 0; i < rule->aid_len; i++)
 			sprintf(aid + (3 * i), "%02X ", rule->aid[i]);
 		aid[3 * i] = 0;
-		DBG("  AID [%zd]: %s", rule->aid_len, aid);
+		DBG("  AID [%zu]: %s", rule->aid_len, aid);
 	}
 
 	if (rule->hash_len == 0) {
@@ -135,7 +135,7 @@ static void dump_rule(gpointer data, gpointer user_data)
 		for (i = 0; i < rule->hash_len; i++)
 			sprintf(hash + (3 * i), "%02X ", rule->hash[i]);
 		hash[3 * i] = 0;
-		DBG("  Hash [%zd]: %s", rule->hash_len, hash);
+		DBG("  Hash [%zu]: %s", rule->hash_len, hash);
 	}
 
 	if (rule->apdu_rules_len == 1) {
@@ -159,7 +159,7 @@ static void dump_rule(gpointer data, gpointer user_data)
 		n_rules = rule->apdu_rules_len /
 				sizeof(struct seel_ace_apdu_rule);
 
-		DBG("  APDU rules (%zd)", n_rules);
+		DBG("  APDU rules (%zu)", n_rules);
 		for (i = 0; i < n_rules; i++) {
 			header = (uint8_t *)&apdu_rule->header;
 			mask = (uint8_t *)&apdu_rule->mask;
@@ -197,7 +197,7 @@ static int build_ref(struct seel_ace_rule *ace_rule,
 		switch (rule_ptr[0]) {
 		case AID_REF_DO:
 			do_length = rule_ptr[1];
-			DBG("AID_REF_DO %zd", do_length);
+			DBG("AID_REF_DO %zu", do_length);
 			rule_ptr += 2;
 
 			if (remaining < do_length)
@@ -216,7 +216,7 @@ static int build_ref(struct seel_ace_rule *ace_rule,
 
 		case HASH_REF_DO:
 			do_length = rule_ptr[1];
-			DBG("HASH_REF_DO %zd", do_length);
+			DBG("HASH_REF_DO %zu", do_length);
 			rule_ptr += 2;
 
 			if (remaining < do_length)
@@ -254,7 +254,7 @@ static int build_ar(struct seel_ace_rule *ace_rule,
 		switch (rule_ptr[0]) {
 		case APDU_AR_DO:
 			do_length = rule_ptr[1];
-			DBG("APDU_AR_DO %zd", do_length);
+			DBG("APDU_AR_DO %zu", do_length);
 			rule_ptr += 2;
 
 			if (remaining < do_length)
@@ -274,7 +274,7 @@ static int build_ar(struct seel_ace_rule *ace_rule,
 
 		case NFC_AR_DO:
 			do_length = rule_ptr[1];
-			DBG("NFC_AR_DO %zd", do_length);
+			DBG("NFC_AR_DO %zu", do_length);
 			rule_ptr += 2;
 
 			if (do_length != 1)
@@ -316,7 +316,7 @@ static struct seel_ace_rule *build_rule(struct seel_ace *ace,
 		switch (rule_ptr[0]) {
 		case REF_DO:
 			do_length = rule_ptr[1];
-			DBG("REF_DO %zd", do_length);
+			DBG("REF_DO %zu", do_length);
 			rule_ptr += 2;
 
 			err = build_ref(ace_rule, rule_ptr, do_length);
@@ -330,7 +330,7 @@ static struct seel_ace_rule *build_rule(struct seel_ace *ace,
 
 		case AR_DO:
 			do_length = rule_ptr[1];
-			DBG("AR_DO %zd", do_length);
+			DBG("AR_DO %zu", do_length);
 			rule_ptr += 2;
 
 			err = build_ar(ace_rule, rule_ptr, do_length);
@@ -378,7 +378,7 @@ static int build_ace_rules(struct seel_ace *ace,
 		remaining -= ref_ar_do_length + 2;
 		rule_ptr += 2;
 
-		DBG("REF_AR_DO %zd bytes", ref_ar_do_length);
+		DBG("REF_AR_DO %zu bytes", ref_ar_do_length);
 
 		rule = build_rule(ace, rule_ptr, ref_ar_do_length);
 		if (!rule) {
@@ -412,7 +412,7 @@ static int ace_rule_length(uint8_t *apdu, size_t apdu_length,
 	if (length & 0x80) {
 		size_t _length = length & 0x7f, i, base;
 
-		DBG("%zd", _length);
+		DBG("%zu", _length);
 
 		if (apdu_length < 3 + _length)
 			return -EINVAL;
@@ -441,7 +441,7 @@ static void get_next_gp_data_cb(void *context,
 	struct seel_ace *ace  = context;
 	size_t payload_length;
 
-	DBG("Current %zd Total %zd Got %zd",
+	DBG("Current %zu Total %zu Got %zu",
 		ace->current_rules_length, ace->rules_length, apdu_length);
 
 	if (err)
@@ -523,7 +523,7 @@ static void get_all_gp_data_cb(void *context,
 	payload_length = apdu_length - GET_ALL_DATA_CMD_LEN -
 					length_length - APDU_STATUS_LEN;
 
-	DBG("Received %zd bytes of payload", payload_length);
+	DBG("Received %zu bytes of payload", payload_length);
 
 	if (payload_length < (size_t)rule_length) {
 		ace->rules_length = rule_length;
@@ -655,7 +655,7 @@ static struct seel_ace_rule *find_specific_rule(struct seel_ace *ace,
 {
 	GSList *list;
 
-	DBG("%zd", aid_len);
+	DBG("%zu", aid_len);
 
 	if (!hash || !aid)
 		return false;
@@ -684,7 +684,7 @@ static bool find_specific_rule_for_aid(struct seel_ace *ace,
 {
 	GSList *list;
 
-	DBG("%zd", aid_len);
+	DBG("%zu", aid_len);
 
 	if (!aid)
 		return false;
@@ -713,7 +713,7 @@ static struct seel_ace_rule *find_generic_rule_for_aid(struct seel_ace *ace,
 {
 	GSList *list;
 
-	DBG("%zd", aid_len);
+	DBG("%zu", aid_len);
 
 	if (!aid)
 		return false;
@@ -833,7 +833,7 @@ bool __seel_ace_apdu_allowed(struct seel_channel *channel, uint8_t *hash,
 	uint8_t *aid;
 	size_t aid_len;
 
-	DBG("%zd", apdu_len);
+	DBG("%zu", apdu_len);
 
 	/* XXX Do we need to do some filtering on the basic channel ?*/
 	if (__seel_channel_is_basic(channel))
se/apdu.c +4 -4
index f5ba28f8046c..fe0e6319732b 100644
@@ -131,7 +131,7 @@ struct seel_apdu *__seel_apdu_build(uint8_t *apdu, size_t length, uint8_t channe
 	}
 
 	if (channel > 3) {
-		DBG("Invalid channel number %d", channel);
+		DBG("Invalid channel number %u", channel);
 		channel = 0;
 	}
 
@@ -159,7 +159,7 @@ void __seel_apdu_dump(uint8_t *apdu, size_t length)
 		sprintf(str + (3 * i), "%02X ", apdu[i]);
 	str[3 * length] = 0;
 
-	DBG("[%zd] %s", length, str);
+	DBG("[%zu] %s", length, str);
 
 	g_free(str);
 }
@@ -188,7 +188,7 @@ struct seel_apdu *__seel_apdu_open_logical_channel(void)
 
 struct seel_apdu *__seel_apdu_close_logical_channel(uint8_t channel)
 {
-	DBG("%d", channel);
+	DBG("%u", channel);
 
 	return alloc_apdu(CLA_CHANNEL_STANDARD, 0, INS_MANAGE_CHANNEL, 0x80,
 							channel, 0, NULL, -1);
@@ -197,7 +197,7 @@ struct seel_apdu *__seel_apdu_close_logical_channel(uint8_t channel)
 struct seel_apdu *__seel_apdu_select_aid(uint8_t channel,
 						uint8_t *aid, size_t aid_length)
 {
-	DBG("%zd", aid_length);
+	DBG("%zu", aid_length);
 
 	if (aid_length < MIN_AID_LENGTH ||
 			aid_length > MAX_AID_LENGTH)
se/plugins/nfc.c +4 -4
index 75aba3b072f7..e2f54126119f 100644
@@ -197,7 +197,7 @@ static int nfc_netlink_event_se(struct genlmsghdr *gnlh, bool add)
 	nfc_idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
 	se_idx = nla_get_u32(attrs[NFC_ATTR_SE_INDEX]);
 
-	DBG("NFC %d SE %d", nfc_idx, se_idx);
+	DBG("NFC %u SE %u", nfc_idx, se_idx);
 
 	if (add) {
 		uint8_t se_type, seel_se_type;
@@ -209,7 +209,7 @@ static int nfc_netlink_event_se(struct genlmsghdr *gnlh, bool add)
 
 		se_type = nla_get_u8(attrs[NFC_ATTR_SE_TYPE]);
 		seel_se_type = nfc_se_type(se_type);
-		DBG("NFC SE type %d %d", se_type, seel_se_type);
+		DBG("NFC SE type %u %u", se_type, seel_se_type);
 
 		return seel_manager_se_add(se_idx, nfc_idx, seel_se_type,
 						SEEL_CONTROLLER_NFC);
@@ -267,7 +267,7 @@ static int nfc_netlink_event_io(struct genlmsghdr *gnlh)
 		goto out;
 	}
 
-	DBG("NFC %d SE %d APDU len %zd", nfc_idx, se_idx, apdu_len);
+	DBG("NFC %u SE %u APDU len %zu", nfc_idx, se_idx, apdu_len);
 
 	nfc_state->ctx->cb(nfc_state->ctx->context, apdu, apdu_len, 0);
 
@@ -550,7 +550,7 @@ static int nfc_transceive(uint8_t ctrl_idx, uint32_t se_idx,
 	void *hdr;
 	int err;
 
-	DBG("%zd APDU %p", apdu_length, apdu);
+	DBG("%zu APDU %p", apdu_length, apdu);
 
 	if (nfc_state->ctx)
 		return -EALREADY;
se/plugins/tizen.c +1 -1
index 6bdbc2473cee..e2ea4dec4212 100644
@@ -375,7 +375,7 @@ static void tapi_transfer_apdu_reply(DBusPendingCall *call, void *user_data)
 	if (apdu_length == 0 || apdu == NULL)
 		DBG("data is NULL");
 
-	DBG("apdu_length %d", apdu_length);
+	DBG("apdu_length %u", apdu_length);
 
 done:
 	ctx->cb(ctx->context, apdu, apdu_length, result);
se/se.c +3 -3
index 002498e63f7a..9a8b32ebe6d2 100644
@@ -116,7 +116,7 @@ static void io_cb(void *context,
 	struct seel_se_ioreq *req = context;
 	struct seel_se *se = req->se;
 
-	DBG("%zd %d", apdu_length, err);
+	DBG("%zu %d", apdu_length, err);
 
 	/* Check response status */
 	if (!err)
@@ -247,7 +247,7 @@ static char *se_path(uint32_t se_idx, uint8_t ctrl_idx,
 	if (type == NULL)
 		return NULL;
 
-	return g_strdup_printf("%s/se/%s%d_%s_se%d", SEEL_PATH,
+	return g_strdup_printf("%s/se/%s%u_%s_se%u", SEEL_PATH,
 					ctrl, ctrl_idx, type, se_idx);
 }
 
@@ -538,7 +538,7 @@ static void open_channel_cb(void *context,
 
 	ctx->channel = apdu[0];
 
-	DBG("Channel %d", ctx->channel);
+	DBG("Channel %u", ctx->channel);
 
 	select_aid = __seel_apdu_select_aid(ctx->channel,
 						ctx->aid, ctx->aid_len);
Signature · 1 line
2.27.0
#20 lore raw

PATCH v2 20/73 adapter: adjust indentation of continued arguments

In reply to Krzysztof Kozlowski

No functional change.

---
 src/adapter.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
src/adapter.c +6 -6
index 9c483ca28855..5a8f083a686c 100644
@@ -232,7 +232,7 @@ static gboolean property_get_powered(const GDBusPropertyTable *property,
 }
 
 static void set_powered(GDBusPendingPropertySet id, dbus_bool_t powered,
-								void *data)
+			void *data)
 {
 	struct near_adapter *adapter = data;
 	int err;
@@ -284,7 +284,7 @@ static void property_set_powered(const GDBusPropertyTable *property,
 }
 
 static void append_protocols(DBusMessageIter *iter,
-					struct near_adapter *adapter)
+			     struct near_adapter *adapter)
 {
 	const char *str;
 
@@ -405,7 +405,7 @@ static DBusMessage *stop_poll_loop(DBusConnection *conn,
 }
 
 static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx,
-								int status);
+			   int status);
 
 static gboolean check_presence(gpointer user_data)
 {
@@ -453,7 +453,7 @@ static gboolean dep_timer(gpointer user_data)
 }
 
 static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx,
-								int status)
+			   int status)
 {
 	struct near_adapter *adapter;
 
@@ -704,7 +704,7 @@ static void tag_read_cb(uint32_t adapter_idx, uint32_t target_idx, int status)
 }
 
 static void device_read_cb(uint32_t adapter_idx, uint32_t target_idx,
-								int status)
+			   int status)
 {
 	struct near_adapter *adapter;
 
@@ -996,7 +996,7 @@ static gboolean execute_recv_cb(gpointer user_data)
 }
 
 static gboolean adapter_recv_event(GIOChannel *channel, GIOCondition condition,
-							gpointer user_data)
+				   gpointer user_data)
 {
 	struct near_adapter *adapter = user_data;
 	struct near_adapter_ioreq *req;
Signature · 1 line
2.27.0
#21 lore raw

PATCH v2 21/73 adapter: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    src/adapter.c: In function ‘near_adapter_disconnect’:
    ./include/near/log.h:45:14: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~
    src/adapter.c:1095:2: note: in expansion of macro ‘DBG’
     1095 |  DBG("idx %d", idx);
          |  ^~~
---
 src/adapter.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
src/adapter.c +14 -14
index 5a8f083a686c..420127f4f396 100644
@@ -566,7 +566,7 @@ struct near_adapter *__near_adapter_create(uint32_t idx,
 							NULL, free_device);
 	adapter->device_sock = -1;
 
-	adapter->path = g_strdup_printf("%s/nfc%d", NFC_PATH, idx);
+	adapter->path = g_strdup_printf("%s/nfc%u", NFC_PATH, idx);
 
 	return adapter;
 }
@@ -597,7 +597,7 @@ int __near_adapter_set_dep_state(uint32_t idx, bool dep)
 {
 	struct near_adapter *adapter;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -639,7 +639,7 @@ bool __near_adapter_get_dep_state(uint32_t idx)
 {
 	struct near_adapter *adapter;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -821,7 +821,7 @@ int __near_adapter_add_target(uint32_t idx, uint32_t target_idx,
 	struct near_adapter *adapter;
 	int ret;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -852,7 +852,7 @@ int __near_adapter_remove_target(uint32_t idx, uint32_t target_idx)
 {
 	struct near_adapter *adapter;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -875,11 +875,11 @@ static gboolean poll_error(gpointer user_data)
 	struct near_adapter *adapter = user_data;
 	bool reset;
 
-	DBG("adapter %d", adapter->idx);
+	DBG("adapter %u", adapter->idx);
 
 	reset = near_setting_get_bool("ResetOnError");
 	if (reset) {
-		near_error("Resetting nfc%d", adapter->idx);
+		near_error("Resetting nfc%u", adapter->idx);
 		 __near_netlink_adapter_enable(adapter->idx, false);
 		 __near_netlink_adapter_enable(adapter->idx, true);
 	}
@@ -893,7 +893,7 @@ int __near_adapter_get_targets_done(uint32_t idx)
 {
 	struct near_adapter *adapter;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -920,7 +920,7 @@ int __near_adapter_add_device(uint32_t idx, uint8_t *nfcid, uint8_t nfcid_len)
 	struct near_adapter *adapter;
 	int ret;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -944,7 +944,7 @@ int __near_adapter_remove_device(uint32_t idx)
 	struct near_adapter *adapter;
 	uint32_t device_idx = 0;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -1040,7 +1040,7 @@ int near_adapter_connect(uint32_t idx, uint32_t target_idx, uint8_t protocol)
 	struct sockaddr_nfc addr;
 	int err, sock;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -1092,7 +1092,7 @@ int near_adapter_disconnect(uint32_t idx)
 	uint32_t target_idx;
 	uint16_t tag_type;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter)
@@ -1106,7 +1106,7 @@ int near_adapter_disconnect(uint32_t idx)
 	tag_type = __near_tag_get_type(adapter->tag_link);
 	target_idx = near_tag_get_target_idx(adapter->tag_link);
 
-	DBG("tag type %d", tag_type);
+	DBG("tag type %u", tag_type);
 
 	__near_adapter_remove_target(adapter->idx, target_idx);
 
@@ -1133,7 +1133,7 @@ int near_adapter_send(uint32_t idx, uint8_t *buf, size_t length,
 	struct near_adapter_ioreq *req = NULL;
 	int err;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
 	if (!adapter) {
Signature · 1 line
2.27.0
#22 lore raw

PATCH v2 22/73 gdbus: do not shadow global 'pending' variable (-Wshadow)

In reply to Krzysztof Kozlowski

Fix -Wshadow warnings:

gdbus/object.c: In function ‘g_dbus_pending_success’:
gdbus/object.c:286:24: error: declaration of ‘pending’ shadows a global declaration [-Werror=shadow]
286 | GDBusPendingReply pending)
| ~~~~~~~~~~~~~~~~~~^~~~~~~
gdbus/object.c:89:16: note: shadowed declaration is here
89 | static GSList *pending = NULL;
| ^~~~~~~
gdbus/object.c: In function ‘g_dbus_pending_error_valist’:
gdbus/object.c:308:23: error: declaration of ‘pending’ shadows a global declaration [-Werror=shadow]
308 | GDBusPendingReply pending, const char *name,
| ~~~~~~~~~~~~~~~~~~^~~~~~~
gdbus/object.c:89:16: note: shadowed declaration is here
89 | static GSList *pending = NULL;
| ^~~~~~~
gdbus/object.c: In function ‘g_dbus_pending_error’:
gdbus/object.c:331:23: error: declaration of ‘pending’ shadows a global declaration [-Werror=shadow]
331 | GDBusPendingReply pending,
| ~~~~~~~~~~~~~~~~~~^~~~~~~
gdbus/object.c:89:16: note: shadowed declaration is here
89 | static GSList *pending = NULL;
| ^~~~~~~
gdbus/object.c: In function ‘builtin_security_function’:
gdbus/object.c:370:25: error: declaration of ‘pending’ shadows a global declaration [-Werror=shadow]
370 | GDBusPendingReply pending)
| ~~~~~~~~~~~~~~~~~~^~~~~~~
gdbus/object.c:89:16: note: shadowed declaration is here
89 | static GSList *pending = NULL;
| ^~~~~~~

---
 gdbus/object.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
gdbus/object.c +11 -11
index 96db51665301..f394334d4594 100644
@@ -283,14 +283,14 @@ static GSList *pending_security = NULL;
 static const GDBusSecurityTable *security_table = NULL;
 
 void g_dbus_pending_success(DBusConnection *connection,
-					GDBusPendingReply pending)
+			    GDBusPendingReply pending_reply)
 {
 	GSList *list;
 
 	for (list = pending_security; list; list = list->next) {
 		struct security_data *secdata = list->data;
 
-		if (secdata->pending != pending)
+		if (secdata->pending != pending_reply)
 			continue;
 
 		pending_security = g_slist_remove(pending_security, secdata);
@@ -305,7 +305,7 @@ void g_dbus_pending_success(DBusConnection *connection,
 }
 
 void g_dbus_pending_error_valist(DBusConnection *connection,
-				GDBusPendingReply pending, const char *name,
+				GDBusPendingReply pending_reply, const char *name,
 					const char *format, va_list args)
 {
 	GSList *list;
@@ -313,7 +313,7 @@ void g_dbus_pending_error_valist(DBusConnection *connection,
 	for (list = pending_security; list; list = list->next) {
 		struct security_data *secdata = list->data;
 
-		if (secdata->pending != pending)
+		if (secdata->pending != pending_reply)
 			continue;
 
 		pending_security = g_slist_remove(pending_security, secdata);
@@ -328,14 +328,14 @@ void g_dbus_pending_error_valist(DBusConnection *connection,
 }
 
 void g_dbus_pending_error(DBusConnection *connection,
-				GDBusPendingReply pending,
+			  GDBusPendingReply pending_reply,
 				const char *name, const char *format, ...)
 {
 	va_list args;
 
 	va_start(args, format);
 
-	g_dbus_pending_error_valist(connection, pending, name, format, args);
+	g_dbus_pending_error_valist(connection, pending_reply, name, format, args);
 
 	va_end(args);
 }
@@ -365,19 +365,19 @@ static void builtin_security_result(dbus_bool_t authorized, void *user_data)
 }
 
 static void builtin_security_function(DBusConnection *conn,
-						const char *action,
-						gboolean interaction,
-						GDBusPendingReply pending)
+				      const char *action,
+				      gboolean interaction,
+				      GDBusPendingReply pending_reply)
 {
 	struct builtin_security_data *data;
 
 	data = g_new0(struct builtin_security_data, 1);
 	data->conn = conn;
-	data->pending = pending;
+	data->pending = pending_reply;
 
 	if (polkit_check_authorization(conn, action, interaction,
 				builtin_security_result, data, 30000) < 0)
-		g_dbus_pending_error(conn, pending, NULL, NULL);
+		g_dbus_pending_error(conn, pending_reply, NULL, NULL);
 }
 
 static gboolean check_privilege(DBusConnection *conn, DBusMessage *msg,
Signature · 1 line
2.27.0
#23 lore raw

PATCH v2 23/73 nciattach: fix poll.h include location

In reply to Krzysztof Kozlowski

poll.h header should not be included from include/sys. This works fine on Glibc but fails on musl:

In file included from tools/nciattach.c:42:
/usr/include/sys/poll.h:1:2: error: #warning redirecting incorrect #include <sys/poll.h> to <poll.h> [-Werror=cpp]
1 | #warning redirecting incorrect #include <sys/poll.h> to <poll.h>

---
 tools/nciattach.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/nciattach.c +1 -1
index 370f98bb176c..574c0fbe784a 100644
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <poll.h>
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
@@ -39,7 +40,6 @@
 #include <termios.h>
 #include <time.h>
 #include <sys/time.h>
-#include <sys/poll.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <termios.h>
Signature · 1 line
2.27.0
#24 lore raw

PATCH v2 24/73 nciattach: do not shadow other local 'opt' variable (-Wshadow)

In reply to Krzysztof Kozlowski

Fix -Wshadow warning:

tools/nciattach.c: In function ‘main’:
tools/nciattach.c:272:9: error: declaration of ‘opt’ shadows a previous local [-Werror=shadow]
272 | char *opt;
| ^~~
tools/nciattach.c:236:24: note: shadowed declaration is here
236 | int detach, printpid, opt, i, n, ld, err;
| ^~~

---
 tools/nciattach.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/nciattach.c +4 -4
index 574c0fbe784a..4ac37d82d545 100644
@@ -269,16 +269,16 @@ int main(int argc, char *argv[])
 	}
 
 	for (n = 0; optind < argc; n++, optind++) {
-		char *opt;
+		char *option;
 
-		opt = argv[optind];
+		option = argv[optind];
 
 		switch(n) {
 		case 0:
 			dev[0] = 0;
-			if (!strchr(opt, '/'))
+			if (!strchr(option, '/'))
 				strcpy(dev, "/dev/");
-			strcat(dev, opt);
+			strcat(dev, option);
 			break;
 
 		case 1:
Signature · 1 line
2.27.0
#25 lore raw

PATCH v2 25/73 bluetooth: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

In file included from src/near.h:36,
from src/bluetooth.c:32:
src/bluetooth.c: In function ‘bt_adapter_property_changed’:
./include/near/log.h:45:14: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 5 has type ‘int’ [-Werror=format=]
45 | near_debug("%s:%s() " fmt, \
| ^~~~~~~~~~
src/bluetooth.c:465:3: note: in expansion of macro ‘DBG’
465 | DBG("%s: %x", property, bt_def_oob_data.class_of_device);
| ^~~

In file included from src/near.h:36,
from src/bluetooth.c:32:
src/bluetooth.c: In function ‘bt_adapter_property_changed’:
./include/near/log.h:45:14: error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 5 has type ‘int’ [-Werror=format=]
45 | near_debug("%s:%s() " fmt, \
| ^~~~~~~~~~
src/bluetooth.c:475:3: note: in expansion of macro ‘DBG’
475 | DBG("%s: %u", property, bt_def_oob_data.powered);
| ^~~

---
 src/bluetooth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/bluetooth.c +2 -2
index 3e67f1c88b84..79cfbb38e334 100644
@@ -462,7 +462,7 @@ static gboolean bt_adapter_property_changed(DBusConnection *conn,
 		dbus_message_iter_get_basic(&var, &class);
 		bt_def_oob_data.class_of_device = class;
 
-		DBG("%s: %x", property, bt_def_oob_data.class_of_device);
+		DBG("%s: %x", property, (unsigned int)bt_def_oob_data.class_of_device);
 	} else if (g_str_equal(property, "Powered")) {
 		dbus_bool_t powered;
 
@@ -472,7 +472,7 @@ static gboolean bt_adapter_property_changed(DBusConnection *conn,
 		dbus_message_iter_get_basic(&var, &powered);
 		bt_def_oob_data.powered = powered;
 
-		DBG("%s: %u", property, bt_def_oob_data.powered);
+		DBG("%s: %d", property, bt_def_oob_data.powered);
 	}
 
 	return TRUE;
Signature · 1 line
2.27.0
#26 lore raw

PATCH v2 26/73 nfctype2: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

In file included from plugins/nfctype2.c:36:
plugins/nfctype2.c: In function ‘data_recv’:
./include/near/log.h:45:14: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
45 | near_debug("%s:%s() " fmt, \
| ^~~~~~~~~~
plugins/nfctype2.c:195:2: note: in expansion of macro ‘DBG’
195 | DBG("adapter %d", adapter_idx);
| ^~~

plugins/nfctype2.c: In function ‘nfctype2_write’:
plugins/nfctype2.c:458:43: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 2 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
458 | near_error("Not enough space on tag %zd %zd",
| ~~^
| |
| long int
| %ld
459 | ndef->length,
| ~~~~~~~~~~~~
| |
| size_t {aka long unsigned int}

---
 plugins/nfctype2.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
plugins/nfctype2.c +6 -6
index dec9615b69af..3618ca177363 100644
@@ -192,7 +192,7 @@ static int data_recv(uint8_t *resp, int length, void *data)
 	cmd.cmd = CMD_READ;
 	cmd.block = DATA_BLOCK_START + tag->current_block;
 
-	DBG("adapter %d", adapter_idx);
+	DBG("adapter %u", adapter_idx);
 
 	return near_adapter_send(adapter_idx,
 				(uint8_t *) &cmd, CMD_READ_SIZE,
@@ -341,7 +341,7 @@ static int nfctype2_read(uint32_t adapter_idx,
 			cb, tgt_subtype);
 
 	default:
-		DBG("Unknown Tag Type 2 subtype %d", tgt_subtype);
+		DBG("Unknown Tag Type 2 subtype %u", tgt_subtype);
 		return -1;
 	}
 }
@@ -455,7 +455,7 @@ static int nfctype2_write(uint32_t adapter_idx, uint32_t target_idx,
 		 */
 		if (near_tag_get_memory_layout(tag) == NEAR_TAG_MEMORY_STATIC) {
 			if ((ndef->length + 3) > near_tag_get_data_length(tag)) {
-				near_error("Not enough space on tag %zd %zd",
+				near_error("Not enough space on tag %zu %zu",
 						ndef->length,
 						near_tag_get_data_length(tag));
 				err = -ENOSPC;
@@ -471,7 +471,7 @@ static int nfctype2_write(uint32_t adapter_idx, uint32_t target_idx,
 		return mifare_write(adapter_idx, target_idx, ndef,
 				cb, tgt_subtype);
 	default:
-		DBG("Unknown TAG Type 2 subtype %d", tgt_subtype);
+		DBG("Unknown TAG Type 2 subtype %u", tgt_subtype);
 		err = -EINVAL;
 		goto out_err;
 	}
@@ -533,7 +533,7 @@ static int nfctype2_check_presence(uint32_t adapter_idx, uint32_t target_idx,
 							cb, tgt_subtype);
 
 	default:
-		DBG("Unknown TAG Type 2 subtype %d", tgt_subtype);
+		DBG("Unknown TAG Type 2 subtype %u", tgt_subtype);
 
 		return -1;
 	}
@@ -586,7 +586,7 @@ static int nfctype2_format(uint32_t adapter_idx, uint32_t target_idx,
 	tgt_subtype = near_tag_get_subtype(adapter_idx, target_idx);
 
 	if (tgt_subtype != NEAR_TAG_NFC_T2_MIFARE_ULTRALIGHT) {
-		DBG("Unknown Tag Type 2 subtype %d", tgt_subtype);
+		DBG("Unknown Tag Type 2 subtype %u", tgt_subtype);
 		return -1;
 	}
 
Signature · 1 line
2.27.0
#27 lore raw

PATCH v2 27/73 nfctype3: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

In file included from plugins/nfctype3.c:36:
plugins/nfctype3.c: In function ‘data_recv’:
./include/near/log.h:45:14: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
45 | near_debug("%s:%s() " fmt, \
| ^~~~~~~~~~
plugins/nfctype3.c:249:3: note: in expansion of macro ‘DBG’
249 | DBG("Done reading %zd bytes at %p", data_length, nfc_data);
| ^~~

---
 plugins/nfctype3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/nfctype3.c +1 -1
index d4fbed0dfc2f..c0502f15d9f2 100644
@@ -246,7 +246,7 @@ static int data_recv(uint8_t *resp, int length, void *data)
 
 		tag->current_block = 0;
 
-		DBG("Done reading %zd bytes at %p", data_length, nfc_data);
+		DBG("Done reading %zu bytes at %p", data_length, nfc_data);
 		records = near_ndef_parse_msg(nfc_data, data_length, NULL);
 		near_tag_add_records(tag->tag, records, tag->cb, 0);
 
Signature · 1 line
2.27.0
#28 lore raw

PATCH v2 28/73 nfctype5: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

In file included from plugins/nfctype5.c:29:
plugins/nfctype5.c: In function ‘t5_read’:
./include/near/log.h:45:14: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
45 | near_debug("%s:%s() " fmt, \
| ^~~~~~~~~~
plugins/nfctype5.c:437:2: note: in expansion of macro ‘DBG’
437 | DBG("Reading %zd bytes starting at offset %d\n", len, offset);
| ^~~

---
 plugins/nfctype5.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
plugins/nfctype5.c +3 -3
index 3d2cdf030d4f..0f90e55ab268 100644
@@ -434,7 +434,7 @@ static int t5_read(struct near_tag *tag, uint8_t offset, uint8_t *buf,
 	uint8_t blk_size = near_tag_get_blk_size(tag);
 	int err;
 
-	DBG("Reading %zd bytes starting at offset %d\n", len, offset);
+	DBG("Reading %zu bytes starting at offset %u\n", len, offset);
 
 	err = t5_cmd_hdr_init(tag, &t5_cmd.hdr, CMD_READ_SINGLE_BLOCK);
 	if (err)
@@ -532,10 +532,10 @@ static int t5_write(struct near_tag *tag, uint8_t offset, uint8_t *buf,
 	uint8_t blk_size = near_tag_get_blk_size(tag);
 	int err;
 
-	DBG("Writing %zd bytes starting at offset %d\n", len, offset);
+	DBG("Writing %zu bytes starting at offset %u\n", len, offset);
 
 	if (offset % blk_size) {
-		near_error("Write - Invalid offset - offset: %d, blk_size: %d",
+		near_error("Write - Invalid offset - offset: %u, blk_size: %u",
 			   offset, blk_size);
 		return -EINVAL;
 	}
Signature · 1 line
2.27.0
#29 lore raw

PATCH v2 29/73 nfctype5: fix returning uninitialized stack value in t5_tag_is_ti_pro()

In reply to Krzysztof Kozlowski

The return value was not initialized so if tag was not matching, random stack value (usually true) was returned instead of false.

This fixes clang warning:

    plugins/nfctype5.c:257:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
            if ((uid[5] == 0xc4) || (uid[5] == 0xc5))
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    plugins/nfctype5.c:261:9: note: uninitialized use occurs here
            return ret;
                   ^~~
    plugins/nfctype5.c:257:2: note: remove the 'if' if its condition is always true
            if ((uid[5] == 0xc4) || (uid[5] == 0xc5))
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    plugins/nfctype5.c:248:10: note: initialize the variable 'ret' to silence this warning
            bool ret;
                    ^
                     = false
---
 plugins/nfctype5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/nfctype5.c +1 -1
index 0f90e55ab268..eef2afe9f6d0 100644
@@ -245,7 +245,7 @@ static bool t5_tag_is_ti_std(struct near_tag *tag)
 static bool t5_tag_is_ti_pro(struct near_tag *tag)
 {
 	uint8_t *uid;
-	bool ret;
+	bool ret = false;
 
 	uid = near_tag_get_iso15693_uid(near_tag_get_adapter_idx(tag),
 					near_tag_get_target_idx(tag));
Signature · 1 line
2.27.0
#30 lore raw

PATCH v2 30/73 mifare: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

plugins/mifare.c: In function ‘mifare_read’:
plugins/mifare.c:836:33: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘unsigned int’ [-Werror=format=]
836 | near_error("Mifare tag type [%d] not supported.", tgt_subtype);
| ~^ ~~~~~~~~~~~
| | |
| int unsigned int
| %d

---
 plugins/mifare.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
plugins/mifare.c +4 -4
index 3d376526735d..a4e4ba443995 100644
@@ -833,7 +833,7 @@ int mifare_read(uint32_t adapter_idx, uint32_t target_idx,
 	case NEAR_TAG_NFC_T2_MIFARE_CLASSIC_4K:
 		break;
 	default:
-		near_error("Mifare tag type [%d] not supported.", tgt_subtype);
+		near_error("Mifare tag type [%u] not supported.", tgt_subtype);
 		return -1;
 	}
 
@@ -900,7 +900,7 @@ int mifare_check_presence(uint32_t adapter_idx, uint32_t target_idx,
 	case NEAR_TAG_NFC_T2_MIFARE_CLASSIC_4K:
 		break;
 	default:
-		near_error("Mifare tag type %d not supported.", tgt_subtype);
+		near_error("Mifare tag type %u not supported.", tgt_subtype);
 		return -1;
 	}
 
@@ -1228,7 +1228,7 @@ static int writing_not_permitted(void *data)
 		}
 	}
 
-	DBG("TAG writable sectors' size: [%d].", new_tag_size);
+	DBG("TAG writable sectors' size: [%u].", new_tag_size);
 
 	/* Check if there's enough space on tag */
 	if (new_tag_size < mf_ck->ndef->length) {
@@ -1293,7 +1293,7 @@ int mifare_write(uint32_t adapter_idx, uint32_t target_idx,
 	case NEAR_TAG_NFC_T2_MIFARE_CLASSIC_4K:
 		break;
 	default:
-		near_error("Mifare tag type %d not supported.", tgt_subtype);
+		near_error("Mifare tag type %u not supported.", tgt_subtype);
 		return -1;
 	}
 
Signature · 1 line
2.27.0
#31 lore raw

PATCH v2 31/73 mifare: use unsigned int to suppress compiler -Wstrict-overflow

In reply to 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) {
^

---
 plugins/mifare.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
plugins/mifare.c +3 -3
index a4e4ba443995..f42007d5dfd7 100644
@@ -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) {
Signature · 1 line
2.27.0
#32 lore raw

PATCH v2 32/73 p2p: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

In file included from plugins/p2p.c:38:
plugins/p2p.c: In function ‘p2p_listener_event’:
./include/near/log.h:45:14: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘__u32’ {aka ‘unsigned int’} [-Werror=format=]
45 | near_debug("%s:%s() " fmt, \
| ^~~~~~~~~~
plugins/p2p.c:261:2: note: in expansion of macro ‘DBG’
261 | DBG("target idx %d", client_addr.target_idx);
| ^~~

---
 plugins/p2p.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
plugins/p2p.c +2 -2
index 13702ade3e14..cf3e0accaf33 100644
@@ -256,9 +256,9 @@ static gboolean p2p_listener_event(GIOChannel *channel, GIOCondition condition,
 		return FALSE;
 	}
 
-	DBG("client dsap %d ssap %d",
+	DBG("client dsap %u ssap %u",
 		client_addr.dsap, client_addr.ssap);
-	DBG("target idx %d", client_addr.target_idx);
+	DBG("target idx %u", client_addr.target_idx);
 
 	client_data = g_try_malloc0(sizeof(struct p2p_data));
 	if (!client_data) {
Signature · 1 line
2.27.0
#33 lore raw

PATCH v2 33/73 npp: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

In file included from plugins/npp.c:36:
plugins/npp.c: In function ‘npp_push’:
./include/near/log.h:45:14: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
45 | near_debug("%s:%s() " fmt, \
| ^~~~~~~~~~
plugins/npp.c:185:2: note: in expansion of macro ‘DBG’
185 | DBG("Sending %zd bytes", frame_length);
| ^~~

---
 plugins/npp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
plugins/npp.c +1 -1
index 6bed302b4a8f..5c9d2e0cd003 100644
@@ -182,7 +182,7 @@ static int npp_push(int fd, uint32_t adapter_idx, uint32_t target_idx,
 	entry->ndef_length = GINT_TO_BE(ndef->length);
 	memcpy(entry->ndef, ndef->data, ndef->length);
 
-	DBG("Sending %zd bytes", frame_length);
+	DBG("Sending %zu bytes", frame_length);
 
 	err = send(fd, frame, frame_length, MSG_DONTWAIT);
 
Signature · 1 line
2.27.0
#34 lore raw

PATCH v2 34/73 device: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    src/device.c: In function ‘near_device_get_device’:
    src/device.c:85:33: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       85 |  path = g_strdup_printf("%s/nfc%d/device%d", NFC_PATH,
          |                                ~^
          |                                 |
          |                                 int
          |                                %d
       86 |      adapter_idx, target_idx);
          |      ~~~~~~~~~~~
          |      |
          |      uint32_t {aka unsigned int}
---
 src/device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
src/device.c +3 -3
index a6598e0ddd28..aeae7d39a290 100644
@@ -82,7 +82,7 @@ struct near_device *near_device_get_device(uint32_t adapter_idx,
 
 	DBG("");
 
-	path = g_strdup_printf("%s/nfc%d/device%d", NFC_PATH,
+	path = g_strdup_printf("%s/nfc%u/device%u", NFC_PATH,
 					adapter_idx, target_idx);
 	if (!path)
 		return NULL;
@@ -305,7 +305,7 @@ int near_device_add_records(struct near_device *device, GList *records,
 	for (list = records; list; list = list->next) {
 		record = list->data;
 
-		path = g_strdup_printf("%s/nfc%d/device%d/record%d",
+		path = g_strdup_printf("%s/nfc%u/device%u/record%u",
 					NFC_PATH, device->adapter_idx,
 					device->target_idx, device->n_records);
 
@@ -342,7 +342,7 @@ struct near_device *__near_device_add(uint32_t adapter_idx, uint32_t target_idx,
 	if (!device)
 		return NULL;
 
-	device->path = g_strdup_printf("%s/nfc%d/device%d", NFC_PATH,
+	device->path = g_strdup_printf("%s/nfc%u/device%u", NFC_PATH,
 					adapter_idx, target_idx);
 	if (!device->path) {
 		g_free(device);
Signature · 1 line
2.27.0
#35 lore raw

PATCH v2 35/73 manager: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    In file included from src/near.h:36,
                     from src/manager.c:34:
    src/manager.c: In function ‘__near_manager_adapter_add’:
    ./include/near/log.h:45:14: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~
    src/manager.c:45:2: note: in expansion of macro ‘DBG’
       45 |  DBG("idx %d", idx);
          |  ^~~
---
 src/manager.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/manager.c +2 -2
index e4b72a73fcbb..754c254d85ad 100644
@@ -42,7 +42,7 @@ int __near_manager_adapter_add(uint32_t idx, const char *name,
 	const char *path;
 	int err;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = __near_adapter_create(idx, name, protocols, powered);
 	if (!adapter)
@@ -66,7 +66,7 @@ void __near_manager_adapter_remove(uint32_t idx)
 	struct near_adapter *adapter;
 	const char *path;
 
-	DBG("idx %d", idx);
+	DBG("idx %u", idx);
 
 	adapter = __near_adapter_get(idx);
 	if (!adapter)
Signature · 1 line
2.27.0
#36 lore raw

PATCH v2 36/73 netlink: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    src/netlink.c: In function ‘nfc_netlink_event_tm_deactivated’:
    ./include/near/log.h:45:14: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~
    src/netlink.c:759:2: note: in expansion of macro ‘DBG’
      759 |  DBG("%d", idx);
          |  ^~~
    src/netlink.c: In function ‘nfc_netlink_event’:
    src/netlink.c:772:54: error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__u32’ {aka ‘unsigned int’} [-Werror=format=]
      772 |   near_error("WARNING: Wrong netlink message sender %d",
          |                                                     ~^
          |                                                      |
          |                                                      int
          |                                                     %d
      773 |         src->nl_pid);
          |         ~~~~~~~~~~~
          |            |
          |            __u32 {aka unsigned int}
---
 src/netlink.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
src/netlink.c +8 -8
index 3c77999a05f2..a3b206aeaa88 100644
@@ -567,7 +567,7 @@ static int get_targets_handler(struct nl_msg *n, void *arg)
 		iso15693_uid_len = 0;
 	}
 
-	DBG("target idx %d proto 0x%x sens_res 0x%x sel_res 0x%x NFCID len %d",
+	DBG("target idx %u proto 0x%x sens_res 0x%x sel_res 0x%x NFCID len %d",
 	    target_idx, protocols, sens_res, sel_res, nfcid_len);
 	DBG("\tiso15693_uid_len %d", iso15693_uid_len);
 
@@ -607,7 +607,7 @@ static int nfc_netlink_event_targets_found(struct genlmsghdr *gnlh)
 
 	adapter_idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
 
-	DBG("adapter %d", adapter_idx);
+	DBG("adapter %u", adapter_idx);
 
 	msg = nlmsg_alloc();
 	if (!msg)
@@ -653,7 +653,7 @@ static int nfc_netlink_event_target_lost(struct genlmsghdr *gnlh)
 	adapter_idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
 	target_idx = nla_get_u32(attr[NFC_ATTR_TARGET_INDEX]);
 
-	DBG("adapter %d target %d", adapter_idx, target_idx);
+	DBG("adapter %u target %u", adapter_idx, target_idx);
 
 	return __near_adapter_remove_target(adapter_idx, target_idx);
 }
@@ -690,7 +690,7 @@ static int nfc_netlink_event_dep_up(struct genlmsghdr *gnlh)
 
 		target_idx = nla_get_u32(attrs[NFC_ATTR_TARGET_INDEX]);
 
-		DBG("%d %d", idx, target_idx);
+		DBG("%u %u", idx, target_idx);
 
 		return __near_adapter_set_dep_state(idx, true);
 	} else {
@@ -735,7 +735,7 @@ static int nfc_netlink_event_tm_activated(struct genlmsghdr *gnlh)
 
 	idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
 
-	DBG("%d", idx);
+	DBG("%u", idx);
 
 	return __near_adapter_add_device(idx, NULL, 0);
 }
@@ -756,7 +756,7 @@ static int nfc_netlink_event_tm_deactivated(struct genlmsghdr *gnlh)
 
 	idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
 
-	DBG("%d", idx);
+	DBG("%u", idx);
 
 	return __near_adapter_remove_device(idx);
 }
@@ -769,8 +769,8 @@ static int nfc_netlink_event(struct nl_msg *n, void *arg)
 	DBG("event 0x%x", gnlh->cmd);
 
 	if (src->nl_pid) {
-		near_error("WARNING: Wrong netlink message sender %d",
-								src->nl_pid);
+		near_error("WARNING: Wrong netlink message sender %u",
+			   src->nl_pid);
 		return NL_SKIP;
 	}
 
Signature · 1 line
2.27.0
#37 lore raw

PATCH v2 37/73 gdbus: annotate printf-like functions as accepting format

In reply to 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",
---
 gdbus/gdbus.h | 15 ++++++++++-----
 src/adapter.c |  1 +
 2 files changed, 11 insertions(+), 5 deletions(-)
gdbus/gdbus.h +10 -5
index d99c2549d056..e9ffd029e178 100644
@@ -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);
src/adapter.c +1 -0
index 420127f4f396..e0ab8c5d6055 100644
@@ -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;
Signature · 1 line
2.27.0
#38 lore raw

PATCH v2 38/73 snep-send: fix near_ndef_message memory leak

In reply to Krzysztof Kozlowski

The result of near_ndef_prepare_text_record() should be freed, otherwise it leaks making ASAN and valgrind unhappy.

---
 tools/snep-send.c | 2 ++
 1 file changed, 2 insertions(+)
tools/snep-send.c +2 -0
index 5bb153210d30..53f53250b1ae 100644
@@ -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) {
Signature · 1 line
2.27.0
#39 lore raw

PATCH v2 39/73 tag: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    src/tag.c: In function ‘near_tag_get_tag’:
    src/tag.c:99:33: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       99 |  path = g_strdup_printf("%s/nfc%d/tag%d", NFC_PATH,
          |                                ~^
          |                                 |
          |                                 int
          |                                %d
      100 |      adapter_idx, target_idx);
          |      ~~~~~~~~~~~
          |      |
          |      uint32_t {aka unsigned int}

    In file included from src/near.h:36,
                     from src/tag.c:35:
    src/tag.c: In function ‘near_tag_set_nfcid’:
    ./include/near/log.h:45:14: error: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘size_t’ {aka ‘long unsigned int’} [-Werror=format=]
       45 |   near_debug("%s:%s() " fmt, \
          |              ^~~~~~~~~~
    src/tag.c:791:2: note: in expansion of macro ‘DBG’
      791 |  DBG("NFCID len %zd", nfcid_len);
          |  ^~~
---
 src/tag.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/tag.c +4 -4
index 9eba4eefef35..520368b1552c 100644
@@ -96,7 +96,7 @@ struct near_tag *near_tag_get_tag(uint32_t adapter_idx, uint32_t target_idx)
 	struct near_tag *tag;
 	char *path;
 
-	path = g_strdup_printf("%s/nfc%d/tag%d", NFC_PATH,
+	path = g_strdup_printf("%s/nfc%u/tag%u", NFC_PATH,
 					adapter_idx, target_idx);
 	if (!path)
 		return NULL;
@@ -658,7 +658,7 @@ static int tag_initialize(struct near_tag *tag,
 {
 	DBG("");
 
-	tag->path = g_strdup_printf("%s/nfc%d/tag%d", NFC_PATH,
+	tag->path = g_strdup_printf("%s/nfc%u/tag%u", NFC_PATH,
 					adapter_idx, target_idx);
 	if (!tag->path)
 		return -ENOMEM;
@@ -788,7 +788,7 @@ int near_tag_set_nfcid(uint32_t adapter_idx, uint32_t target_idx,
 {
 	struct near_tag *tag;
 
-	DBG("NFCID len %zd", nfcid_len);
+	DBG("NFCID len %zu", nfcid_len);
 
 	tag = near_tag_get_tag(adapter_idx, target_idx);
 	if (!tag)
@@ -881,7 +881,7 @@ int near_tag_add_records(struct near_tag *tag, GList *records,
 	for (list = records; list; list = list->next) {
 		record = list->data;
 
-		path = g_strdup_printf("%s/nfc%d/tag%d/record%d",
+		path = g_strdup_printf("%s/nfc%u/tag%u/record%u",
 					NFC_PATH, tag->adapter_idx,
 					tag->target_idx, tag->next_record);
 
Signature · 1 line
2.27.0
#40 lore raw

PATCH v2 40/73 tag: do not open-code freeing ndef message

In reply to Krzysztof Kozlowski

Use near_ndef_msg_free() instead of open-coding it.

---
 src/tag.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
src/tag.c +2 -4
index 520368b1552c..ce8c477d9527 100644
@@ -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);
Signature · 1 line
2.27.0
#41 lore raw

PATCH v2 41/73 snep: do not open-code freeing ndef message

In reply to Krzysztof Kozlowski

Use near_ndef_msg_free() instead of open-coding it.

---
 src/snep.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
src/snep.c +2 -5
index c0a1d1a00491..a1e90243c020 100644
@@ -147,8 +147,7 @@ void near_snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
 	near_snep_core_response_with_info(client_fd, NEAR_SNEP_RESP_SUCCESS,
 								msg->data, msg->length);
 
-	g_free(msg->data);
-	g_free(msg);
+	near_ndef_msg_free(msg);
 }
 
 /*
@@ -787,9 +786,7 @@ done:
 		}
 	}
 
-	if (ndef)
-		g_free(ndef->data);
-	g_free(ndef);
+	near_ndef_msg_free(ndef);
 }
 
 /* SNEP Core: on P2P push */
Signature · 1 line
2.27.0
#42 lore raw

PATCH v2 42/73 snep: remove useless NULL-ify of local pointer variable

In reply to Krzysztof Kozlowski

Assigning NULL to a local variable (a pointer) at the end of function does not have any effect as this NULL is not passed outside.

---
 src/snep.c | 1 -
 1 file changed, 1 deletion(-)
src/snep.c +0 -1
index a1e90243c020..737060139b07 100644
@@ -206,7 +206,6 @@ static void free_snep_core_fragment(gpointer data)
 		g_free(fragment->data);
 
 	g_free(fragment);
-	fragment = NULL;
 }
 
 static void free_snep_core_push_data(gpointer userdata, int status)
Signature · 1 line
2.27.0
#43 lore raw

PATCH v2 43/73 snep: fix double free of GSList

In reply to Krzysztof Kozlowski

g_slist_free_full() already frees entire GSList so calling it with g_slist_free causes a double free and memory corruption.

This can be seen with Valgrind:

Invalid read of size 8

    at 0x48E3980: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122075: snep_core_process_request (snep.c:481)
    by 0x122075: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    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 0x10F982: main (test-snep-read.c:960)
   Address 0x501e198 is 8 bytes inside a block of size 16 free'd
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122068: snep_core_process_request (snep.c:479)
    by 0x122068: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    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 0x10F982: main (test-snep-read.c:960)
   Block was alloc'd at
    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 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4407: g_slist_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x121AC7: snep_core_push_prepare_fragments (snep.c:377)
    by 0x121AC7: near_snep_core_response (snep.c:695)
    by 0x1224DB: near_snep_core_response_with_info (snep.c:779)
    by 0x122E41: test_snep_dummy_req_get (test-snep-read.c:172)
    by 0x121FF3: snep_core_process_request (snep.c:413)
    by 0x121FF3: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x124449: test_snep_read_get_req_frags_client_resp (test-snep-read.c:746)
    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)

Invalid free() / delete / delete[] / realloc()

    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122075: snep_core_process_request (snep.c:481)
    by 0x122075: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    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 0x10F982: main (test-snep-read.c:960)
   Address 0x501e190 is 0 bytes inside a block of size 16 free'd
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122068: snep_core_process_request (snep.c:479)
    by 0x122068: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    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 0x10F982: main (test-snep-read.c:960)
   Block was alloc'd at
    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 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4407: g_slist_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x121AC7: snep_core_push_prepare_fragments (snep.c:377)
    by 0x121AC7: near_snep_core_response (snep.c:695)
    by 0x1224DB: near_snep_core_response_with_info (snep.c:779)
    by 0x122E41: test_snep_dummy_req_get (test-snep-read.c:172)
    by 0x121FF3: snep_core_process_request (snep.c:413)
    by 0x121FF3: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x124449: test_snep_read_get_req_frags_client_resp (test-snep-read.c:746)
    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)
---
 src/snep.c | 2 --
 1 file changed, 2 deletions(-)
src/snep.c +0 -2
index 737060139b07..bac93c115cb3 100644
@@ -436,7 +436,6 @@ static bool snep_core_process_request(int client_fd,
 
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
-		g_slist_free(snep_data->req->fragments);
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
@@ -476,7 +475,6 @@ leave_cont:
 		/* No more fragment to send, clean memory */
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
-		g_slist_free(snep_data->req->fragments);
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
Signature · 1 line
2.27.0
#44 lore raw

PATCH v2 44/73 snep: fix fragmented response memory leaks

In reply to Krzysztof Kozlowski

Sending long response might cause frame fragmentation and near_snep_core_response_with_info() does not free such 'struct p2p_snep_put_req_data'. It looks like freeing the fragmented response is task for snep_core_process_request as it already frees the fragments. Add also freeing the response itself to fix Valgrind (and ASAN) reported memory leaks:

  $ valgrind  --leak-check=full unit/test-snep-read

80 bytes in 2 blocks are definitely lost in loss record 55 of 60

    at 0x483ED99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x122496: near_snep_core_response_with_info (snep.c:762)
    by 0x122E21: test_snep_dummy_req_get (test-snep-read.c:179)
    by 0x121FF3: snep_core_process_request (snep.c:411)
    by 0x121FF3: near_snep_core_read (snep.c:616)
    by 0x122CC4: test_snep_read_req_common (test-snep-read.c:355)
    by 0x124792: test_snep_read_get_req_frags_client_resp (test-snep-read.c:760)
    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 0x10F982: main (test-snep-read.c:976)
---
 src/snep.c | 4 ++++
 1 file changed, 4 insertions(+)
src/snep.c +4 -0
index bac93c115cb3..d4692c522df3 100644
@@ -436,6 +436,8 @@ static bool snep_core_process_request(int client_fd,
 
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
+		g_free(snep_data->req);
+		snep_data->req = NULL;
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
@@ -475,6 +477,8 @@ leave_cont:
 		/* No more fragment to send, clean memory */
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
+		g_free(snep_data->req);
+		snep_data->req = NULL;
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
Signature · 1 line
2.27.0
#45 lore raw

PATCH v2 45/73 unit: use g_assert_cmpstr()

In reply to Krzysztof Kozlowski

Comparisons of simple values should use test macros instead of checking standard library call return value. This prints more information:

g_assert():

    ERROR:unit/test-ndef-parse.c:256:test_ndef_text_encoding: assertion failed: (strcmp(record->text->language_code, "en-US1") == 0)

g_assert_cmpstr():

    ERROR:unit/test-ndef-parse.c:256:test_ndef_text_encoding: assertion failed (record->text->language_code == "en-US1"): ("en-US" == "en-US1")
---
 unit/test-ndef-parse.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
unit/test-ndef-parse.c +8 -8
index 6c62c7a928c7..91dc1f7c185e 100644
@@ -244,9 +244,9 @@ static void test_ndef_text(void)
 	g_assert(record->header->me == 1);
 
 	g_assert(record->text);
-	g_assert(strcmp(record->text->data, "hello żółw") == 0);
-	g_assert(strcmp(record->text->encoding, "UTF-8") == 0);
-	g_assert(strcmp(record->text->language_code, "en-US") == 0);
+	g_assert_cmpstr(record->text->data, ==, "hello żółw");
+	g_assert_cmpstr(record->text->encoding,==,  "UTF-8");
+	g_assert_cmpstr(record->text->language_code, ==, "en-US");
 
 	if (g_test_verbose()) {
 		g_print("NDEF Text data: %s\n", record->text->data);
@@ -349,9 +349,9 @@ static void test_ndef_title_sp(void)
 		g_print("NDEF SP URI field: %.*s\n", uri->field_length,
 							(char *) uri->field);
 
-	g_assert(strcmp(text->data, "Intel") == 0);
-	g_assert(strcmp(text->encoding, "UTF-8") == 0);
-	g_assert(strcmp(text->language_code, "en") == 0);
+	g_assert_cmpstr(text->data, ==, "Intel");
+	g_assert_cmpstr(text->encoding, ==, "UTF-8");
+	g_assert_cmpstr(text->language_code, ==, "en");
 
 	if (g_test_verbose()) {
 		g_print("NDEF SP Title data: %s\n", text->data);
@@ -389,7 +389,7 @@ static void test_ndef_aar(void)
 
 	g_assert(record->aar);
 	g_assert(record->aar->package);
-	g_assert(strcmp((char *) record->aar->package, "com.example.aar") == 0);
+	g_assert_cmpstr((char *) record->aar->package, ==, "com.example.aar");
 
 
 	if (g_test_verbose())
@@ -431,7 +431,7 @@ static void test_ndef_ho_hs_bt(void)
 
 	records = g_list_next(records);
 	record = records->data;
-	g_assert(strcmp(record->type, BT_MIME_STRING_2_1) == 0);
+	g_assert_cmpstr(record->type, ==, BT_MIME_STRING_2_1);
 }
 
 int main(int argc, char **argv)
Signature · 1 line
2.27.0
#46 lore raw

PATCH v2 46/73 unit: use g_assert_cmpint() and g_assert_cmpuint()

In reply to Krzysztof Kozlowski

Comparisons of simple values should use test macros instead of checking standard library call return value. This prints more information on failure - the actual values used for comparisons.

---
 unit/test-ndef-build.c |  6 ++---
 unit/test-ndef-parse.c | 60 +++++++++++++++++++++---------------------
 unit/test-snep-read.c  | 45 +++++++++++++++----------------
 3 files changed, 56 insertions(+), 55 deletions(-)
unit/test-ndef-build.c +3 -3
index 7ff2222c7855..e83f7a8075df 100644
@@ -63,7 +63,7 @@ static void test_ndef_text_build(void)
 	ndef = near_ndef_prepare_text_record("UTF-8", "en-US", "hello");
 
 	g_assert(ndef);
-	g_assert(ndef->length == ARRAY_SIZE(text));
+	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(text));
 	g_assert(!memcmp(ndef->data, text, ARRAY_SIZE(text)));
 }
 
@@ -74,7 +74,7 @@ static void test_ndef_wsc_with_passphrase_build(void)
 	ndef = near_ndef_prepare_wsc_record("TestSSID", "Testpass");
 
 	g_assert(ndef);
-	g_assert(ndef->length == ARRAY_SIZE(wsc));
+	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc));
 	g_assert(!memcmp(ndef->data, wsc, ARRAY_SIZE(wsc)));
 }
 
@@ -85,7 +85,7 @@ static void test_ndef_wsc_with_out_passphrase_build(void)
 	ndef = near_ndef_prepare_wsc_record("TestSSID", NULL);
 
 	g_assert(ndef);
-	g_assert(ndef->length == ARRAY_SIZE(wsc_wo));
+	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc_wo));
 	g_assert(!memcmp(ndef->data, wsc_wo, ARRAY_SIZE(wsc_wo)));
 }
 
unit/test-ndef-parse.c +30 -30

138 lines not on this page · raw message

unit/test-snep-read.c +23 -22

114 lines not on this page · raw message

Signature · 1 line
2.27.0
#47 lore raw

PATCH v2 47/73 unit: fix recv() and send() return types

In reply to Krzysztof Kozlowski

The recv() and send() return negative number on errors, the return value should be stored in integer or ssize_t.

---
 unit/test-snep-read.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
unit/test-snep-read.c +10 -6
index 802451e8ee18..1871bac5038a 100644
@@ -337,10 +337,11 @@ static bool test_snep_read_req_common(
 			near_server_io req_get, near_server_io req_put)
 {
 	bool ret;
-	size_t nbytes;
+	ssize_t nbytes;
 
 	nbytes = send(sockfd[client], req, frame_len, 0);
-	g_assert(nbytes == frame_len);
+	g_assert_cmpint(nbytes, >, 0);
+	g_assert_cmpuint(nbytes, ==, frame_len);
 
 	TEST_SNEP_LOG("sent 0x%02X request\n", req->request);
 
@@ -364,9 +365,10 @@ static bool test_snep_read_req_common(
 static bool test_snep_read_send_fragment(size_t frag_len,
 						uint8_t *data)
 {
-	size_t nbytes;
+	ssize_t nbytes;
 
 	nbytes = send(sockfd[client], data, frag_len, 0);
+	g_assert_cmpint(nbytes, >, 0);
 	g_assert_cmpuint(nbytes, ==, frag_len);
 
 	near_snep_core_read(sockfd[server], 0, 0, NULL,
@@ -439,7 +441,7 @@ static void test_snep_read_verify_resp(int exp_resp_code,
 		uint32_t exp_resp_info_len, uint8_t *exp_resp_info)
 {
 	struct p2p_snep_resp_frame *resp;
-	size_t nbytes, frame_len;
+	ssize_t nbytes, frame_len;
 
 	frame_len = NEAR_SNEP_RESP_HEADER_LENGTH + exp_resp_info_len;
 	resp = test_snep_build_resp_frame(frame_len, 0, 0, 0, NULL);
@@ -713,7 +715,7 @@ static void test_snep_read_get_req_frags_client_resp(gpointer context,
 	struct p2p_snep_resp_frame *resp;
 	uint32_t frame_len, payload_len;
 	bool ret;
-	size_t nbytes;
+	ssize_t nbytes;
 	uint8_t *data_recvd;
 	uint32_t offset;
 	uint32_t frag_len, info_len;
@@ -750,6 +752,7 @@ static void test_snep_read_get_req_frags_client_resp(gpointer context,
 
 	/* start receiving fragments */
 	nbytes = recv(sockfd[client], resp, frame_len, 0);
+	g_assert_cmpint(nbytes, >=, 0);
 	g_assert_cmpuint(nbytes, ==, frag_len);
 	g_assert_cmpuint(resp->length, ==, GUINT_TO_BE(ctx->req_info_len));
 	g_assert(resp->info);
@@ -829,7 +832,7 @@ static void test_snep_response_noinfo(gpointer context, gconstpointer gp)
 static void test_snep_response_put_get_ndef(gpointer context,
 						gconstpointer gp)
 {
-	size_t nbytes;
+	ssize_t nbytes;
 
 	struct p2p_snep_req_frame *req;
 	struct p2p_snep_resp_frame *resp;
@@ -855,6 +858,7 @@ static void test_snep_response_put_get_ndef(gpointer context,
 
 	/* Send PUT request with text record */
 	nbytes = send(sockfd[server], req, frame_len, 0);
+	g_assert_cmpint(nbytes, >=, 0);
 	g_assert_cmpuint(nbytes, ==, frame_len);
 
 	/* UUT */
Signature · 1 line
2.27.0
#48 lore raw

PATCH v2 48/73 unit: use g_assert_null()

In reply to Krzysztof Kozlowski

It's more readable.

---
 unit/test-ndef-build.c | 2 +-
 unit/test-ndef-parse.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
unit/test-ndef-build.c +1 -1
index e83f7a8075df..bf77fdd42165 100644
@@ -95,7 +95,7 @@ static void test_ndef_wsc_with_out_ssid_build(void)
 
 	ndef = near_ndef_prepare_wsc_record(NULL, NULL);
 
-	g_assert(!ndef);
+	g_assert_null(ndef);
 }
 
 int main(int argc, char **argv)
unit/test-ndef-parse.c +4 -4
index 9d68a6a77c64..a4f1ab3d0df4 100644
@@ -290,8 +290,8 @@ static void test_ndef_single_sp(void)
 
 	g_assert(record->sp);
 	g_assert_cmpuint(record->sp->number_of_title_records, ==, 0);
-	g_assert(!record->sp->type);
-	g_assert(!record->sp->action);
+	g_assert_null(record->sp->type);
+	g_assert_null(record->sp->action);
 	g_assert_cmpuint(record->sp->size, ==, 0);
 	g_assert(record->sp->uri);
 
@@ -332,8 +332,8 @@ static void test_ndef_title_sp(void)
 
 	g_assert(record->sp);
 	g_assert_cmpuint(record->sp->number_of_title_records, ==, 1);
-	g_assert(!record->sp->type);
-	g_assert(!record->sp->action);
+	g_assert_null(record->sp->type);
+	g_assert_null(record->sp->action);
 	g_assert_cmpuint(record->sp->size, ==, 0);
 	g_assert(record->sp->uri);
 	g_assert(record->sp->title_records[0]);
Signature · 1 line
2.27.0
#49 lore raw

PATCH v2 49/73 unit: use g_assert_cmpmem()

In reply to Krzysztof Kozlowski

Comparisons of simple values should use test macros instead of checking standard library call return value. This prints more information on failure - the actual values used for comparisons.

---
 unit/test-ndef-build.c | 6 +++---
 unit/test-ndef-parse.c | 2 +-
 unit/test-snep-read.c  | 9 +++++----
 3 files changed, 9 insertions(+), 8 deletions(-)
unit/test-ndef-build.c +3 -3
index bf77fdd42165..44dce4bf9aef 100644
@@ -64,7 +64,7 @@ static void test_ndef_text_build(void)
 
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(text));
-	g_assert(!memcmp(ndef->data, text, ARRAY_SIZE(text)));
+	g_assert_cmpmem(ndef->data, ARRAY_SIZE(text), text, ARRAY_SIZE(text));
 }
 
 static void test_ndef_wsc_with_passphrase_build(void)
@@ -75,7 +75,7 @@ static void test_ndef_wsc_with_passphrase_build(void)
 
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc));
-	g_assert(!memcmp(ndef->data, wsc, ARRAY_SIZE(wsc)));
+	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc), wsc, ARRAY_SIZE(wsc));
 }
 
 static void test_ndef_wsc_with_out_passphrase_build(void)
@@ -86,7 +86,7 @@ static void test_ndef_wsc_with_out_passphrase_build(void)
 
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc_wo));
-	g_assert(!memcmp(ndef->data, wsc_wo, ARRAY_SIZE(wsc_wo)));
+	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc_wo), wsc_wo, ARRAY_SIZE(wsc_wo));
 }
 
 static void test_ndef_wsc_with_out_ssid_build(void)
unit/test-ndef-parse.c +1 -1
index a4f1ab3d0df4..96288f29f44d 100644
@@ -427,7 +427,7 @@ static void test_ndef_ho_hs_bt(void)
 	ac = ho->ac_payloads[0];
 
 	g_assert_cmpuint(ac->cdr_len, ==, 1);
-	g_assert(memcmp(ac->cdr, "0", ac->cdr_len) == 0);
+	g_assert_cmpmem(ac->cdr, ac->cdr_len, "0", sizeof("0"));
 
 	records = g_list_next(records);
 	record = records->data;
unit/test-snep-read.c +5 -4
index 1871bac5038a..5511fecf5c17 100644
@@ -456,7 +456,8 @@ static void test_snep_read_verify_resp(int exp_resp_code,
 	g_assert_cmpuint(resp->version, ==, NEAR_SNEP_VERSION);
 	g_assert_cmpuint(resp->response, ==, exp_resp_code);
 	g_assert_cmpuint(resp->length, ==, GUINT_TO_BE(exp_resp_info_len));
-	g_assert(!memcmp(resp->info, exp_resp_info, exp_resp_info_len));
+	g_assert_cmpmem(resp->info, GUINT_FROM_BE(resp->length),
+			exp_resp_info, exp_resp_info_len);
 
 	g_free(resp);
 }
@@ -786,8 +787,8 @@ static void test_snep_read_get_req_frags_client_resp(gpointer context,
 					data_recvd + offset);
 
 		/* verify data */
-		g_assert(!memcmp(data_recvd, ctx->req_info,
-				ctx->req_info_len));
+		g_assert_cmpmem(data_recvd, ctx->req_info_len, ctx->req_info,
+				ctx->req_info_len);
 	}
 
 	g_free(data_recvd);
@@ -891,7 +892,7 @@ static void test_snep_response_put_get_ndef(gpointer context,
 	g_assert_cmpuint(resp->response, ==, NEAR_SNEP_RESP_SUCCESS);
 	g_assert_cmpint(resp->length, ==, GUINT_TO_BE(ndef->length));
 	g_assert_cmpuint(resp->length, ==, GUINT_TO_BE(ndef->length));
-	g_assert(!memcmp(resp->info, text, ndef->length));
+	g_assert_cmpmem(resp->info, GUINT_FROM_BE(resp->length), text, ndef->length);
 
 	g_free(req);
 	g_free(resp);
Signature · 1 line
2.27.0
#50 lore raw

PATCH v2 50/73 unit: use proper pointer to uint8_t in test_snep_read_recv_fragments()

In reply to Krzysztof Kozlowski

Raw data bytes should be passed as pointer to uint8_t and the calling function already uses that type. This fixes warning:

unit/test-snep-read.c: In function ‘test_snep_read_recv_fragments’:
unit/test-snep-read.c:408:21: error: pointer of type ‘void *’ used in arithmetic [-Werror=pointer-arith]
408 | memcpy(data_recvd + offset, resp, nbytes);
| ^

---
 unit/test-snep-read.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
unit/test-snep-read.c +1 -1
index 5511fecf5c17..78db58ba859f 100644
@@ -386,7 +386,7 @@ static bool test_snep_read_send_fragment(size_t frag_len,
  * @param[out] data             Must be preallocated
  */
 static void test_snep_read_recv_fragments(uint32_t frag_len,
-				uint32_t remaining_bytes, void *data_recvd)
+				uint32_t remaining_bytes, uint8_t *data_recvd)
 {
 	struct p2p_snep_resp_frame *resp;
 	uint32_t offset = 0;
Signature · 1 line
2.27.0
#51 lore raw

PATCH v2 51/73 unit: do not shadow global 'text' variable (-Wshadow)

In reply to Krzysztof Kozlowski

Fix -Wshadow warning:

unit/test-ndef-parse.c: In function ‘test_ndef_title_sp’:
unit/test-ndef-parse.c:194:33: error: declaration of ‘text’ shadows a global declaration [-Werror=shadow]
194 | struct near_ndef_text_payload *text;
| ^~~~
unit/test-ndef-parse.c:42:16: note: shadowed declaration is here
42 | static uint8_t text[] = {0xd1, 0x1, 0x13, 0x54, 0x5, 0x65, 0x6e, 0x2d,
| ^~~~

---
 unit/test-ndef-parse.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
unit/test-ndef-parse.c +4 -4
index 96288f29f44d..67de3f2e77bd 100644
@@ -146,9 +146,9 @@ static uint8_t uri[] = {0xd1, 0x1, 0xa, 0x55, 0x1, 0x69, 0x6e, 0x74,
 			0x65, 0x6c, 0x2e, 0x63, 0x6f, 0x6d};
 
 /* 'hello żółw' - UTF-8 - en-US Text NDEF */
-static uint8_t text[] = {0xd1, 0x1, 0x13, 0x54, 0x5, 0x65, 0x6e, 0x2d,
-			 0x55, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0xc5,
-			 0xbc, 0xc3, 0xb3, 0xc5, 0x82, 0x77};
+static uint8_t text_utf8[] = {0xd1, 0x1, 0x13, 0x54, 0x5, 0x65, 0x6e, 0x2d,
+			0x55, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0xc5,
+			0xbc, 0xc3, 0xb3, 0xc5, 0x82, 0x77};
 
 /* 'hello żółw' - UTF-16 - en-US Text NDEF UTF-16 malformed*/
 static uint8_t text_utf16_invalid[] = {0xd1, 0x1, 0x19, 0x54, 0x85,
@@ -232,7 +232,7 @@ static void test_ndef_text(void)
 	GList *records;
 	struct near_ndef_record *record;
 
-	records = near_ndef_parse_msg(text, sizeof(text), NULL);
+	records = near_ndef_parse_msg(text_utf8, sizeof(text_utf8), NULL);
 
 	g_assert(records);
 	g_assert_cmpuint(g_list_length(records), ==, 1);
Signature · 1 line
2.27.0
#52 lore raw

PATCH v2 52/73 unit: do not shadow global 'uri' variable (-Wshadow)

In reply to Krzysztof Kozlowski

Fix -Wshadow warnings like:

unit/test-ndef-parse.c: In function ‘test_ndef_single_sp’:
unit/test-ndef-parse.c:291:32: error: declaration of ‘uri’ shadows a global declaration [-Werror=shadow]
291 | struct near_ndef_uri_payload *uri;
| ^~~
unit/test-ndef-parse.c:145:16: note: shadowed declaration is here
145 | static uint8_t uri[] = {0xd1, 0x1, 0xa, 0x55, 0x1, 0x69, 0x6e, 0x74,
| ^~~

---
 unit/test-ndef-parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
unit/test-ndef-parse.c +2 -2
index 67de3f2e77bd..f8b3b7be3a4c 100644
@@ -142,7 +142,7 @@ struct near_ndef_ac_payload {
 };
 
 /* http://www.intel.com URI NDEF */
-static uint8_t uri[] = {0xd1, 0x1, 0xa, 0x55, 0x1, 0x69, 0x6e, 0x74,
+static uint8_t test_uri[] = {0xd1, 0x1, 0xa, 0x55, 0x1, 0x69, 0x6e, 0x74,
 			0x65, 0x6c, 0x2e, 0x63, 0x6f, 0x6d};
 
 /* 'hello żółw' - UTF-8 - en-US Text NDEF */
@@ -203,7 +203,7 @@ static void test_ndef_uri(void)
 	GList *records;
 	struct near_ndef_record *record;
 
-	records = near_ndef_parse_msg(uri, sizeof(uri), NULL);
+	records = near_ndef_parse_msg(test_uri, sizeof(test_uri), NULL);
 
 	g_assert(records);
 	g_assert_cmpuint(g_list_length(records), ==, 1);
Signature · 1 line
2.27.0
#53 lore raw

PATCH v2 53/73 unit: use proper format for integers (-Wformat)

In reply to Krzysztof Kozlowski

Properly print signed and unsigned integers. This fixes warnings like:

    unit/test-ndef-parse.c: In function ‘test_ndef_single_sp’:
    unit/test-ndef-parse.c:318:33: error: field precision specifier ‘.*’ expects argument of type ‘int’, but argument 2 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
      318 |   g_print("NDEF SP URI field: %.*s\n", uri->field_length,
          |                               ~~^~     ~~~~~~~~~~~~~~~~~
          |                                 |         |
          |                                 int       uint32_t {aka unsigned int}

    unit/test-snep-read.c: In function ‘test_snep_dummy_req_put’:
    unit/test-snep-read.c:42:12: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘uint32_t’ {aka ‘unsigned int’} [-Werror=format=]
       42 |   g_printf("[SNEP unit] " fmt, ##__VA_ARGS__); \
          |            ^~~~~~~~~~~~~~
    ......
      118 |     frag_cnt, fragment->nfc_data_length,
          |               ~~~~~~~~~~~~~~~~~~~~~~~~~
          |                       |
          |                       uint32_t {aka unsigned int}

    unit/test-snep-read.c: In function ‘test_snep_read_verify_resp’:
    unit/test-snep-read.c:42:12: error: format ‘%X’ expects argument of type ‘unsigned int’, but argument 3 has type ‘int’ [-Werror=format=]
       42 |   g_printf("[SNEP unit] " fmt, ##__VA_ARGS__); \
          |            ^~~~~~~~~~~~~~
    ......
      454 |    resp->response, exp_resp_code);
          |                    ~~~~~~~~~~~~~
          |                    |
          |                    int
---
 unit/test-ndef-parse.c | 8 ++++----
 unit/test-snep-read.c  | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)
unit/test-ndef-parse.c +4 -4
index f8b3b7be3a4c..24f7d2f2c3ac 100644
@@ -302,8 +302,8 @@ static void test_ndef_single_sp(void)
 					uri->field_length) == 0);
 
 	if (g_test_verbose())
-		g_print("NDEF SP URI field: %.*s\n", uri->field_length,
-							(char *) uri->field);
+		g_print("NDEF SP URI field: %.*s\n", (int)uri->field_length,
+			(char *) uri->field);
 
 	g_free(uri->field);
 	g_free(uri);
@@ -346,8 +346,8 @@ static void test_ndef_title_sp(void)
 					uri->field_length) == 0);
 
 	if (g_test_verbose())
-		g_print("NDEF SP URI field: %.*s\n", uri->field_length,
-							(char *) uri->field);
+		g_print("NDEF SP URI field: %.*s\n", (int)uri->field_length,
+			(char *) uri->field);
 
 	g_assert_cmpstr(text->data, ==, "Intel");
 	g_assert_cmpstr(text->encoding, ==, "UTF-8");
unit/test-snep-read.c +3 -3
index 78db58ba859f..414b801a5e71 100644
@@ -114,7 +114,7 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 		static int frag_cnt;
 		struct p2p_snep_data *fragment = test_fragments->data;
 
-		TEST_SNEP_LOG("\tdummy_req_put frag=%d, len=%d, current=%d\n",
+		TEST_SNEP_LOG("\tdummy_req_put frag=%d, len=%u, current=%u\n",
 				frag_cnt, fragment->nfc_data_length,
 				fragment->nfc_data_current_length);
 		test_fragments = g_slist_remove(test_fragments, fragment);
@@ -437,7 +437,7 @@ static void test_snep_read_no_response(void)
  * @param[in] exp_resp_info_len  Expected response info length
  * @param[in] exp_resp_info      Expected response info
  */
-static void test_snep_read_verify_resp(int exp_resp_code,
+static void test_snep_read_verify_resp(uint8_t exp_resp_code,
 		uint32_t exp_resp_info_len, uint8_t *exp_resp_info)
 {
 	struct p2p_snep_resp_frame *resp;
@@ -467,7 +467,7 @@ static void test_snep_read_verify_resp(int exp_resp_code,
  *
  * @param[in] exp_resp_code  Expected response code
  */
-static void test_snep_read_verify_resp_code(int exp_resp_code)
+static void test_snep_read_verify_resp_code(uint8_t exp_resp_code)
 {
 	test_snep_read_verify_resp(exp_resp_code, 0, NULL);
 }
Signature · 1 line
2.27.0
#54 lore raw

PATCH v2 54/73 unit: fix memory leaks in test-ndef-parse

In reply to 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)
---
 unit/test-ndef-parse.c | 39 +++++----------------------------------
 1 file changed, 5 insertions(+), 34 deletions(-)
unit/test-ndef-parse.c +5 -34
index 24f7d2f2c3ac..ace0f9038ad9 100644
@@ -189,15 +189,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;
@@ -222,9 +213,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(void)
@@ -255,11 +244,7 @@ static void test_ndef_text(void)
 						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_invalid_utf16(void)
@@ -305,10 +290,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)
@@ -359,16 +341,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)
@@ -395,9 +368,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)
Signature · 1 line
2.27.0
#55 lore raw

PATCH v2 55/73 unit: do not open-code freeing ndef message

In reply to Krzysztof Kozlowski

Use near_ndef_msg_free() instead of open-coding it.

---

Changes since v1:
1. Change also test_snep_cleanup()

---
 unit/test-snep-read.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
unit/test-snep-read.c +3 -6
index 414b801a5e71..213b3e5b3d74 100644
@@ -222,10 +222,8 @@ static void test_snep_cleanup(gpointer context, gconstpointer data)
 	if (stored_recd)
 		test_ndef_free_record(stored_recd);
 
-	if (ctx->test_recd_msg) {
-		g_free(ctx->test_recd_msg->data);
-		g_free(ctx->test_recd_msg);
-	}
+	if (ctx->test_recd_msg)
+		near_ndef_msg_free(ctx->test_recd_msg);
 
 	g_slist_free(test_fragments);
 
@@ -896,8 +894,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)
Signature · 1 line
2.27.0
#56 lore raw

PATCH v2 56/73 unit: fix memory leaks in test-ndef-build

In reply to Krzysztof Kozlowski

test-ndef-build.c was not freeing the ndef records it got leading to memory leaks. Report by valgrind:

(24 direct, 15 indirect) bytes in 1 blocks are definitely lost in loss record 24 of 38

    at 0x483ED99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x11C176: ndef_message_alloc_complete.constprop.0 (ndef.c:1654)
    by 0x11FEC5: ndef_message_alloc (ndef.c:1760)
    by 0x11FEC5: near_ndef_prepare_text_record (ndef.c:3142)
    by 0x121676: test_ndef_text_build (test-ndef-build.c:63)
    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 0x10F5A1: main (test-ndef-build.c:113)
---
 unit/test-ndef-build.c | 6 ++++++
 1 file changed, 6 insertions(+)
unit/test-ndef-build.c +6 -0
index 44dce4bf9aef..54b502f4a40b 100644
@@ -65,6 +65,8 @@ static void test_ndef_text_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(text));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(text), text, ARRAY_SIZE(text));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_passphrase_build(void)
@@ -76,6 +78,8 @@ static void test_ndef_wsc_with_passphrase_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc), wsc, ARRAY_SIZE(wsc));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_out_passphrase_build(void)
@@ -87,6 +91,8 @@ static void test_ndef_wsc_with_out_passphrase_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc_wo));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc_wo), wsc_wo, ARRAY_SIZE(wsc_wo));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_out_ssid_build(void)
Signature · 1 line
2.27.0
#57 lore raw

PATCH v2 57/73 unit: fix memory leaks in test-snep-read error paths

In reply to Krzysztof Kozlowski

Cleanup and free memory in error paths in test-snep-read.c.

---
 unit/test-snep-read.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
unit/test-snep-read.c +6 -2
index 213b3e5b3d74..a463c1df30b8 100644
@@ -131,12 +131,12 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	records = near_ndef_parse_msg(nfc_data, nfc_data_length, NULL);
 	if (!records) {
 		TEST_SNEP_LOG("\tdummy_req_put parsing ndef failed\n");
-		goto error;
+		goto error_free_nfc_data;
 	}
 
 	if (g_list_length(records) != 1) {
 		TEST_SNEP_LOG("\tdummy_req_put records number mismatch");
-		goto error;
+		goto error_free_records;
 	}
 
 	g_free(nfc_data);
@@ -149,6 +149,10 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	near_snep_core_response_noinfo(fd, NEAR_SNEP_RESP_SUCCESS);
 	return true;
 
+error_free_records:
+	near_ndef_records_free(records);
+error_free_nfc_data:
+	g_free(nfc_data);
 error:
 	TEST_SNEP_LOG("\tdummy_req_put error!!!\n");
 	return false;
Signature · 1 line
2.27.0
#58 lore raw

PATCH v2 58/73 unit: fix record memory leak in test-snep-read

In reply to Krzysztof Kozlowski

Instead of open-coding __near_ndef_record_free() with mistakes, use it directly to fix memory leaks like:

2 bytes in 1 blocks are definitely lost in loss record 2 of 36

    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 0x11CB66: parse_record_header (ndef.c:1122)
    by 0x11CB66: parse_record_header (ndef.c:1029)
    by 0x11E549: near_ndef_parse_msg (ndef.c:2846)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    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)

15 bytes in 1 blocks are definitely lost in loss record 13 of 36

    at 0x483ED99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x11E65F: near_ndef_parse_msg (ndef.c:2958)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    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 0x10F784: main (test-snep-read.c:967)
---
 unit/test-snep-read.c | 2 +-
 unit/test-utils.c     | 8 --------
 unit/test-utils.h     | 2 --
 3 files changed, 1 insertion(+), 11 deletions(-)
unit/test-snep-read.c +1 -1
index a463c1df30b8..f64ef0c6fce2 100644
@@ -224,7 +224,7 @@ static void test_snep_cleanup(gpointer context, gconstpointer data)
 	__near_snep_core_cleanup();
 
 	if (stored_recd)
-		test_ndef_free_record(stored_recd);
+		__near_ndef_record_free(stored_recd);
 
 	if (ctx->test_recd_msg)
 		near_ndef_msg_free(ctx->test_recd_msg);
unit/test-utils.c +0 -8
index fe256561821f..369437421971 100644
@@ -20,14 +20,6 @@
 
 #include "test-utils.h"
 
-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);
-}
-
 struct near_ndef_message *test_ndef_create_test_record(const char *str)
 {
 	struct near_ndef_message *ndef;
unit/test-utils.h +0 -2
index c371d566a573..108f2a1fb139 100644
@@ -143,8 +143,6 @@ struct near_ndef_record {
 	size_t data_len;
 };
 
-void test_ndef_free_record(struct near_ndef_record *record);
-
 struct near_ndef_message *test_ndef_create_test_record(const char *str);
 
 #endif
Signature · 1 line
2.27.0
#59 lore raw

PATCH v2 59/73 unit: fix records GList memory leak in test-snep-read

In reply to Krzysztof Kozlowski

The test_snep_dummy_req_put() stores one record in global stored_recd pointer, so the GList itself should be freed. This fixes Valgrind warning:

24 bytes in 1 blocks are definitely lost in loss record 21 of 30

    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 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48BFF07: g_list_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x11E68A: near_ndef_parse_msg (ndef.c:2964)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    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)
---
 unit/test-snep-read.c | 1 +
 1 file changed, 1 insertion(+)
unit/test-snep-read.c +1 -0
index f64ef0c6fce2..128937ed910f 100644
@@ -142,6 +142,7 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	g_free(nfc_data);
 
 	stored_recd = records->data;
+	g_list_free(records);
 
 	TEST_SNEP_LOG("\t\tdummy_req_put STORED REC data=%p length=%zu\n",
 			stored_recd->data, stored_recd->data_len);
Signature · 1 line
2.27.0
#60 lore raw

PATCH v2 60/73 unit: do not pass NULL to memcpy()

In reply to Krzysztof Kozlowski

memcpy() should not receive NULL as source pointer and such is passed from test_snep_read_get_req_frags_client_resp() and test_snep_read_verify_resp(). ASAN reports:

unit/test-snep-read.c:325:2: runtime error: null pointer passed as argument 2, which is declared to never be null unit/test-snep-read.c:266:2: runtime error: null pointer passed as argument 2, which is declared to never be null

---
 unit/test-snep-read.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
unit/test-snep-read.c +4 -2
index 128937ed910f..ea41ae03a8b2 100644
@@ -261,7 +261,8 @@ static struct p2p_snep_req_frame *test_snep_build_req_frame(
 	req->version = ver;
 	req->request = req_type;
 	req->length = GUINT_TO_BE(info_len);
-	memcpy(req->ndef, data, payload_len);
+	if (data)
+		memcpy(req->ndef, data, payload_len);
 
 	return req;
 }
@@ -320,7 +321,8 @@ static struct p2p_snep_resp_frame *test_snep_build_resp_frame(
 	resp->version = ver;
 	resp->response = resp_type;
 	resp->length = GUINT_TO_BE(info_len);
-	memcpy(resp->info, data, info_len);
+	if (data)
+		memcpy(resp->info, data, info_len);
 
 	return resp;
 }
Signature · 1 line
2.27.0
#61 lore raw

PATCH v2 61/73 unit: do not search for headers locally where they do not exist

In reply to Krzysztof Kozlowski

near/ndef.h and src/near.h are coming from include path, so no point to look for them in current folder. Also reverse the order to match unit/test-snep-read.c

---
 unit/test-ndef-build.c | 4 ++--
 unit/test-ndef-parse.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
unit/test-ndef-build.c +2 -2
index 54b502f4a40b..5174f053841e 100644
@@ -30,8 +30,8 @@
 #include <glib.h>
 #include <glib/gprintf.h>
 
-#include "src/near.h"
-#include "include/ndef.h"
+#include <near/ndef.h>
+#include <src/near.h>
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
unit/test-ndef-parse.c +2 -2
index ace0f9038ad9..de3cac81b90d 100644
@@ -30,8 +30,8 @@
 #include <glib.h>
 #include <glib/gprintf.h>
 
-#include "src/near.h"
-#include "include/ndef.h"
+#include <near/ndef.h>
+#include <src/near.h>
 
 enum record_type {
 	RECORD_TYPE_WKT_SMART_POSTER          =   0x01,
Signature · 1 line
2.27.0
#62 lore raw

PATCH v2 62/73 unit: remove duplicated invalid definitions in test-snep-read

In reply to Krzysztof Kozlowski

The unit tests duplicated several definitions in unit/test-utils.h which after some time become outdated and not matching the original ones. This lead to bogus data printed in logs, for example length of near_ndef_record:

    [SNEP unit]	dummy_req_put STORED REC data=0x55ceb3fc8050 length=94346271294192

Move all of them into new src/ndef-private.h header. Start using SPDX identifier instead of full GPL license boilerplate.

---
 Makefile.am           |   2 +-
 src/ndef-private.h    | 140 ++++++++++++++++++++++++++++++++++++++++++
 src/ndef.c            | 137 +----------------------------------------
 unit/test-snep-read.c |   2 +
 unit/test-utils.h     |  81 +-----------------------
 5 files changed, 145 insertions(+), 217 deletions(-)
 create mode 100644 src/ndef-private.h
Makefile.am +1 -1
index fa552ee38f98..26aa4ca82e80 100644
@@ -37,7 +37,7 @@ pkglibexecdir = ${libexecdir}/nfc
 pkglibexec_PROGRAMS = src/neard
 
 src_neard_SOURCES = $(gdbus_sources) $(gweb_sources) $(builtin_sources) \
-			src/main.c src/error.c src/near.h src/log.c \
+			src/main.c src/error.c src/ndef-private.h src/near.h src/log.c \
 			src/dbus.c src/manager.c src/adapter.c src/device.c \
 			src/tag.c src/plugin.c src/netlink.c src/ndef.c \
 			src/tlv.c src/bluetooth.c src/agent.c src/snep.c
src/ndef-private.h new file +140 -0

140 lines not on this page · raw message

src/ndef.c +1 -136

149 lines not on this page · raw message

unit/test-snep-read.c +2 -0
index ea41ae03a8b2..21be58785eda 100644
@@ -35,6 +35,8 @@
 
 #include <near/types.h>
 
+#include <src/near.h>
+#include <src/ndef-private.h>
 #include "test-utils.h"
 
 #define TEST_SNEP_LOG(fmt, ...) do { \
unit/test-utils.h +1 -80

93 lines not on this page · raw message

Signature · 1 line
2.27.0
#63 lore raw

PATCH v2 63/73 unit: remove duplicated definitions in test-ndef-parse

In reply to Krzysztof Kozlowski

The unit/test-ndef-parse.c duplicated several definitions which is error-prone.

---
 unit/test-ndef-parse.c | 109 +----------------------------------------
 1 file changed, 1 insertion(+), 108 deletions(-)
unit/test-ndef-parse.c +1 -108
index de3cac81b90d..53a5b584437a 100644
@@ -32,114 +32,7 @@
 
 #include <near/ndef.h>
 #include <src/near.h>
-
-enum record_type {
-	RECORD_TYPE_WKT_SMART_POSTER          =   0x01,
-	RECORD_TYPE_WKT_URI                   =   0x02,
-	RECORD_TYPE_WKT_TEXT                  =   0x03,
-	RECORD_TYPE_WKT_SIZE                  =   0x04,
-	RECORD_TYPE_WKT_TYPE                  =   0x05,
-	RECORD_TYPE_WKT_ACTION                =   0x06,
-	RECORD_TYPE_WKT_HANDOVER_REQUEST      =   0x07,
-	RECORD_TYPE_WKT_HANDOVER_SELECT       =   0x08,
-	RECORD_TYPE_WKT_HANDOVER_CARRIER      =   0x09,
-	RECORD_TYPE_WKT_ALTERNATIVE_CARRIER   =   0x0a,
-	RECORD_TYPE_WKT_COLLISION_RESOLUTION  =   0x0b,
-	RECORD_TYPE_WKT_ERROR                 =   0x0c,
-	RECORD_TYPE_MIME_TYPE                 =   0x0d,
-	RECORD_TYPE_EXT_AAR                   =   0x0e,
-	RECORD_TYPE_UNKNOWN                   =   0xfe,
-	RECORD_TYPE_ERROR                     =   0xff
-};
-
-struct near_ndef_record_header {
-	uint8_t mb;
-	uint8_t me;
-	uint8_t cf;
-	uint8_t sr;
-	uint8_t il;
-	uint8_t tnf;
-	uint8_t il_length;
-	uint8_t *il_field;
-	uint32_t payload_len;
-	uint32_t offset;
-	uint8_t	type_len;
-	enum record_type rec_type;
-	char *type_name;
-	uint32_t header_len;
-};
-
-struct near_ndef_text_payload {
-	char *encoding;
-	char *language_code;
-	char *data;
-};
-
-struct near_ndef_uri_payload {
-	uint8_t identifier;
-
-	uint32_t  field_length;
-	uint8_t  *field;
-};
-
-struct near_ndef_sp_payload {
-	struct near_ndef_uri_payload *uri;
-
-	uint8_t number_of_title_records;
-	struct near_ndef_text_payload **title_records;
-
-	uint32_t size; /* from Size record*/
-	char *type;    /* from Type record*/
-	char *action;
-};
-
-struct near_ndef_aar_payload {
-	char *package;
-};
-
-struct near_ndef_record {
-	char *path;
-
-	struct near_ndef_record_header *header;
-
-	/* specific payloads */
-	struct near_ndef_text_payload *text;
-	struct near_ndef_uri_payload  *uri;
-	struct near_ndef_sp_payload   *sp;
- 	struct near_ndef_mime_payload *mime;
-	struct near_ndef_ho_payload   *ho;	/* handover payload */
-	struct near_ndef_aar_payload  *aar;
-
-	char *type;
-
-	uint8_t *data;
-	size_t data_len;
-};
-
-struct near_ndef_ho_payload {
-	uint8_t version;		/* version id */
-	uint16_t collision_record;	/* collision record */
-
-	uint8_t number_of_ac_payloads;	/* At least 1 ac is needed */
-	struct near_ndef_ac_payload **ac_payloads;
-
-	/* Optional records */
-	uint16_t *err_record;	/* not NULL if present */
-
-	uint8_t number_of_cfg_payloads;	/* extra NDEF records */
-	struct near_ndef_mime_payload **cfg_payloads;
-};
-
-struct near_ndef_ac_payload {
-	enum carrier_power_state cps;	/* carrier power state */
-
-	uint8_t cdr_len;	/* carrier data reference length: 0x01 */
-	uint8_t *cdr;		/* carrier data reference */
-	uint8_t adata_refcount;	/* auxiliary data reference count */
-
-	/* !: if adata_refcount == 0, then there's no data reference */
-	uint16_t **adata;	/* auxiliary data reference */
-};
+#include <src/ndef-private.h>
 
 /* http://www.intel.com URI NDEF */
 static uint8_t test_uri[] = {0xd1, 0x1, 0xa, 0x55, 0x1, 0x69, 0x6e, 0x74,
Signature · 1 line
2.27.0
#64 lore raw

PATCH v2 64/73 unit: add few asserts in test-snep-read

In reply to Krzysztof Kozlowski

For consistency, check for returned values of test_snep_build_req_frame()-like functions and __near_snep_core_init(). No functional change expected as all these are already tests.

---
 unit/test-snep-read.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
unit/test-snep-read.c +10 -1
index 21be58785eda..6d144b22f4e9 100644
@@ -205,7 +205,7 @@ static void test_snep_init(gpointer context, gconstpointer data)
 	if (ret != 0)
 		TEST_SNEP_LOG("set sock SO_RCVTIMEO failed");
 
-	__near_snep_core_init();
+	g_assert_cmpint(__near_snep_core_init(), ==, 0);
 
 	stored_recd = NULL;
 
@@ -499,6 +499,7 @@ static void test_snep_read_put_req_ok(gpointer context, gconstpointer gp)
 	req = test_snep_build_req_frame(frame_len, NEAR_SNEP_VERSION,
 					NEAR_SNEP_REQ_PUT, ctx->req_info_len,
 					ctx->req_info, payload_len);
+	g_assert(req);
 
 	ret = test_snep_read_req_common(req, frame_len, test_snep_dummy_req_get,
 					test_snep_dummy_req_put);
@@ -529,6 +530,7 @@ static void test_snep_read_put_req_unsupp_ver(gpointer context,
 
 	req = test_snep_build_req_frame(frame_len, 0xF8, NEAR_SNEP_REQ_PUT,
 				ctx->req_info_len, ctx->req_info, payload_len);
+	g_assert(req);
 
 	ret = test_snep_read_req_common(req, frame_len, test_snep_dummy_req_get,
 					test_snep_dummy_req_put);
@@ -562,6 +564,7 @@ static void test_snep_read_put_req_not_impl(gpointer context,
 	req = test_snep_build_req_frame(frame_len, NEAR_SNEP_VERSION,
 					NEAR_SNEP_REQ_PUT, ctx->req_info_len,
 					ctx->req_info, payload_len);
+	g_assert(req);
 
 	ret = test_snep_read_req_common(req, frame_len, test_snep_dummy_req_get,
 					NULL);
@@ -597,6 +600,7 @@ static void test_snep_read_put_req_fragmented(gpointer context,
 	req = test_snep_build_req_frame(frame_len, NEAR_SNEP_VERSION,
 					NEAR_SNEP_REQ_PUT, ctx->req_info_len,
 					ctx->req_info, payload_len);
+	g_assert(req);
 
 	/* send 1st fragment within PUT request */
 	ret = test_snep_read_req_common(req, frame_len, test_snep_dummy_req_get,
@@ -654,6 +658,7 @@ static void test_snep_read_get_req_ok(gpointer context, gconstpointer gp)
 	req = test_snep_build_req_get_frame(frame_len, NEAR_SNEP_VERSION,
 				NEAR_SNEP_REQ_GET, info_len,
 				ctx->acc_len, ctx->req_info, payload_len);
+	g_assert(req);
 
 	ret = test_snep_read_req_common(req, frame_len, test_snep_dummy_req_get,
 					test_snep_dummy_req_put);
@@ -693,6 +698,7 @@ static void test_snep_read_get_req_not_impl(gpointer context,
 	req = test_snep_build_req_get_frame(frame_len, NEAR_SNEP_VERSION,
 			NEAR_SNEP_REQ_GET, ctx->req_info_len, ctx->acc_len,
 			ctx->req_info, payload_len);
+	g_assert(req);
 
 	/* call snep_core_read with NULL req_get handler */
 	ret = test_snep_read_req_common(req, frame_len, NULL,
@@ -748,6 +754,7 @@ static void test_snep_read_get_req_frags_client_resp(gpointer context,
 	req = test_snep_build_req_get_frame(frame_len, NEAR_SNEP_VERSION,
 				NEAR_SNEP_REQ_GET, info_len,
 				ctx->acc_len, ctx->req_info, payload_len);
+	g_assert(req);
 
 	/* send GET request */
 	ret = test_snep_read_req_common(req, frame_len, test_snep_dummy_req_get,
@@ -757,6 +764,7 @@ static void test_snep_read_get_req_frags_client_resp(gpointer context,
 
 	frame_len = NEAR_SNEP_RESP_HEADER_LENGTH + payload_len;
 	resp = test_snep_build_resp_frame(frame_len, 0, 0, 0, NULL);
+	g_assert(resp);
 
 	/* start receiving fragments */
 	nbytes = recv(sockfd[client], resp, frame_len, 0);
@@ -778,6 +786,7 @@ static void test_snep_read_get_req_frags_client_resp(gpointer context,
 	frame_len = NEAR_SNEP_REQ_PUT_HEADER_LENGTH;
 	req = test_snep_build_req_frame(frame_len, NEAR_SNEP_VERSION,
 					client_resp, 0, NULL, 0);
+	g_assert(req);
 
 	ret = test_snep_read_req_common(req, frame_len, NULL, NULL);
 	g_free(req);
Signature · 1 line
2.27.0
#65 lore raw

PATCH v2 65/73 HACKING: refine required packages

In reply to Krzysztof Kozlowski

Debian since Jessie (8.0 from 2015) seems to have automake v1.14, so mentioning some specific configuration for it is not needed. In the same time other required libraries and tools are not mentioned, so let's refresh the requirements list.

---
 HACKING | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
HACKING +12 -11
index 478653c8a292..c1eb6d6189a6 100644
@@ -5,17 +5,18 @@ Hacking on Near Field Communication manager
 Build tools requirements
 ========================
 
-When building and testing directly from the repository it is important to
-have at least automake version 1.10 or later installed. All modern
-distributions should default to the latest version, but it seems that
-Debian's default is still an earlier version:
-
-  Check version
-    # dpkg -l '*automake*'
-
-  Install new version
-    # apt-get install automake1.10
-    # update-alternatives --config automake
+Required packages and tools:
+  autoconf
+  automake
+  dbus
+  gcc/clang
+  glib 2.0
+  libtool
+  libnl-3
+  libnl-genl-3
+  make
+
+See also installation scripts for  Continuous Integration in ci/ directory.
 
 
 Working with the source code repository
Signature · 1 line
2.27.0
#66 lore raw

PATCH v2 66/73 build: fix setting CFLAGS on dash shell (Alpine Linux)

In reply to Krzysztof Kozlowski

Syntax like "CFLAGS+=" does not work on simple shells, e.g. dash from BusyBox. This seems to fail to properly configure CFLAGS on Alpine Linux:

    checking for pkg-config... /usr/bin/pkg-config
    checking pkg-config is at least version 0.9.0... yes
    ./configure: line 3441: CFLAGS+= -Werror -Wextra: not found
    ./configure: line 3442: CFLAGS+= -Wno-unused-parameter: not found
    ./configure: line 3443: CFLAGS+= -Wno-missing-field-initializers: not found
    ./configure: line 3444: CFLAGS+= -Wdeclaration-after-statement: not found
    ./configure: line 3445: CFLAGS+= -Wmissing-declarations: not found
    ./configure: line 3446: CFLAGS+= -Wredundant-decls: not found
    ./configure: line 3447: CFLAGS+= -Wcast-align: not found
    ./configure: line 3448: CFLAGS+= -DG_DISABLE_DEPRECATED: not found
    checking for gcc... gcc
---
 acinclude.m4 | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
acinclude.m4 +9 -8
index fbc7660dfb67..027ed69977db 100644
@@ -15,13 +15,14 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [
 		CFLAGS="-Wall -O2 -D_FORTIFY_SOURCE=2"
 	fi
 	if (test "$USE_MAINTAINER_MODE" = "yes"); then
-		CFLAGS+=" -Werror -Wextra"
-		CFLAGS+=" -Wno-unused-parameter"
-		CFLAGS+=" -Wno-missing-field-initializers"
-		CFLAGS+=" -Wdeclaration-after-statement"
-		CFLAGS+=" -Wmissing-declarations"
-		CFLAGS+=" -Wredundant-decls"
-		CFLAGS+=" -Wcast-align"
-		CFLAGS+=" -DG_DISABLE_DEPRECATED"
+		CFLAGS="$CFLAGS -Werror -Wextra"
+		CFLAGS="$CFLAGS -Werror -Wextra"
+		CFLAGS="$CFLAGS -Wno-unused-parameter"
+		CFLAGS="$CFLAGS -Wno-missing-field-initializers"
+		CFLAGS="$CFLAGS -Wdeclaration-after-statement"
+		CFLAGS="$CFLAGS -Wmissing-declarations"
+		CFLAGS="$CFLAGS -Wredundant-decls"
+		CFLAGS="$CFLAGS -Wcast-align"
+		CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"
 	fi
 ])
Signature · 1 line
2.27.0
#67 lore raw

PATCH v2 67/73 build: add more compiler warnings

In reply to Krzysztof Kozlowski

Use the AX_CHECK_COMPILE_FLAG() macro from autoconf-archive to check for support for more compiler warning flags (not enabled via -Wall and -Wextra) and enable these which pass.

These flags are warning for:
1. Code bugs like dereferencing NULL or truncating string operations functions.

2. Minor code quality or portability issues like using undefined defines, wrong casts of functions, missing global function declarations, skipping variable initializations, duplicated if conditions or branches, usage of variable-length arrays.

3. Portability issues like implicit promoting float to double, allocating zero bytes or depending of size of void *.

Keep more warnings for later, because the code does not build with them.

The AX_CHECK_COMPILE_FLAG() macro tries to compile C code with given flag, so move the code from acinclude.m4 (executed early, before AC_LANG and others) to separate accflags.m4.

---
 HACKING      |  1 +
 accflags.m4  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 acinclude.m4 | 17 -----------------
 configure.ac |  5 +++--
 4 files changed, 49 insertions(+), 19 deletions(-)
 create mode 100644 accflags.m4
HACKING +1 -0
index c1eb6d6189a6..7326242506a6 100644
@@ -7,6 +7,7 @@ Build tools requirements
 
 Required packages and tools:
   autoconf
+  autoconf-archive
   automake
   dbus
   gcc/clang
accflags.m4 new file +45 -0

45 lines not on this page · raw message

acinclude.m4 +0 -17
index 027ed69977db..a12b93972cfa 100644
@@ -9,20 +9,3 @@ AC_DEFUN([NEARD_PROG_CC_PIE], [
 		rm -rf conftest*
 	])
 ])
-
-AC_DEFUN([NEARD_COMPILER_FLAGS], [
-	if (test "${CFLAGS}" = ""); then
-		CFLAGS="-Wall -O2 -D_FORTIFY_SOURCE=2"
-	fi
-	if (test "$USE_MAINTAINER_MODE" = "yes"); then
-		CFLAGS="$CFLAGS -Werror -Wextra"
-		CFLAGS="$CFLAGS -Werror -Wextra"
-		CFLAGS="$CFLAGS -Wno-unused-parameter"
-		CFLAGS="$CFLAGS -Wno-missing-field-initializers"
-		CFLAGS="$CFLAGS -Wdeclaration-after-statement"
-		CFLAGS="$CFLAGS -Wmissing-declarations"
-		CFLAGS="$CFLAGS -Wredundant-decls"
-		CFLAGS="$CFLAGS -Wcast-align"
-		CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED"
-	fi
-])
configure.ac +3 -2
index c4e8993305b1..b9419c1fad74 100644
@@ -22,8 +22,6 @@ AC_SUBST(se_plugindir)
 
 PKG_PROG_PKG_CONFIG
 
-NEARD_COMPILER_FLAGS
-
 AC_LANG([C])
 
 AC_PROG_CC
@@ -34,6 +32,9 @@ AC_PROG_MKDIR_P
 m4_define([_LT_AC_TAGCONFIG], [])
 m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])])
 
+m4_include([accflags.m4])
+NEARD_COMPILER_FLAGS
+
 LT_INIT([disable-static])
 
 AM_CONDITIONAL(READLINE, test "${enable_readline}" = "yes")
Signature · 1 line
2.27.0
#68 lore raw

PATCH v2 68/73 build: enable -Wshadow and -Wformat-signedness compiler warnings

In reply to Krzysztof Kozlowski

Enable code quality warnings - shadowing variables and using wrong signed data in formats (leading to conversions).

---
 accflags.m4 | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
accflags.m4 +3 -4
index b1bb1500324f..e4df62c13cf3 100644
@@ -22,7 +22,10 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [
 		AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes], [CFLAGS="$CFLAGS -Wmissing-prototypes"])
 		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"])
 
+		# GCC v5.0
+		AX_CHECK_COMPILE_FLAG([-Wformat-signedness], [CFLAGS="$CFLAGS -Wformat-signedness"])
 		# GCC v6.0
 		AX_CHECK_COMPILE_FLAG([-Wnull-dereference], [CFLAGS="$CFLAGS -Wnull-dereference"])
 		AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], [CFLAGS="$CFLAGS -Wduplicated-cond"])
@@ -35,11 +38,7 @@ AC_DEFUN([NEARD_COMPILER_FLAGS], [
 	fi
 	if (test "$USE_MAINTAINER_MODE" = "pedantic"); then
 		AX_CHECK_COMPILE_FLAG([-Wstrict-overflow=3], [CFLAGS="$CFLAGS -Wstrict-overflow=3"])
-		AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"])
 		AX_CHECK_COMPILE_FLAG([-Wcast-qual], [CFLAGS="$CFLAGS -Wcast-qual"])
 		AX_CHECK_COMPILE_FLAG([-Wunsafe-loop-optimizations], [CFLAGS="$CFLAGS -Wunsafe-loop-optimizations"])
-
-		# GCC v5.0
-		AX_CHECK_COMPILE_FLAG([-Wformat-signedness], [CFLAGS="$CFLAGS -Wformat-signedness"])
 	fi
 ])
Signature · 1 line
2.27.0
#69 lore raw

PATCH v2 69/73 build: enable -Wformat=2 warnings

In reply to Krzysztof Kozlowski

The -Wformat=2 compiler warning can detect potentials errors when using printf-like functions. It is supported by GCC and clang.

---
 accflags.m4 | 1 +
 1 file changed, 1 insertion(+)
accflags.m4 +1 -0
index e4df62c13cf3..57cc48beecc2 100644
@@ -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"])
Signature · 1 line
2.27.0
#70 lore raw

PATCH v2 70/73 build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2 warnings

In reply to 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.

---
 accflags.m4 | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
accflags.m4 +9 -2
index 57cc48beecc2..0030ac339c86 100644
@@ -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
 ])
Signature · 1 line
2.27.0
#71 lore raw

PATCH v2 71/73 build: fix missing usage of PIE check result

In reply to Krzysztof Kozlowski

The test result whether compiler accepts -fPIE in acinclude.m4 is stored as neard_cv_prog_cc_pie variable. Using wrong name of that variable in a 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")
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configure.ac +1 -1
index b9419c1fad74..1ec6f4eb30ea 100644
@@ -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
Signature · 1 line
2.27.0
#72 lore raw

PATCH v2 72/73 build: add support for GCC sanitizers (asan, lsan and ubsan)

In reply to 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 <[email protected]>):
https://git.kernel.org/pub/scm/libs/ell/ell.git

---
 HACKING      |  5 ++++-
 acinclude.m4 | 36 ++++++++++++++++++++++++++++++++++++
 configure.ac | 45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 1 deletion(-)
HACKING +4 -1
index 7326242506a6..40bde2fb3c8b 100644
@@ -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
acinclude.m4 +36 -0
index a12b93972cfa..e9ad0d63cc8c 100644
@@ -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*
+])
+])
configure.ac +45 -0

57 lines not on this page · raw message

Signature · 1 line
2.27.0
#73 lore raw

PATCH v2 73/73 AUTHORS: Mention Krzysztof Kozlowski's contributions

In reply to Krzysztof Kozlowski
---
 AUTHORS | 1 +
 1 file changed, 1 insertion(+)
AUTHORS +1 -0
index 7b60db5e1755..ff8b64624207 100644
@@ -22,3 +22,4 @@ Mark A. Greer <[email protected]>
 Arron Wang <[email protected]>
 Vincent Cuissard <[email protected]>
 Oleg Zhurakivskyy <[email protected]>
+Krzysztof Kozlowski <[email protected]> <[email protected]>
Signature · 1 line
2.27.0
#74 lore raw
In reply to Krzysztof Kozlowski
Quoted 11 lines · Krzysztof Kozlowski

Hi,

Mark asked for resending fixes separate from setting up CI under Github Actions, so here is a combination of all my previously sent patches related only to the actual C code:

https://lore.kernel.org/linux-nfc/20210710033859.3989-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210714110518.104655-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210716100844.51360-1-krzysztof.kozlowski(a)canonical.com/T/#t

Quoted 8 lines

This includes fixes for GCC/clang warnings, memory leaks, memory corruption and few other minor fixes. The UTF-8 and UTF-16 is not entirely fixed and I removed the work-in-progress patches.

Changes since v1 are:
1. Group all patches based on prefix (unit file), instead of topic.
2. Put the build-related patches at the end.
3. Remove all CI-related patches.

I put CI-related changes in:
https://github.com/linux-nfc/neard/commits/krzk/github-ci-v2

It's based on master, so it fails building (fixes are in the set here). Should be rebased on top of this set before merging. Few patches got also squashed as now this set does not follow my exact development history.

Best regards,
Krzysztof

#75 lore raw
Quoted 21 lines · Krzysztof Kozlowski
Quoted 11 lines · Krzysztof Kozlowski

Hi,

Mark asked for resending fixes separate from setting up CI under Github Actions, so here is a combination of all my previously sent patches related only to the actual C code:

https://lore.kernel.org/linux-nfc/20210710033859.3989-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210714110518.104655-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210716100844.51360-1-krzysztof.kozlowski(a)canonical.com/T/#t

Quoted 8 lines

This includes fixes for GCC/clang warnings, memory leaks, memory corruption and few other minor fixes. The UTF-8 and UTF-16 is not entirely fixed and I removed the work-in-progress patches.

Changes since v1 are:
1. Group all patches based on prefix (unit file), instead of topic.
2. Put the build-related patches at the end.
3. Remove all CI-related patches.

Quoted 6 lines

I put CI-related changes in:
https://github.com/linux-nfc/neard/commits/krzk/github-ci-v2

It's based on master, so it fails building (fixes are in the set here). Should be rebased on top of this set before merging. Few patches got also squashed as now this set does not follow my exact development history.

Okay. I'll work on reviewing through the week but I likely won't get through many until next weekend.

Thanks for the quick turn-around.

Mark
--

Applied
#76 lore raw
In reply to Krzysztof Kozlowski
Quoted 94 lines · Krzysztof Kozlowski

Hi,

Mark asked for resending fixes separate from setting up CI under Github Actions, so here is a combination of all my previously sent patches related only to the actual C code:

https://lore.kernel.org/linux-nfc/20210710033859.3989-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210714110518.104655-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210716100844.51360-1-krzysztof.kozlowski(a)canonical.com/T/#t

This includes fixes for GCC/clang warnings, memory leaks, memory corruption and few other minor fixes. The UTF-8 and UTF-16 is not entirely fixed and I removed the work-in-progress patches.

Changes since v1 are:
1. Group all patches based on prefix (unit file), instead of topic.
2. Put the build-related patches at the end.
3. Remove all CI-related patches.
4. Drop patch: ndef: fix parsing of UTF-16 text payload.
5. Fix commit msg in: nfctool: pass the format as string literal

Best regards,
Krzysztof

Krzysztof Kozlowski (73):
Drop empty NEWS
nfctool: fix adapter_get_devices() cast-function-type
nfctool: fix adapter_print_target() cast-function-type
nfctool: fix adapter_print_info() cast-function-type
nfctool: fix adapter_compare_idx() cast-function-type
nfctool: fix nfctool_send_dep_link_up() cast-function-type
nfctool: fix nfctool_print_and_remove_snl() cast-function-type
nfctool: use proper format for integers (-Wformat)
nfctool: pass the format as string literal
dbus: fix -Wformat in near_dbus_encode_string()
unit: pass real UTF-8 for testing text NDEF
ndef: check UTF-16 text payload length
ndef: silence clang -Wcast-align warning
ndef: use NDEF_TEXT_RECORD_UTF16_STATUS define
ndef: use proper format for integers (-Wformat)
ndef: make freeing near_ndef_message reusable
se: fix multiple apdu definitions
se: silence clang -Wcast-align warning
se: use proper format for integers (-Wformat)
adapter: adjust indentation of continued arguments
adapter: use proper format for integers (-Wformat)
gdbus: do not shadow global 'pending' variable (-Wshadow)
nciattach: fix poll.h include location
nciattach: do not shadow other local 'opt' variable (-Wshadow)
bluetooth: use proper format for integers (-Wformat)
nfctype2: use proper format for integers (-Wformat)
nfctype3: use proper format for integers (-Wformat)
nfctype5: use proper format for integers (-Wformat)
nfctype5: fix returning uninitialized stack value in

    t5_tag_is_ti_pro()

mifare: use proper format for integers (-Wformat)
mifare: use unsigned int to suppress compiler -Wstrict-overflow
p2p: use proper format for integers (-Wformat)
npp: use proper format for integers (-Wformat)
device: use proper format for integers (-Wformat)
manager: use proper format for integers (-Wformat)
netlink: use proper format for integers (-Wformat)
gdbus: annotate printf-like functions as accepting format
snep-send: fix near_ndef_message memory leak
tag: use proper format for integers (-Wformat)
tag: do not open-code freeing ndef message
snep: do not open-code freeing ndef message
snep: remove useless NULL-ify of local pointer variable
snep: fix double free of GSList
snep: fix fragmented response memory leaks
unit: use g_assert_cmpstr()
unit: use g_assert_cmpint() and g_assert_cmpuint()
unit: fix recv() and send() return types
unit: use g_assert_null()
unit: use g_assert_cmpmem()
unit: use proper pointer to uint8_t in test_snep_read_recv_fragments()
unit: do not shadow global 'text' variable (-Wshadow)
unit: do not shadow global 'uri' variable (-Wshadow)
unit: use proper format for integers (-Wformat)
unit: fix memory leaks in test-ndef-parse
unit: do not open-code freeing ndef message
unit: fix memory leaks in test-ndef-build
unit: fix memory leaks in test-snep-read error paths
unit: fix record memory leak in test-snep-read
unit: fix records GList memory leak in test-snep-read
unit: do not pass NULL to memcpy()
unit: do not search for headers locally where they do not exist
unit: remove duplicated invalid definitions in test-snep-read
unit: remove duplicated definitions in test-ndef-parse
unit: add few asserts in test-snep-read
HACKING: refine required packages
build: fix setting CFLAGS on dash shell (Alpine Linux)

Quoted 8 lines

build: add more compiler warnings
build: enable -Wshadow and -Wformat-signedness compiler warnings
build: enable -Wformat=2 warnings
build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2
warnings
build: fix missing usage of PIE check result
build: add support for GCC sanitizers (asan, lsan and ubsan)
AUTHORS: Mention Krzysztof Kozlowski's contributions

Applied.

Thanks Krzysztof.

FYI, I built neard natively with these patches applied on an amd64 (ubuntu 20.04) and an ARM Cortext A8 (debian 10). Both build cleanly and I could read & write tags.

My plans include:
- python3-ize the python test scripts
- debug an issue I think I saw
- look for races that I recall running into in the past
- recruit another arm SoC for testing
- get my trf7970 working again

When things settle down and we're happy with what we have, we should cut a new version (0.17 or 1.0 even).

Mark
--

#77 lore raw
Quoted 112 lines · Mark Greer
Quoted 94 lines · Krzysztof Kozlowski

Hi,

Mark asked for resending fixes separate from setting up CI under Github Actions, so here is a combination of all my previously sent patches related only to the actual C code:

https://lore.kernel.org/linux-nfc/20210710033859.3989-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210714110518.104655-1-krzysztof.kozlowski(a)canonical.com/T/#t
https://lore.kernel.org/linux-nfc/20210716100844.51360-1-krzysztof.kozlowski(a)canonical.com/T/#t

This includes fixes for GCC/clang warnings, memory leaks, memory corruption and few other minor fixes. The UTF-8 and UTF-16 is not entirely fixed and I removed the work-in-progress patches.

Changes since v1 are:
1. Group all patches based on prefix (unit file), instead of topic.
2. Put the build-related patches at the end.
3. Remove all CI-related patches.
4. Drop patch: ndef: fix parsing of UTF-16 text payload.
5. Fix commit msg in: nfctool: pass the format as string literal

Best regards,
Krzysztof

Krzysztof Kozlowski (73):
Drop empty NEWS
nfctool: fix adapter_get_devices() cast-function-type
nfctool: fix adapter_print_target() cast-function-type
nfctool: fix adapter_print_info() cast-function-type
nfctool: fix adapter_compare_idx() cast-function-type
nfctool: fix nfctool_send_dep_link_up() cast-function-type
nfctool: fix nfctool_print_and_remove_snl() cast-function-type
nfctool: use proper format for integers (-Wformat)
nfctool: pass the format as string literal
dbus: fix -Wformat in near_dbus_encode_string()
unit: pass real UTF-8 for testing text NDEF
ndef: check UTF-16 text payload length
ndef: silence clang -Wcast-align warning
ndef: use NDEF_TEXT_RECORD_UTF16_STATUS define
ndef: use proper format for integers (-Wformat)
ndef: make freeing near_ndef_message reusable
se: fix multiple apdu definitions
se: silence clang -Wcast-align warning
se: use proper format for integers (-Wformat)
adapter: adjust indentation of continued arguments
adapter: use proper format for integers (-Wformat)
gdbus: do not shadow global 'pending' variable (-Wshadow)
nciattach: fix poll.h include location
nciattach: do not shadow other local 'opt' variable (-Wshadow)
bluetooth: use proper format for integers (-Wformat)
nfctype2: use proper format for integers (-Wformat)
nfctype3: use proper format for integers (-Wformat)
nfctype5: use proper format for integers (-Wformat)
nfctype5: fix returning uninitialized stack value in

    t5_tag_is_ti_pro()

mifare: use proper format for integers (-Wformat)
mifare: use unsigned int to suppress compiler -Wstrict-overflow
p2p: use proper format for integers (-Wformat)
npp: use proper format for integers (-Wformat)
device: use proper format for integers (-Wformat)
manager: use proper format for integers (-Wformat)
netlink: use proper format for integers (-Wformat)
gdbus: annotate printf-like functions as accepting format
snep-send: fix near_ndef_message memory leak
tag: use proper format for integers (-Wformat)
tag: do not open-code freeing ndef message
snep: do not open-code freeing ndef message
snep: remove useless NULL-ify of local pointer variable
snep: fix double free of GSList
snep: fix fragmented response memory leaks
unit: use g_assert_cmpstr()
unit: use g_assert_cmpint() and g_assert_cmpuint()
unit: fix recv() and send() return types
unit: use g_assert_null()
unit: use g_assert_cmpmem()
unit: use proper pointer to uint8_t in test_snep_read_recv_fragments()
unit: do not shadow global 'text' variable (-Wshadow)
unit: do not shadow global 'uri' variable (-Wshadow)
unit: use proper format for integers (-Wformat)
unit: fix memory leaks in test-ndef-parse
unit: do not open-code freeing ndef message
unit: fix memory leaks in test-ndef-build
unit: fix memory leaks in test-snep-read error paths
unit: fix record memory leak in test-snep-read
unit: fix records GList memory leak in test-snep-read
unit: do not pass NULL to memcpy()
unit: do not search for headers locally where they do not exist
unit: remove duplicated invalid definitions in test-snep-read
unit: remove duplicated definitions in test-ndef-parse
unit: add few asserts in test-snep-read
HACKING: refine required packages
build: fix setting CFLAGS on dash shell (Alpine Linux)

Quoted 8 lines

build: add more compiler warnings
build: enable -Wshadow and -Wformat-signedness compiler warnings
build: enable -Wformat=2 warnings
build: enable -Wunsafe-loop-optimizations and -Wstrict-overflow=2
warnings
build: fix missing usage of PIE check result
build: add support for GCC sanitizers (asan, lsan and ubsan)
AUTHORS: Mention Krzysztof Kozlowski's contributions

Applied.

Thanks Krzysztof.

FYI, I built neard natively with these patches applied on an amd64 (ubuntu 20.04) and an ARM Cortext A8 (debian 10). Both build cleanly and I could read & write tags.

Quoted 6 lines

My plans include:
- python3-ize the python test scripts
- debug an issue I think I saw
- look for races that I recall running into in the past
- recruit another arm SoC for testing
- get my trf7970 working again

Great, sounds like a good plan.

I sent now rebased and fixed CI under Github:
https://github.com/linux-nfc/neard/pull/2

Quoted 3 lines

When things settle down and we're happy with what we have, we should cut a new version (0.17 or 1.0 even).

Best regards,
Krzysztof

#78 lore raw
Quoted 6 lines · Krzysztof Kozlowski
Quoted 6 lines

FYI, I built neard natively with these patches applied on an amd64 (ubuntu 20.04) and an ARM Cortext A8 (debian 10). Both build cleanly and I could read & write tags.

My plans include:
- python3-ize the python test scripts

I checked now Ubuntu/Debian packages and dependency on Python2 was reason of removal of neard from their package repository. Convertinging these to Python3 would allow bring it back, so it's quite useful task.

Best regards,
Krzysztof

#79 lore raw
Quoted 6 lines · Krzysztof Kozlowski
Quoted 4 lines · Krzysztof Kozlowski
Quoted 4 lines

FYI, I built neard natively with these patches applied on an amd64 (ubuntu 20.04) and an ARM Cortext A8 (debian 10). Both build cleanly and I could read & write tags.

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

My plans include:
- python3-ize the python test scripts

I checked now Ubuntu/Debian packages and dependency on Python2 was reason of removal of neard from their package repository. Convertinging these to Python3 would allow bring it back, so it's quite useful task.

Good to know. Thanks for checking.

Mark
--