Do not store SID string in a local buffer

https://fedorahosted.org/freeipa/ticket/3596
This commit is contained in:
Sumit Bose
2013-04-26 09:21:43 +02:00
committed by Rob Crittenden
parent 631b3cf7cd
commit 0f43cd6ea0

View File

@@ -432,7 +432,8 @@ int create_response(struct extdom_req *req, struct domain_info *domain_info,
struct extdom_res *res; struct extdom_res *res;
uint32_t id; uint32_t id;
enum idmap_error_code err; enum idmap_error_code err;
char sid_str[WBC_SID_STRING_BUFLEN + 1]; char *sid_str;
wbcErr werr;
res = malloc(sizeof(struct extdom_res)); res = malloc(sizeof(struct extdom_res));
if (res == NULL) { if (res == NULL) {
@@ -450,9 +451,8 @@ int create_response(struct extdom_req *req, struct domain_info *domain_info,
case INP_NAME: case INP_NAME:
res->response_type = RESP_SID; res->response_type = RESP_SID;
len = wbcSidToStringBuf(sid, sid_str, werr = wbcSidToString(sid, &sid_str);
WBC_SID_STRING_BUFLEN); if (!WBC_ERROR_IS_OK(werr)) {
if (len + 1 > WBC_SID_STRING_BUFLEN) {
ret = EINVAL; ret = EINVAL;
goto done; goto done;
} }
@@ -465,13 +465,14 @@ int create_response(struct extdom_req *req, struct domain_info *domain_info,
} }
break; break;
case REQ_FULL: case REQ_FULL:
len = wbcSidToStringBuf(sid, sid_str, WBC_SID_STRING_BUFLEN); len = wbcSidToString(sid, &sid_str);
if (len + 1 > WBC_SID_STRING_BUFLEN) { if (!WBC_ERROR_IS_OK(werr)) {
ret = EINVAL; ret = EINVAL;
goto done; goto done;
} }
err = sss_idmap_sid_to_unix(domain_info->idmap_ctx, sid_str, &id); err = sss_idmap_sid_to_unix(domain_info->idmap_ctx, sid_str, &id);
wbcFreeMemory(sid_str);
if (err != IDMAP_SUCCESS) { if (err != IDMAP_SUCCESS) {
ret = EINVAL; ret = EINVAL;
goto done; goto done;
@@ -566,6 +567,7 @@ int pack_response(struct extdom_res *res, struct berval **ret_val)
switch (res->response_type) { switch (res->response_type) {
case RESP_SID: case RESP_SID:
ret = ber_printf(ber,"{es}", res->response_type, res->data.sid); ret = ber_printf(ber,"{es}", res->response_type, res->data.sid);
wbcFreeMemory(res->data.sid);
break; break;
case RESP_NAME: case RESP_NAME:
ret = ber_printf(ber,"{e{ss}}", res->response_type, ret = ber_printf(ber,"{e{ss}}", res->response_type,