Browse Source

HPCC-24202 Fix htpasswd memory leak in error handling

Capture file loading exceptions so they may either be re-thrown or released. Any
exception message starting with "htpasswd" will be re-thrown. All others will be
repackaged and released.

Signed-off-by: Tim Klemm <tim.klemm@lexisnexisrisk.com>
Tim Klemm 5 years ago
parent
commit
6d8b1d7044
1 changed files with 7 additions and 2 deletions
  1. 7 2
      system/security/plugins/htpasswdSecurity/htpasswdSecurity.cpp

+ 7 - 2
system/security/plugins/htpasswdSecurity/htpasswdSecurity.cpp

@@ -309,9 +309,14 @@ private:
 			io->close();
 			pwFileLastMod = whenChanged;//remember when last changed
 		}
-		catch(IException*)
+        catch(IException* e)
 		{
-			throw MakeStringException(-1, "htpasswd Exception accessing Password file");
+            StringBuffer msg;
+            if (strncmp(e->errorMessage(msg).str(), "htpasswd", 8) == 0)
+                throw;
+            int code = e->errorCode();
+            e->Release();
+            throw MakeStringException(code, "htpasswd Exception accessing Password file: %s", msg.str());
 		}
 		return true;
 	}