Skip to content

Commit

Permalink
add validation for db parameter in adapter config
Browse files Browse the repository at this point in the history
  • Loading branch information
bberry6 committed Jul 7, 2015
1 parent e342938 commit 8ce3f71
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/prepare-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module.exports = function (app){
var redisClientConnectionError;
var pubReady;
var subReady;
var db;
adapterConfig.pubClient.once('ready', function (){
if (pubReady) return;
pubReady = true;
Expand Down Expand Up @@ -136,9 +137,16 @@ module.exports = function (app){
return cb();
}

// if `db` was supplied, call `select` on that redis database
adapterConfig.pubClient.select(adapterConfig.db, function() {
adapterConfig.subClient.select(adapterConfig.db, function (){
// if `db` was supplied, validate the value
db = parseInt(adapterConfig.db, 10);
if(isNaN(db) || db > 15 || db < 0){
db = 0;
sails.log.warn('socket.io-redis db adapter paramter must be a number between 0 and 15');
sails.log.warn('Falling back to database 0');
}
// then call `select` on that redis database
adapterConfig.pubClient.select(db, function() {
adapterConfig.subClient.select(db, function (){
return cb();
});
});
Expand Down

0 comments on commit 8ce3f71

Please sign in to comment.