Skip to content

Commit

Permalink
Fix memory leaks in duo.c
Browse files Browse the repository at this point in the history
  • Loading branch information
ysyrota authored and AaronAtDuo committed Oct 21, 2024
1 parent a419fc1 commit d7db1c2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/duo.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ duo_login(struct duo_ctx *ctx, const char *username,
const char *client_ip, int flags, const char *command, const int failmode)
{
duo_code_t ret;
int size;
char buf[256];
char *pushinfo = NULL;
char p[256];
Expand Down Expand Up @@ -599,13 +600,23 @@ duo_login(struct duo_ctx *ctx, const char *username,
}

/* Add pushinfo parameters */
char *encoded_command = urlenc_encode(command);
if (encoded_command == NULL) {
return (DUO_LIB_ERROR);
}

local_ip = duo_local_ip();
if (asprintf(&pushinfo, "Server+IP=%s&Command=%s",
local_ip, command ? urlenc_encode(command) : "") < 0 ||
duo_add_param(ctx, "pushinfo", pushinfo) != DUO_OK) {
size = asprintf(&pushinfo, "Server+IP=%s&Command=%s", local_ip, encoded_command);
free(encoded_command);
if (size < 0) {
return (DUO_LIB_ERROR);
}

ret = duo_add_param(ctx, "pushinfo", pushinfo);
free(pushinfo);
if (ret != DUO_OK) {
return (DUO_LIB_ERROR);
}

/* Try Duo authentication. Only use the configured timeout if
* the call is asynchronous, because async calls should return
Expand Down Expand Up @@ -694,8 +705,10 @@ duo_login(struct duo_ctx *ctx, const char *username,
result);
ret = DUO_SERVER_ERROR;
}
_JSON_VALUE_FREE(json_new);
break;
}
_JSON_VALUE_FREE(json_new);
}
_JSON_VALUE_FREE(json);
return (ret);
Expand Down

0 comments on commit d7db1c2

Please sign in to comment.