diff options
author | Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> | 2021-07-12 11:18:50 +0200 |
---|---|---|
committer | Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> | 2021-07-19 12:44:07 +0200 |
commit | 69f7a05a42029e64756ac2012090623036a6452f (patch) | |
tree | c040ab2de65dab4d10c97466e9b97b00a92fdebe | |
parent | 5330b05c83ad9ce776d61c7ee2643a8e6d06e2f5 (diff) | |
download | neard-69f7a05a42029e64756ac2012090623036a6452f.tar.gz |
gdbus: annotate printf-like functions as accepting format
Printf-like functions should have the "format" argument annotated to:
1. Help in detection of format string vulnerabilities (and mistakes).
2. Satisfy -Wformat-nonliteral (-Wformat=2) warning.
This fixes clang warnings like:
gdbus/object.c:1416:31: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
vsnprintf(str, sizeof(str), format, args);
^~~~~~
src/adapter.c:255:7: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
strerror(err));
^~~~~~~~~~~~~
src/adapter.c:255:7: note: treat the string as an argument to avoid this
strerror(err));
^
"%s",
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
-rw-r--r-- | gdbus/gdbus.h | 15 | ||||
-rw-r--r-- | src/adapter.c | 1 |
2 files changed, 11 insertions, 5 deletions
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h index d99c254..e9ffd02 100644 --- a/gdbus/gdbus.h +++ b/gdbus/gdbus.h @@ -239,13 +239,15 @@ void g_dbus_pending_error(DBusConnection *connection, __attribute__((format(printf, 4, 5))); void g_dbus_pending_error_valist(DBusConnection *connection, GDBusPendingReply pending, const char *name, - const char *format, va_list args); + const char *format, va_list args) + __attribute__ ((format (printf, 4, 0))); DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name, const char *format, ...) __attribute__((format(printf, 3, 4))); DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name, - const char *format, va_list args); + const char *format, va_list args) + __attribute__ ((format (printf, 3, 0))); DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...); DBusMessage *g_dbus_create_reply_valist(DBusMessage *message, int type, va_list args); @@ -259,7 +261,8 @@ gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message, __attribute__((format(printf, 4, 5))); gboolean g_dbus_send_error_valist(DBusConnection *connection, DBusMessage *message, const char *name, - const char *format, va_list args); + const char *format, va_list args) + __attribute__ ((format (printf, 4, 0))); gboolean g_dbus_send_reply(DBusConnection *connection, DBusMessage *message, int type, ...); gboolean g_dbus_send_reply_valist(DBusConnection *connection, @@ -294,9 +297,11 @@ void g_dbus_remove_all_watches(DBusConnection *connection); void g_dbus_pending_property_success(GDBusPendingPropertySet id); void g_dbus_pending_property_error_valist(GDBusPendingReply id, - const char *name, const char *format, va_list args); + const char *name, const char *format, va_list args) + __attribute__ ((format (printf, 3, 0))); void g_dbus_pending_property_error(GDBusPendingReply id, const char *name, - const char *format, ...); + const char *format, ...) + __attribute__((format(printf, 3, 4))); void g_dbus_emit_property_changed(DBusConnection *connection, const char *path, const char *interface, const char *name); diff --git a/src/adapter.c b/src/adapter.c index 420127f..e0ab8c5 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -252,6 +252,7 @@ static void set_powered(GDBusPendingPropertySet id, dbus_bool_t powered, g_dbus_pending_property_error(id, NFC_ERROR_INTERFACE ".Failed", + "%s", strerror(err)); return; |