[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] init: Do not report a failed initialisation as initialised
[Thread Prev] | [Thread Next]
- Subject: [PATCH 2/2] init: Do not report a failed initialisation as initialised
- From: Daniel Golle <daniel@xxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Fri, 28 Aug 2026 08:40:52 +0100
- To: libssh@xxxxxxxxxx
- Cc: John Crispin <john@xxxxxxxxxxx>
is_ssh_initialized() answered only whether _ssh_init() had run, not
whether it had succeeded: the counter is incremented before anything is
attempted and stays raised when initialisation fails (_ssh_finalize()
relies on that to skip tearing down what was never set up). After a
failed constructor initialisation, for example with no usable entropy
source, the guard in ssh_connect() therefore passed and the session ran
into the unusable crypto state instead of failing with the intended
"Library not initialized" error.
Report the library as initialised only when the recorded initialisation
result is a success.
Signed-off-by: Daniel Golle <daniel@xxxxxxxxxxxxxx>
---
src/init.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/init.c b/src/init.c
index e516c331..9277cd92 100644
--- a/src/init.c
+++ b/src/init.c
@@ -277,7 +277,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL,
* @internal
* @brief Return whether the library is initialized
*
- * @returns true if the library is initialized; false otherwise.
+ * @returns true if the library is initialized and initialization
+ * succeeded; false otherwise.
*
* @see ssh_init()
*/
@@ -286,7 +287,7 @@ bool is_ssh_initialized(void) {
bool is_initialized = false;
ssh_mutex_lock(&ssh_init_mutex);
- is_initialized = _ssh_initialized > 0;
+ is_initialized = _ssh_initialized > 0 && _ssh_init_ret == 0;
ssh_mutex_unlock(&ssh_init_mutex);
return is_initialized;
--
2.55.0
Archive administrator: postmaster@lists.cynapses.org