[gnome-terminal] app: Only allow valid charsets
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal] app: Only allow valid charsets
- Date: Tue, 20 May 2014 14:05:33 +0000 (UTC)
commit b0bdd4740f82daa6c2bb020738a857b8e8d2a6dd
Author: Christian Persch <chpe gnome org>
Date: Tue May 20 16:04:15 2014 +0200
app: Only allow valid charsets
Charsets must be [-_A-Za-z0-9] only.
https://bugzilla.gnome.org/show_bug.cgi?id=730390
src/terminal-app.c | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
---
diff --git a/src/terminal-app.c b/src/terminal-app.c
index 33f6e6f..64c7dd3 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -625,6 +625,25 @@ terminal_app_get_encodings (TerminalApp *app)
return app->encodings;
}
+static const char *
+charset_validated (const char *charset)
+{
+ gsize i;
+
+ if (charset == NULL)
+ goto out;
+
+ for (i = 0; charset[i] != '\0'; i++) {
+ char c = charset[i];
+ if (!(g_ascii_isalnum(c) || c == '_' || c == '-'))
+ goto out;
+ }
+
+ return charset;
+ out:
+ return "UTF-8";
+}
+
/**
* terminal_app_ensure_encoding:
* @app:
@@ -635,7 +654,7 @@ terminal_app_get_encodings (TerminalApp *app)
* @charset is not a known charset, returns a #TerminalEncoding for a
* custom charset.
*
- * Returns: (transfer none): a #TerminalEncoding
+ * Returns: (transfer none): a #TerminalEncoding, or %NULL
*/
TerminalEncoding *
terminal_app_ensure_encoding (TerminalApp *app,
@@ -643,7 +662,7 @@ terminal_app_ensure_encoding (TerminalApp *app,
{
TerminalEncoding *encoding;
- encoding = g_hash_table_lookup (app->encodings, charset ? charset : "UTF-8");
+ encoding = g_hash_table_lookup (app->encodings, charset_validated (charset));
if (encoding == NULL)
{
encoding = terminal_encoding_new (charset,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]