Merge lp:~donadigo/switchboard-plug-parental-controls/fix-time-parse-crashes into lp:~elementary-pantheon/switchboard-plug-parental-controls/trunk

Proposed by Adam Bieńkowski
Status: Rejected
Rejected by: Adam Bieńkowski
Proposed branch: lp:~donadigo/switchboard-plug-parental-controls/fix-time-parse-crashes
Merge into: lp:~elementary-pantheon/switchboard-plug-parental-controls/trunk
Diff against target: 137 lines (+52/-38)
2 files modified
src/Widgets/GeneralBox.vala (+25/-14)
src/shared/PAMControl.vala (+27/-24)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-parental-controls/fix-time-parse-crashes
Reviewer Review Type Date Requested Status
elementary Pantheon team Pending
Review via email: mp+303831@code.launchpad.net

Commit message

* Fix crash were split would be performed on a null string.

Description of the change

Fix crash were split would be performed on a null string.

If it would be possible, this would go into loki update.

To post a comment you must log in.
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Since the merge-cli-deamon branch was merged, I'm marking this as rejected.

Unmerged revisions

224. By Adam Bieńkowski

Prevent from time parsing crashes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/GeneralBox.vala'
2--- src/Widgets/GeneralBox.vala 2016-07-27 16:14:53 +0000
3+++ src/Widgets/GeneralBox.vala 2016-08-24 15:27:47 +0000
4@@ -142,24 +142,35 @@
5 limit_combobox.active_id = restrict.day_id;
6 switch (restrict.day_id) {
7 case Vars.ALL_ID:
8- string from_weekday = restrict.weekday_hours.split ("-")[0];
9- string to_weekday = restrict.weekday_hours.split ("-")[1];
10- string from_weekend = restrict.weekend_hours.split ("-")[0];
11- string to_weekend = restrict.weekend_hours.split ("-")[1];
12-
13- weekday_box.set_from (from_weekday);
14- weekday_box.set_to (to_weekday);
15-
16- weekend_box.set_from (from_weekend);
17- weekend_box.set_to (to_weekend);
18+ if (restrict.weekday_hours != null) {
19+ string from_weekday = restrict.weekday_hours.split ("-")[0];
20+ string to_weekday = restrict.weekday_hours.split ("-")[1];
21+ weekday_box.set_from (from_weekday);
22+ weekday_box.set_to (to_weekday);
23+
24+ }
25+
26+ if (restrict.weekend_hours != null) {
27+ string from_weekend = restrict.weekend_hours.split ("-")[0];
28+ string to_weekend = restrict.weekend_hours.split ("-")[1];
29+ weekend_box.set_from (from_weekend);
30+ weekend_box.set_to (to_weekend);
31+ }
32+
33 break;
34 case Vars.WEEKDAYS_ID:
35- weekday_box.set_from (restrict.from);
36- weekday_box.set_to (restrict.to);
37+ if (restrict.from != null && restrict.to != null) {
38+ weekday_box.set_from (restrict.from);
39+ weekday_box.set_to (restrict.to);
40+ }
41+
42 break;
43 case Vars.WEEKENDS_ID:
44- weekend_box.set_from (restrict.from);
45- weekend_box.set_to (restrict.to);
46+ if (restrict.from != null && restrict.to != null) {
47+ weekend_box.set_from (restrict.from);
48+ weekend_box.set_to (restrict.to);
49+ }
50+
51 break;
52 default:
53 break;
54
55=== modified file 'src/shared/PAMControl.vala'
56--- src/shared/PAMControl.vala 2016-02-21 18:52:25 +0000
57+++ src/shared/PAMControl.vala 2016-08-24 15:27:47 +0000
58@@ -21,13 +21,13 @@
59 */
60
61 namespace PC {
62- public class PAMRestrictInfo : Object {
63- public string user;
64- public string day_id;
65- public string weekday_hours;
66- public string weekend_hours;
67- public string from;
68- public string to;
69+ public class PAMRestrictInfo {
70+ public string user = "";
71+ public string day_id = "";
72+ public string weekday_hours = "";
73+ public string weekend_hours = "";
74+ public string from = "";
75+ public string to = "";
76 }
77
78 public class PAMControl : Object {
79@@ -71,38 +71,41 @@
80 if (!line.has_prefix ("#")) {
81 var restrict_info = new PAMRestrictInfo ();
82 string[] units = line.split (";");
83- if (units.length >= 4) {
84+ if (units.length == 4) {
85 restrict_info.user = units[2];
86 string time = units[3];
87 time = time.replace ("!", "");
88
89- char[] time_chars = time.to_utf8 ();
90- string day = time_chars[0].to_string () + time_chars[1].to_string ();
91- switch (day.down ()) {
92- case "al":
93- restrict_info.day_id = "all";
94- break;
95- case "wk":
96- restrict_info.day_id = "weekdays";
97- break;
98- case "wd":
99- restrict_info.day_id = "weekends";
100+ string day = time.slice (0, 2);
101+ switch (day) {
102+ case "Al":
103+ restrict_info.day_id = Vars.ALL_ID;
104+ break;
105+ case "Wk":
106+ restrict_info.day_id = Vars.WEEKDAYS_ID;
107+ break;
108+ case "Wd":
109+ restrict_info.day_id = Vars.WEEKENDS_ID;
110 break;
111 default:
112 restrict_info.day_id = "";
113 break;
114 }
115
116- string hours = time.replace (day, "");
117+ string hours = time.substring (2);
118 string[] tmp = {};
119 if ("|" in hours) {
120 tmp = hours.split ("|");
121- restrict_info.weekday_hours = tmp[0];
122- restrict_info.weekend_hours = tmp[1];
123+ if (tmp.length >= 2) {
124+ restrict_info.weekday_hours = tmp[0];
125+ restrict_info.weekend_hours = tmp[1];
126+ }
127 } else {
128 tmp = hours.split ("-");
129- restrict_info.from = tmp[0];
130- restrict_info.to = tmp[1];
131+ if (tmp.length >= 2) {
132+ restrict_info.from = tmp[0];
133+ restrict_info.to = tmp[1];
134+ }
135 }
136
137 retval.append (restrict_info);

Subscribers

People subscribed via source and target branches

to all changes: