Merge pull request #72 from whatdoineed2do/usage-validation-memleaks

Usage validation and memleaks fixes
This commit is contained in:
WitherOrNot 2023-09-27 04:42:08 -04:00 committed by GitHub
commit 8f843ad4c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 7 deletions

View File

@ -22,6 +22,15 @@
#include "cli.h" #include "cli.h"
CLI::~CLI()
{
EC_GROUP_free(eCurve);
EC_POINT_free(genPoint);
EC_POINT_free(pubPoint);
BN_free(privateKey);
BN_free(genOrder);
}
bool CLI::loadJSON(const fs::path& filename, json *output) { bool CLI::loadJSON(const fs::path& filename, json *output) {
if (!filename.empty() && !fs::exists(filename)) { if (!filename.empty() && !fs::exists(filename)) {
fmt::print("ERROR: File {} does not exist\n", filename.string()); fmt::print("ERROR: File {} does not exist\n", filename.string());
@ -183,6 +192,10 @@ int CLI::parseCommandLine(int argc, char* argv[], Options* options) {
} }
i++; i++;
} else if (arg == "-p" || arg == "--productid") { } else if (arg == "-p" || arg == "--productid") {
if (i == argc -1) {
options->error = true;
break;
}
options->productid = argv[i+1]; options->productid = argv[i+1];
i++; i++;
} else if (arg == "-V" || arg == "--validate") { } else if (arg == "-V" || arg == "--validate") {
@ -203,7 +216,7 @@ int CLI::parseCommandLine(int argc, char* argv[], Options* options) {
} }
// make sure that a product id is entered for OFFICE_2K3 or OFFICE_2K7 IIDs // make sure that a product id is entered for OFFICE_2K3 or OFFICE_2K7 IIDs
if ((options->activationMode == OFFICE_2K3 || options->activationMode == OFFICE_2K7) && options->productid == "") { if ((options->activationMode == OFFICE_2K3 || options->activationMode == OFFICE_2K7) && (options->productid.empty() || options->instid.empty()) ) {
return options->error = true; return options->error = true;
} }
@ -413,6 +426,7 @@ int CLI::BINK1998Generate() {
sscanf(cRaw, "%d", &oRaw); sscanf(cRaw, "%d", &oRaw);
nRaw += (oRaw % 999999); // ensure our serial is less than 999999 nRaw += (oRaw % 999999); // ensure our serial is less than 999999
BN_free(bnrand);
} }
if (this->options.verbose) { if (this->options.verbose) {

View File

@ -85,6 +85,7 @@ class CLI {
public: public:
CLI(Options options, json keys); CLI(Options options, json keys);
~CLI();
static bool loadJSON(const fs::path& filename, json *output); static bool loadJSON(const fs::path& filename, json *output);
static void showHelp(char *argv[]); static void showHelp(char *argv[]);

View File

@ -100,6 +100,13 @@ EC_GROUP* PIDGEN3::initializeEllipticCurve(
// Cleanup // Cleanup
BN_CTX_free(context); BN_CTX_free(context);
BN_free(p);
BN_free(a);
BN_free(b);
BN_free(generatorX);
BN_free(generatorY);
BN_free(publicKeyX);
BN_free(publicKeyY);
return eCurve; return eCurve;
} }

View File

@ -39,23 +39,23 @@ int main(int argc, char *argv[]) {
return status; return status;
} }
CLI* run = new CLI(options, keys); CLI run(options, keys);
switch(options.applicationMode) { switch(options.applicationMode) {
case MODE_BINK1998_GENERATE: case MODE_BINK1998_GENERATE:
return run->BINK1998Generate(); return run.BINK1998Generate();
case MODE_BINK2002_GENERATE: case MODE_BINK2002_GENERATE:
return run->BINK2002Generate(); return run.BINK2002Generate();
case MODE_BINK1998_VALIDATE: case MODE_BINK1998_VALIDATE:
return run->BINK1998Validate(); return run.BINK1998Validate();
case MODE_BINK2002_VALIDATE: case MODE_BINK2002_VALIDATE:
return run->BINK2002Validate(); return run.BINK2002Validate();
case MODE_CONFIRMATION_ID: case MODE_CONFIRMATION_ID:
return run->ConfirmationID(); return run.ConfirmationID();
default: default:
return 1; return 1;