Merge lp:~charlesk/indicator-session/lp-1290876-fix-null-dereference-in-get-user-label into lp:indicator-session/15.04

Proposed by Charles Kerr
Status: Merged
Approved by: Ted Gould
Approved revision: 465
Merged at revision: 463
Proposed branch: lp:~charlesk/indicator-session/lp-1290876-fix-null-dereference-in-get-user-label
Merge into: lp:indicator-session/15.04
Diff against target: 31 lines (+15/-6)
1 file modified
src/service.c (+15/-6)
To merge this branch: bzr merge lp:~charlesk/indicator-session/lp-1290876-fix-null-dereference-in-get-user-label
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+254105@code.launchpad.net

Commit message

Fix a crash in get_user_label() by testing a string pointer for NULL before dereferencing it.

Description of the change

Fix a crash in get_user_label() by testing a string pointer for NULL before dereferencing it.

Steps to test:

1. install this branch and restart indicator-session
2. edit /etc/password
3. remove the fullname portion of your current login's line:
   - username:x:1000:1000:Full Name:/home/username:/bin/bash
   + username:x:1000:1000::/home/username:/bin/bash

Expected results:

Instead of crashing, indicator-session's user section should change your current login's menuitem from "Full Name" to "username"

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
464. By Charles Kerr

use unichar rather than ascii

465. By Charles Kerr

if someone has control codes in their real name, who are we do disagree?

Revision history for this message
Ted Gould (ted) wrote :

Great, thanks for the fixes! ☺

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/service.c'
2--- src/service.c 2014-07-18 21:36:13 +0000
3+++ src/service.c 2015-03-25 22:30:52 +0000
4@@ -295,12 +295,21 @@
5 {
6 const char * c;
7
8- /* If blank or whitespace, use username instead */
9- for (c = user->real_name; *c != '\0' && g_ascii_isspace (*c); c++);
10- if (*c == '\0')
11- return user->user_name;
12-
13- return user->real_name;
14+ /* if real_name exists and is printable, use it */
15+ c = user->real_name;
16+ if ((c != NULL) && g_utf8_validate(c, -1, NULL))
17+ {
18+ while (*c != '\0')
19+ {
20+ if (g_unichar_isgraph(g_utf8_get_char(c)))
21+ return user->real_name;
22+
23+ c = g_utf8_next_char(c);
24+ }
25+ }
26+
27+ /* otherwise, use this as a fallback */
28+ return user->user_name;
29 }
30
31 static const char *

Subscribers

People subscribed via source and target branches