ssh: fix memleaks during ssh.softwareversion init and cleanup

pull/562/head
Victor Julien 13 years ago
parent ec724a1e56
commit 16130cc974

@ -154,7 +154,7 @@ int DetectSshSoftwareVersionMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx
DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (char *str) DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (char *str)
{ {
DetectSshSoftwareVersionData *ssh = NULL; DetectSshSoftwareVersionData *ssh = NULL;
#define MAX_SUBSTRINGS 30 #define MAX_SUBSTRINGS 30
int ret = 0, res = 0; int ret = 0, res = 0;
int ov[MAX_SUBSTRINGS]; int ov[MAX_SUBSTRINGS];
@ -167,7 +167,7 @@ DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (char *str)
} }
if (ret > 1) { if (ret > 1) {
const char *str_ptr; const char *str_ptr = NULL;
res = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 1, &str_ptr); res = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 1, &str_ptr);
if (res < 0) { if (res < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed"); SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
@ -179,11 +179,13 @@ DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (char *str)
if (unlikely(ssh == NULL)) if (unlikely(ssh == NULL))
goto error; goto error;
ssh->software_ver = (uint8_t *)SCStrdup((char*)str_ptr); ssh->software_ver = (uint8_t *)SCStrdup((char *)str_ptr);
if (ssh->software_ver == NULL) { if (ssh->software_ver == NULL) {
goto error; goto error;
} }
ssh->len = strlen((char *) ssh->software_ver); pcre_free_substring(str_ptr);
ssh->len = strlen((char *)ssh->software_ver);
SCLogDebug("will look for ssh %s", ssh->software_ver); SCLogDebug("will look for ssh %s", ssh->software_ver);
} }
@ -214,7 +216,8 @@ static int DetectSshSoftwareVersionSetup (DetectEngineCtx *de_ctx, Signature *s,
SigMatch *sm = NULL; SigMatch *sm = NULL;
ssh = DetectSshSoftwareVersionParse(str); ssh = DetectSshSoftwareVersionParse(str);
if (ssh == NULL) goto error; if (ssh == NULL)
goto error;
/* Okay so far so good, lets get this into a SigMatch /* Okay so far so good, lets get this into a SigMatch
* and put it in the Signature. */ * and put it in the Signature. */
@ -236,8 +239,10 @@ static int DetectSshSoftwareVersionSetup (DetectEngineCtx *de_ctx, Signature *s,
return 0; return 0;
error: error:
if (ssh != NULL) DetectSshSoftwareVersionFree(ssh); if (ssh != NULL)
if (sm != NULL) SCFree(sm); DetectSshSoftwareVersionFree(ssh);
if (sm != NULL)
SCFree(sm);
return -1; return -1;
} }
@ -248,8 +253,13 @@ error:
* \param id_d pointer to DetectSshSoftwareVersionData * \param id_d pointer to DetectSshSoftwareVersionData
*/ */
void DetectSshSoftwareVersionFree(void *ptr) { void DetectSshSoftwareVersionFree(void *ptr) {
DetectSshSoftwareVersionData *id_d = (DetectSshSoftwareVersionData *)ptr; if (ptr == NULL)
SCFree(id_d); return;
DetectSshSoftwareVersionData *ssh = (DetectSshSoftwareVersionData *)ptr;
if (ssh->software_ver != NULL)
SCFree(ssh->software_ver);
SCFree(ssh);
} }
#ifdef UNITTESTS /* UNITTESTS */ #ifdef UNITTESTS /* UNITTESTS */

Loading…
Cancel
Save