diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2015-03-27 15:00:13 +0000 |
---|---|---|
committer | CI Train Bot <ci-train-bot@canonical.com> | 2015-03-27 15:00:13 +0000 |
commit | 16b6769150875f4635dc3cd04f6464a4be0b8168 (patch) | |
tree | 8af26e27faa34e36c021922fe8109588e8397444 | |
parent | 4776ccea13253645e0ddd76d5550790dbfe02863 (diff) | |
parent | c83ee3f1bc5a9de5eefbc542f5734b481d0bbffd (diff) | |
download | ayatana-indicator-session-16b6769150875f4635dc3cd04f6464a4be0b8168.tar.gz ayatana-indicator-session-16b6769150875f4635dc3cd04f6464a4be0b8168.tar.bz2 ayatana-indicator-session-16b6769150875f4635dc3cd04f6464a4be0b8168.zip |
Fix a crash in get_user_label() by testing a string pointer for NULL before dereferencing it. Fixes: #1290876
Approved by: Ted Gould, PS Jenkins bot
-rw-r--r-- | src/service.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/service.c b/src/service.c index 445f1af..9fda2f1 100644 --- a/src/service.c +++ b/src/service.c @@ -295,12 +295,21 @@ get_user_label (const IndicatorSessionUser * user) { const char * c; - /* If blank or whitespace, use username instead */ - for (c = user->real_name; *c != '\0' && g_ascii_isspace (*c); c++); - if (*c == '\0') - return user->user_name; + /* if real_name exists and is printable, use it */ + c = user->real_name; + if ((c != NULL) && g_utf8_validate(c, -1, NULL)) + { + while (*c != '\0') + { + if (g_unichar_isgraph(g_utf8_get_char(c))) + return user->real_name; + + c = g_utf8_next_char(c); + } + } - return user->real_name; + /* otherwise, use this as a fallback */ + return user->user_name; } static const char * |