From b2501ad24ef5ae92e1445cedcf7127c6a4033fcb Mon Sep 17 00:00:00 2001 From: Jakub Jandl Date: Fri, 16 Dec 2022 13:37:48 +0100 Subject: [PATCH] Fix path behavior - `path.join` just joins the path segments, not allowing the use of absolute paths --- lib/geoip.js | 12 ++++-------- scripts/updatedb.js | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/geoip.js b/lib/geoip.js index 619f339d..b52ae0c2 100644 --- a/lib/geoip.js +++ b/lib/geoip.js @@ -10,14 +10,10 @@ var async = require('async'); var watcherName = 'dataWatcher'; - -var geodatadir; - -if (typeof global.geodatadir === 'undefined'){ - geodatadir = path.join(__dirname, '/../data/'); -} else { - geodatadir = global.geodatadir; -} +var geodatadir = path.resolve( + __dirname, + global.geodatadir || process.env.GEODATADIR || '../data/' +); var dataFiles = { city: path.join(geodatadir, 'geoip-city.dat'), diff --git a/scripts/updatedb.js b/scripts/updatedb.js index 4f9ba9a4..9c1a43d7 100644 --- a/scripts/updatedb.js +++ b/scripts/updatedb.js @@ -36,15 +36,15 @@ var geodatadir = args.find(function(arg) { if (typeof geodatadir === 'undefined' && typeof process.env.GEODATADIR !== 'undefined') { geodatadir = 'geodatadir='+process.env.GEODATADIR; } -var dataPath = path.join(__dirname, '..', 'data'); +var dataPath = path.resolve(__dirname, '..', 'data'); if (typeof geodatadir !== 'undefined') { - dataPath = path.join(process.cwd(), geodatadir.split('=')[1]); + dataPath = path.resolve(process.cwd(), geodatadir.split('=')[1]); if (!fs.existsSync(dataPath)) { console.log(chalk.red('ERROR') + ': Directory does\'t exist: ' + dataPath); process.exit(1); } } -var tmpPath = path.join(__dirname, '..', 'tmp'); +var tmpPath = path.resolve(__dirname, '..', 'tmp'); var countryLookup = {}; var cityLookup = {}; var databases = [