Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SER-1550] API common. Fix insuficient null checks #5698

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/utils/common.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with this update, if params is not passed to the function, request will just hang since there's nothing ending "res".
to me, completely removing the nullcheck for params from the if condition would be the best approach here

Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,11 @@ common.unblockResponses = function(params) {
* @param {object} heads - headers to add to the output
*/
common.returnRaw = function(params, returnCode, body, heads) {
if (!params) {
console.error("Params is null or undefined, cannot proceed.");
return;
}

params.response = {
code: returnCode,
body: body
Expand Down Expand Up @@ -1569,6 +1574,11 @@ common.returnRaw = function(params, returnCode, body, heads) {
* @param {boolean} noResult - skip wrapping message object into stupid {result: }
*/
common.returnMessage = function(params, returnCode, message, heads, noResult = false) {
if (!params) {
console.error("Params is null or undefined, cannot proceed.");
return;
}

params.response = {
code: returnCode,
body: JSON.stringify(noResult && typeof message === 'object' ? message : {result: message}, escape_html_entities)
Expand Down Expand Up @@ -2629,7 +2639,7 @@ common.updateAppUser = function(params, update, no_meta, callback) {
callback = no_meta;
no_meta = false;
}
if (Object.keys(update).length) {
if (update && Object.keys(update).length) {
for (var i in update) {
if (i.indexOf("$") !== 0) {
let err = "Unkown modifier " + i + " in " + update + " for " + params.href;
Expand Down
Loading