diff options
| author | daurnimator <quae@daurnimator.com> | 2017-04-03 19:29:42 +1000 |
|---|---|---|
| committer | daurnimator <quae@daurnimator.com> | 2017-04-03 19:29:42 +1000 |
| commit | e9feb9dd6c8e87544d2f891e4a1e7b9d7f0264ad (patch) | |
| tree | 7752be57e4a012147a8eb4d1bfab62813f824574 | |
| parent | 4dcda3a009e3f56ea37dac44f9d891b1903d8742 (diff) | |
| download | luaossl-e9feb9dd6c8e87544d2f891e4a1e7b9d7f0264ad.tar.gz luaossl-e9feb9dd6c8e87544d2f891e4a1e7b9d7f0264ad.tar.bz2 luaossl-e9feb9dd6c8e87544d2f891e4a1e7b9d7f0264ad.zip | |
Don't leak ctx on error
Fixes #72
| -rw-r--r-- | src/openssl.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/openssl.c b/src/openssl.c index 2b363d5..dc67d8a 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -7328,7 +7328,7 @@ static int xs_verify(lua_State *L) { | |||
| 7328 | X509 *crt = checksimple(L, 2, X509_CERT_CLASS); | 7328 | X509 *crt = checksimple(L, 2, X509_CERT_CLASS); |
| 7329 | STACK_OF(X509) *chain = NULL, **proof; | 7329 | STACK_OF(X509) *chain = NULL, **proof; |
| 7330 | X509_STORE_CTX *ctx = NULL; | 7330 | X509_STORE_CTX *ctx = NULL; |
| 7331 | int nr = 0, ok, why; | 7331 | int ok, why; |
| 7332 | 7332 | ||
| 7333 | /* pre-allocate space for a successful return */ | 7333 | /* pre-allocate space for a successful return */ |
| 7334 | lua_settop(L, 3); | 7334 | lua_settop(L, 3); |
| @@ -7363,27 +7363,24 @@ static int xs_verify(lua_State *L) { | |||
| 7363 | case 1: /* verified */ | 7363 | case 1: /* verified */ |
| 7364 | if (!(*proof = X509_STORE_CTX_get1_chain(ctx))) | 7364 | if (!(*proof = X509_STORE_CTX_get1_chain(ctx))) |
| 7365 | goto eossl; | 7365 | goto eossl; |
| 7366 | X509_STORE_CTX_free(ctx); | ||
| 7366 | 7367 | ||
| 7367 | lua_pushboolean(L, 1); | 7368 | lua_pushboolean(L, 1); |
| 7368 | lua_pushvalue(L, -2); | 7369 | lua_pushvalue(L, -2); |
| 7369 | nr = 2; | ||
| 7370 | 7370 | ||
| 7371 | break; | 7371 | return 2; |
| 7372 | case 0: /* not verified */ | 7372 | case 0: /* not verified */ |
| 7373 | why = X509_STORE_CTX_get_error(ctx); | 7373 | why = X509_STORE_CTX_get_error(ctx); |
| 7374 | X509_STORE_CTX_free(ctx); | ||
| 7374 | 7375 | ||
| 7375 | lua_pushboolean(L, 0); | 7376 | lua_pushboolean(L, 0); |
| 7376 | lua_pushstring(L, X509_verify_cert_error_string(why)); | 7377 | lua_pushstring(L, X509_verify_cert_error_string(why)); |
| 7377 | nr = 2; | ||
| 7378 | 7378 | ||
| 7379 | break; | 7379 | return 2; |
| 7380 | default: | 7380 | default: |
| 7381 | goto eossl; | 7381 | goto eossl; |
| 7382 | } | 7382 | } |
| 7383 | 7383 | ||
| 7384 | X509_STORE_CTX_free(ctx); | ||
| 7385 | |||
| 7386 | return nr; | ||
| 7387 | eossl: | 7384 | eossl: |
| 7388 | if (ctx) | 7385 | if (ctx) |
| 7389 | X509_STORE_CTX_free(ctx); | 7386 | X509_STORE_CTX_free(ctx); |
