Skip to content

Commit 18e2151

Browse files
Merge pull request #5506 from Countly/SER-1557
[SER-1557] [Deepscan] Mix 3. Fix insufficient null checks
2 parents 562ee4f + 55c860a commit 18e2151

File tree

14 files changed

+126
-101
lines changed

14 files changed

+126
-101
lines changed

api/parts/jobs/job.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,16 @@ class IPCFaçadeJob extends ResourcefulJob {
10681068
this.ipcChannel.remove();
10691069
}, (error) => {
10701070
this.ipcChannel.remove();
1071-
log.e('[%s] Error in IPCFaçadeJob %s: %j / %j', this.job.channel, this.resourceFaçade._id, error, error.stack);
1071+
if (error) {
1072+
log.e('[%s] Error in IPCFaçadeJob %s: %j / %j', this.job.channel, this.resourceFaçade._id, error, error.stack);
1073+
}
1074+
else {
1075+
log.e('[%s] Error in IPCFaçadeJob %s: Unknown error', this.job.channel, this.resourceFaçade._id);
1076+
}
10721077
this.job._finish(error || 'Aborted').catch(()=>{});
1073-
throw error;
1078+
if (error) {
1079+
throw error;
1080+
}
10741081
});
10751082
}
10761083

api/parts/mgmt/apps.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ appsApi.updateAppPlugins = function(params) {
613613
* @returns {boolean} true if operation successful
614614
**/
615615
appsApi.deleteApp = function(params) {
616+
params = params || {};
616617
var argProps = {
617618
'app_id': {
618619
'required': true,

bin/scripts/drill_index.js

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -32,75 +32,77 @@ Promise.all([plugins.dbConnection("countly"), plugins.dbConnection("countly_dril
3232
countlyDb.close();
3333
console.log("Error occured:", error);
3434
}
35-
var cnt = 0;
36-
results = results.filter(collection => collection && collection.collectionName && collection.collectionName.startsWith("drill_events"));
37-
async.eachSeries(results, function(collection, done) {
38-
cnt++;
39-
console.log("Processing", cnt, "of", results.length, collection.collectionName);
40-
var col = db.collection(collection.collectionName);
41-
col.createIndex({uid: 1}, {background: true}, function() {
42-
console.log("Done", {uid: 1});
43-
if (hashes[collection.collectionName] === "[CLY]_session") {
44-
col.createIndex({ts: 1, "up.cc": 1, uid: 1}, {background: true}, function() {
45-
console.log("Done", "[CLY]_session", {ts: 1, "up.cc": 1, uid: 1});
46-
done();
47-
});
48-
}
49-
else if (hashes[collection.collectionName] === "[CLY]_view") {
50-
col.createIndex({ts: 1, "sg.name": 1}, {background: true}, function() {
51-
console.log("Done", "[CLY]_view", {ts: 1, "sg.name": 1});
52-
done();
53-
});
54-
}
55-
else if (hashes[collection.collectionName] === "[CLY]_crash") {
56-
col.createIndex({ts: 1, "sg.crash": 1}, {background: true}, function() {
57-
console.log("Done", "[CLY]_crash", {ts: 1, "sg.crash": 1});
58-
done();
59-
});
60-
}
61-
else if (hashes[collection.collectionName] === "[CLY]_push_action") {
62-
col.createIndex({ts: 1, "sg.i": 1, uid: 1}, {background: true}, function() {
63-
console.log("Done", "[CLY]_push_action", {ts: 1, "sg.i": 1});
64-
done();
65-
});
66-
}
67-
else if (hashes[collection.collectionName] === "[CLY]_star_rating") {
68-
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
69-
console.log("Done", "[CLY]_star_rating", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
70-
done();
71-
});
72-
}
73-
else if (hashes[collection.collectionName] === "[CLY]_nps") {
74-
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
75-
console.log("Done", "[CLY]_nps", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
76-
done();
77-
});
78-
}
79-
else if (hashes[collection.collectionName] === "[CLY]_survey") {
80-
col.createIndex({ts: 1, "sg.widget_id": 1, uid: 1}, {background: true}, function() {
81-
console.log("Done", "[CLY]_survey", {ts: 1, "sg.widget_id": 1});
82-
done();
83-
});
84-
}
85-
else {
86-
col.createIndex({ts: 1}, {background: true}, function() {
87-
console.log("Done", {ts: 1});
35+
else {
36+
var cnt = 0;
37+
results = results.filter(collection => collection && collection.collectionName && collection.collectionName.startsWith("drill_events"));
38+
async.eachSeries(results, function(collection, done) {
39+
cnt++;
40+
console.log("Processing", cnt, "of", results.length, collection.collectionName);
41+
var col = db.collection(collection.collectionName);
42+
col.createIndex({uid: 1}, {background: true}, function() {
43+
console.log("Done", {uid: 1});
44+
if (hashes[collection.collectionName] === "[CLY]_session") {
45+
col.createIndex({ts: 1, "up.cc": 1, uid: 1}, {background: true}, function() {
46+
console.log("Done", "[CLY]_session", {ts: 1, "up.cc": 1, uid: 1});
47+
done();
48+
});
49+
}
50+
else if (hashes[collection.collectionName] === "[CLY]_view") {
51+
col.createIndex({ts: 1, "sg.name": 1}, {background: true}, function() {
52+
console.log("Done", "[CLY]_view", {ts: 1, "sg.name": 1});
53+
done();
54+
});
55+
}
56+
else if (hashes[collection.collectionName] === "[CLY]_crash") {
57+
col.createIndex({ts: 1, "sg.crash": 1}, {background: true}, function() {
58+
console.log("Done", "[CLY]_crash", {ts: 1, "sg.crash": 1});
59+
done();
60+
});
61+
}
62+
else if (hashes[collection.collectionName] === "[CLY]_push_action") {
63+
col.createIndex({ts: 1, "sg.i": 1, uid: 1}, {background: true}, function() {
64+
console.log("Done", "[CLY]_push_action", {ts: 1, "sg.i": 1});
65+
done();
66+
});
67+
}
68+
else if (hashes[collection.collectionName] === "[CLY]_star_rating") {
69+
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
70+
console.log("Done", "[CLY]_star_rating", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
71+
done();
72+
});
73+
}
74+
else if (hashes[collection.collectionName] === "[CLY]_nps") {
75+
col.createIndex({ts: 1, "sg.widget_id": 1, "sg.rating": 1, uid: 1}, {background: true}, function() {
76+
console.log("Done", "[CLY]_nps", {ts: 1, "sg.widget_id": 1, "sg.rating": 1});
77+
done();
78+
});
79+
}
80+
else if (hashes[collection.collectionName] === "[CLY]_survey") {
81+
col.createIndex({ts: 1, "sg.widget_id": 1, uid: 1}, {background: true}, function() {
82+
console.log("Done", "[CLY]_survey", {ts: 1, "sg.widget_id": 1});
83+
done();
84+
});
85+
}
86+
else {
87+
col.createIndex({ts: 1}, {background: true}, function() {
88+
console.log("Done", {ts: 1});
89+
done();
90+
});
91+
}
92+
});
93+
}, function() {
94+
console.log("Fixing indexes on eventTimes collections");
95+
async.eachSeries(apps, function(app, done) {
96+
countlyDb.collection('eventTimes' + app._id).ensureIndex({"uid": 1}, function() {
8897
done();
8998
});
90-
}
91-
});
92-
}, function() {
93-
console.log("Fixing indexes on eventTimes collections");
94-
async.eachSeries(apps, function(app, done) {
95-
countlyDb.collection('eventTimes' + app._id).ensureIndex({"uid": 1}, function() {
96-
done();
99+
}, function() {
100+
db.close();
101+
countlyDb.close();
102+
console.log("Drill index finished");
97103
});
98-
}, function() {
99-
db.close();
100-
countlyDb.close();
101-
console.log("Drill index finished");
102104
});
103-
});
105+
}
104106
});
105107
});
106108
});

bin/scripts/fix-data/recheck_merges_new.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("
172172
}
173173
totalProcessedUsers[app._id]++;
174174
}
175-
await addRecheckedFlag(app._id, user.uid);
175+
if (user && user.uid) {
176+
await addRecheckedFlag(app._id, user.uid);
177+
}
176178
}
177179
console.log("Processed users for app", app.name, ": ", totalProcessedUsers[app._id]);
178180
}

frontend/express/public/core/app-management/javascripts/countly.views.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -381,26 +381,28 @@
381381
},
382382
dataType: "json",
383383
success: function(data) {
384-
data.locked = false;
385-
countlyGlobal.apps[data._id] = data;
386-
countlyGlobal.admin_apps[data._id] = data;
387-
Backbone.history.appIds.push(data._id + "");
388-
countlyGlobal.apps[data._id].image = "appimages/" + data._id + ".png?" + Date.now().toString();
389-
self.appList.push({
390-
value: data._id + "",
391-
label: data.name
392-
});
393-
self.$store.dispatch("countlyCommon/addToAllApps", data);
394-
if (self.firstApp) {
395-
countlyCommon.ACTIVE_APP_ID = data._id + "";
396-
app.onAppManagementSwitch(data._id + "", data && data.type || "mobile");
397-
self.$store.dispatch("countlyCommon/updateActiveApp", data._id + "");
398-
app.initSidebar();
384+
if (data && data._id) {
385+
data.locked = false;
386+
countlyGlobal.apps[data._id] = data;
387+
countlyGlobal.admin_apps[data._id] = data;
388+
Backbone.history.appIds.push(data._id + "");
389+
countlyGlobal.apps[data._id].image = "appimages/" + data._id + ".png?" + Date.now().toString();
390+
self.appList.push({
391+
value: data._id + "",
392+
label: data.name
393+
});
394+
self.$store.dispatch("countlyCommon/addToAllApps", data);
395+
if (self.firstApp) {
396+
countlyCommon.ACTIVE_APP_ID = data._id + "";
397+
app.onAppManagementSwitch(data._id + "", data && data.type || "mobile");
398+
self.$store.dispatch("countlyCommon/updateActiveApp", data._id + "");
399+
app.initSidebar();
400+
}
401+
self.firstApp = self.checkIfFirst();
402+
setTimeout(function() {
403+
self.selectedSearchBar = data._id + "";
404+
}, 1);
399405
}
400-
self.firstApp = self.checkIfFirst();
401-
setTimeout(function() {
402-
self.selectedSearchBar = data._id + "";
403-
}, 1);
404406
},
405407
error: function(xhr, status, error) {
406408
CountlyHelpers.notify({

frontend/express/public/javascripts/countly/countly.template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ var AppRouter = Backbone.Router.extend({
14141414
* <span>{{#limitString value 15}}{{/limitString}}</span>
14151415
*/
14161416
Handlebars.registerHelper('limitString', function(string, limit) {
1417-
if (string.length > limit) {
1417+
if (string && string.length > limit) {
14181418
return (string || '').substr(0, limit) + "..";
14191419
}
14201420
else {

frontend/express/public/javascripts/countly/vue/components/drawer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@
127127
* Delete the hover key as its set by the data table on hovering a row
128128
* and we don't want to pass it to the drawer.
129129
*/
130-
delete initialEditedObject.hover;
130+
if (initialEditedObject && initialEditedObject.hover !== undefined) {
131+
delete initialEditedObject.hover;
132+
}
131133
this.drawers[name].initialEditedObject = initialEditedObject || {};
132134
},
133135
closeDrawer: function(name) {

plugins/alerts/api/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ const PERIOD_TO_TEXT_EXPRESSION_MAPPER = {
213213
{$set: alertConfig},
214214
function(err, result) {
215215
if (!err) {
216-
plugins.dispatch("/updateAlert", { method: "alertTrigger", alert: result.value });
216+
if (result && result.value) {
217+
plugins.dispatch("/updateAlert", { method: "alertTrigger", alert: result.value });
218+
}
217219
plugins.dispatch("/updateAlert", { method: "alertTrigger" });
218220

219221
common.returnOutput(params, result && result.value);

plugins/alerts/frontend/public/javascripts/countly.models.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,15 @@
245245
},
246246
dataType: "json",
247247
success: function(res) {
248-
if (res && res.aaData && res.aaData.length > 0 && callback) {
248+
if (res && res.aaData && res.aaData.length > 0) {
249249
var data = [];
250250
for (var i = 0; i < res.aaData.length; i++) {
251251
data.push({
252252
value: res.aaData[i]._id,
253253
name: res.aaData[i].view,
254254
});
255255
}
256+
256257
return callback(data);
257258
}
258259

plugins/crashes/api/api.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ plugins.setConfigs("crashes", {
451451
report.group = hash;
452452
report.uid = dbAppUser.uid;
453453
report.ts = params.time.timestamp;
454-
var updateUser = {};
454+
let updateUser = {};
455455
if (!report.nonfatal) {
456456
if (!dbAppUser.hadFatalCrash) {
457457
updateUser.hadFatalCrash = "true";
@@ -464,20 +464,24 @@ plugins.setConfigs("crashes", {
464464
}
465465
updateUser.hadAnyNonfatalCrash = report.ts;
466466
}
467-
let updateData = {$inc: {}};
467+
let updateData = { $inc: {} };
468468
updateData.$inc["data.crashes"] = 1;
469469
if (Object.keys(updateUser).length) {
470470
updateData.$set = updateUser;
471471
}
472472
ob.updates.push(updateData);
473473

474-
var set = {group: hash, 'uid': report.uid, last: report.ts};
475-
if (dbAppUser && dbAppUser.sc) {
474+
var set = {
475+
group: hash,
476+
uid: report.uid,
477+
last: report.ts,
478+
};
479+
if (dbAppUser.sc) {
476480
set.sessions = dbAppUser.sc;
477481
}
478482
common.db.collection('app_crashusers' + params.app_id).findAndModify({group: hash, 'uid': report.uid}, {}, {$set: set, $inc: {reports: 1}}, {upsert: true, new: false}, function(err, user) {
479483
user = user && user.ok ? user.value : null;
480-
if (user && user.sessions && dbAppUser && dbAppUser.sc && dbAppUser.sc > user.sessions) {
484+
if (user && user.sessions && dbAppUser.sc && dbAppUser.sc > user.sessions) {
481485
report.session = dbAppUser.sc - user.sessions;
482486
}
483487
common.db.collection('app_crashes' + params.app_id).insert(report, function(crashErr, res) {

0 commit comments

Comments
 (0)