From 3ddac122908f024e153abae83c232edf2d480f12 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 5 Dec 2014 15:54:20 +0100 Subject: Correct ugly boundary checks in database init The check if dbargc exceeds MAX_ARGUMENTS was done _after_ it was checked if the array element is NULL. This was not the intention. Signed-off-by: David Sommerseth (cherry picked from commit 51f8c8e930221cc5feeac4f84be5550b4e5be9dd) --- eurephiadm/eurephiadm.c | 2 +- plugin/eurephia.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eurephiadm/eurephiadm.c b/eurephiadm/eurephiadm.c index 6775a4f..f9deb31 100644 --- a/eurephiadm/eurephiadm.c +++ b/eurephiadm/eurephiadm.c @@ -250,7 +250,7 @@ int eurephia_ConnectDB(eurephiaCTX *ctx, const char *argstr) { dbargc = 0; dbargv[dbargc] = strtok(cp, delims); - while( (dbargv[dbargc] != NULL) && (dbargc <= MAX_ARGUMENTS) ) { + while( (dbargc <= MAX_ARGUMENTS) && (dbargv[dbargc] != NULL) ) { dbargv[++dbargc] = strtok(NULL, delims); } diff --git a/plugin/eurephia.c b/plugin/eurephia.c index 880ad71..25af617 100644 --- a/plugin/eurephia.c +++ b/plugin/eurephia.c @@ -115,7 +115,7 @@ eurephiaCTX *eurephiaInit(const char const **argv, const char const **envp) // Put the rest of the arguments into an own array which will be the db module arguments if( optind < argc ) { // copy arguments, but make sure we do not exceed our limit - while( (optind < argc) && (dbargc < MAX_ARGUMENTS) ) { + while( (dbargc < MAX_ARGUMENTS) && (optind < argc) ) { dbargv[dbargc] = argv[optind++]; dbargc++; dbargv[dbargc] = NULL; -- cgit