diff mbox series

[BlueZ,1/3] shared/util: implement argsisutf8()

Message ID 20250318131431.124750-2-r.smirnov@omp.ru
State New
Headers show
Series Fix crash in dbus caused by Unicode characters | expand

Commit Message

Roman Smirnov March 18, 2025, 1:14 p.m. UTC
This implements argsisutf8() which checks that all strings in the
argv array are written in utf8.
---
 src/shared/util.c | 12 ++++++++++++
 src/shared/util.h |  1 +
 2 files changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/src/shared/util.c b/src/shared/util.c
index 6e7634ad1..5d3a14d96 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1947,3 +1947,15 @@  bool strisutf8(const char *str, size_t len)
 
 	return true;
 }
+
+bool argsisutf8(int argc, char *argv[])
+{
+	for (int i = 0; i < argc; i++) {
+		if (!strisutf8(argv[i], strlen(argv[i]))) {
+			printf("Invalid character in string: %s\n", argv[i]);
+			return false;
+		}
+	}
+
+	return true;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index f2ca4f29f..dd357fb93 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -91,6 +91,7 @@  char *strdelimit(char *str, char *del, char c);
 int strsuffix(const char *str, const char *suffix);
 char *strstrip(char *str);
 bool strisutf8(const char *str, size_t length);
+bool argsisutf8(int argc, char *argv[]);
 
 void *util_malloc(size_t size);
 void *util_memdup(const void *src, size_t size);