project
stringclasses 633
values | commit_id
stringlengths 7
81
| target
int64 0
1
| func
stringlengths 5
484k
| cwe
stringclasses 131
values | big_vul_idx
float64 0
189k
⌀ | idx
int64 0
522k
| hash
stringlengths 34
39
| size
float64 1
24k
⌀ | message
stringlengths 0
11.5k
⌀ | dataset
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static struct samldb_ctx *samldb_ctx_init(struct ldb_module *module,
struct ldb_request *req)
{
struct ldb_context *ldb;
struct samldb_ctx *ac;
ldb = ldb_module_get_ctx(module);
ac = talloc_zero(req, struct samldb_ctx);
if (ac == NULL) {
ldb_oom(ldb);
return NULL;
}
ac->module = module;
ac->req = req;
return ac;
}
|
CWE-264
| 8 | 10,849 |
33409164939998819009491676712734100433
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_fill_foreignSecurityPrincipal_object(struct samldb_ctx *ac)
{
struct ldb_context *ldb;
const struct ldb_val *rdn_value;
struct dom_sid *sid;
int ret;
ldb = ldb_module_get_ctx(ac->module);
sid = samdb_result_dom_sid(ac->msg, ac->msg, "objectSid");
if (sid == NULL) {
rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
if (rdn_value == NULL) {
return ldb_operr(ldb);
}
sid = dom_sid_parse_talloc(ac->msg,
(const char *)rdn_value->data);
if (sid == NULL) {
ldb_set_errstring(ldb,
"samldb: No valid SID found in ForeignSecurityPrincipal CN!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
if (! samldb_msg_add_sid(ac->msg, "objectSid", sid)) {
return ldb_operr(ldb);
}
}
/* finally proceed with adding the entry */
ret = samldb_add_step(ac, samldb_add_entry);
if (ret != LDB_SUCCESS) return ret;
return samldb_first_step(ac);
}
|
CWE-264
| 9 | 10,850 |
64065653880728031503073838568297939860
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_fill_object(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
int ret;
/* Add information for the different account types */
switch(ac->type) {
case SAMLDB_TYPE_USER: {
struct ldb_control *rodc_control = ldb_request_get_control(ac->req,
LDB_CONTROL_RODC_DCPROMO_OID);
if (rodc_control != NULL) {
/* see [MS-ADTS] 3.1.1.3.4.1.23 LDAP_SERVER_RODC_DCPROMO_OID */
rodc_control->critical = false;
ret = samldb_add_step(ac, samldb_rodc_add);
if (ret != LDB_SUCCESS) return ret;
}
/* check if we have a valid sAMAccountName */
ret = samldb_add_step(ac, samldb_check_sAMAccountName);
if (ret != LDB_SUCCESS) return ret;
ret = samldb_add_step(ac, samldb_add_entry);
if (ret != LDB_SUCCESS) return ret;
break;
}
case SAMLDB_TYPE_GROUP: {
/* check if we have a valid sAMAccountName */
ret = samldb_add_step(ac, samldb_check_sAMAccountName);
if (ret != LDB_SUCCESS) return ret;
ret = samldb_add_step(ac, samldb_add_entry);
if (ret != LDB_SUCCESS) return ret;
break;
}
case SAMLDB_TYPE_CLASS: {
const struct ldb_val *rdn_value, *def_obj_cat_val;
unsigned int v = ldb_msg_find_attr_as_uint(ac->msg, "objectClassCategory", -2);
/* As discussed with Microsoft through dochelp in April 2012 this is the behavior of windows*/
if (!ldb_msg_find_element(ac->msg, "subClassOf")) {
ret = ldb_msg_add_string(ac->msg, "subClassOf", "top");
if (ret != LDB_SUCCESS) return ret;
}
ret = samdb_find_or_add_attribute(ldb, ac->msg,
"rdnAttId", "cn");
if (ret != LDB_SUCCESS) return ret;
/* do not allow to mark an attributeSchema as RODC filtered if it
* is system-critical */
if (check_rodc_critical_attribute(ac->msg)) {
ldb_asprintf_errstring(ldb, "Refusing schema add of %s - cannot combine critical class with RODC filtering",
ldb_dn_get_linearized(ac->msg->dn));
return LDB_ERR_UNWILLING_TO_PERFORM;
}
rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
if (rdn_value == NULL) {
return ldb_operr(ldb);
}
if (!ldb_msg_find_element(ac->msg, "lDAPDisplayName")) {
/* the RDN has prefix "CN" */
ret = ldb_msg_add_string(ac->msg, "lDAPDisplayName",
samdb_cn_to_lDAPDisplayName(ac->msg,
(const char *) rdn_value->data));
if (ret != LDB_SUCCESS) {
ldb_oom(ldb);
return ret;
}
}
if (!ldb_msg_find_element(ac->msg, "schemaIDGUID")) {
struct GUID guid;
/* a new GUID */
guid = GUID_random();
ret = dsdb_msg_add_guid(ac->msg, &guid, "schemaIDGUID");
if (ret != LDB_SUCCESS) {
ldb_oom(ldb);
return ret;
}
}
def_obj_cat_val = ldb_msg_find_ldb_val(ac->msg,
"defaultObjectCategory");
if (def_obj_cat_val != NULL) {
/* "defaultObjectCategory" has been set by the caller.
* Do some checks for consistency.
* NOTE: The real constraint check (that
* 'defaultObjectCategory' is the DN of the new
* objectclass or any parent of it) is still incomplete.
* For now we say that 'defaultObjectCategory' is valid
* if it exists and it is of objectclass "classSchema".
*/
ac->dn = ldb_dn_from_ldb_val(ac, ldb, def_obj_cat_val);
if (ac->dn == NULL) {
ldb_set_errstring(ldb,
"Invalid DN for 'defaultObjectCategory'!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
} else {
/* "defaultObjectCategory" has not been set by the
* caller. Use the entry DN for it. */
ac->dn = ac->msg->dn;
ret = ldb_msg_add_string(ac->msg, "defaultObjectCategory",
ldb_dn_alloc_linearized(ac->msg, ac->dn));
if (ret != LDB_SUCCESS) {
ldb_oom(ldb);
return ret;
}
}
ret = samldb_add_step(ac, samldb_add_entry);
if (ret != LDB_SUCCESS) return ret;
/* Now perform the checks for the 'defaultObjectCategory'. The
* lookup DN was already saved in "ac->dn" */
ret = samldb_add_step(ac, samldb_find_for_defaultObjectCategory);
if (ret != LDB_SUCCESS) return ret;
/* -2 is not a valid objectClassCategory so it means the attribute wasn't present */
if (v == -2) {
/* Windows 2003 does this*/
ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg, "objectClassCategory", 0);
if (ret != LDB_SUCCESS) {
return ret;
}
}
break;
}
case SAMLDB_TYPE_ATTRIBUTE: {
const struct ldb_val *rdn_value;
struct ldb_message_element *el;
rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
if (rdn_value == NULL) {
return ldb_operr(ldb);
}
if (!ldb_msg_find_element(ac->msg, "lDAPDisplayName")) {
/* the RDN has prefix "CN" */
ret = ldb_msg_add_string(ac->msg, "lDAPDisplayName",
samdb_cn_to_lDAPDisplayName(ac->msg,
(const char *) rdn_value->data));
if (ret != LDB_SUCCESS) {
ldb_oom(ldb);
return ret;
}
}
/* do not allow to mark an attributeSchema as RODC filtered if it
* is system-critical */
if (check_rodc_critical_attribute(ac->msg)) {
ldb_asprintf_errstring(ldb,
"samldb: refusing schema add of %s - cannot combine critical attribute with RODC filtering",
ldb_dn_get_linearized(ac->msg->dn));
return LDB_ERR_UNWILLING_TO_PERFORM;
}
ret = samdb_find_or_add_attribute(ldb, ac->msg,
"isSingleValued", "FALSE");
if (ret != LDB_SUCCESS) return ret;
if (!ldb_msg_find_element(ac->msg, "schemaIDGUID")) {
struct GUID guid;
/* a new GUID */
guid = GUID_random();
ret = dsdb_msg_add_guid(ac->msg, &guid, "schemaIDGUID");
if (ret != LDB_SUCCESS) {
ldb_oom(ldb);
return ret;
}
}
el = ldb_msg_find_element(ac->msg, "attributeSyntax");
if (el) {
/*
* No need to scream if there isn't as we have code later on
* that will take care of it.
*/
const struct dsdb_syntax *syntax = find_syntax_map_by_ad_oid((const char *)el->values[0].data);
if (!syntax) {
DEBUG(9, ("Can't find dsdb_syntax object for attributeSyntax %s\n",
(const char *)el->values[0].data));
} else {
unsigned int v = ldb_msg_find_attr_as_uint(ac->msg, "oMSyntax", 0);
const struct ldb_val *val = ldb_msg_find_ldb_val(ac->msg, "oMObjectClass");
if (v == 0) {
ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg, "oMSyntax", syntax->oMSyntax);
if (ret != LDB_SUCCESS) {
return ret;
}
}
if (!val) {
struct ldb_val val2 = ldb_val_dup(ldb, &syntax->oMObjectClass);
if (val2.length > 0) {
ret = ldb_msg_add_value(ac->msg, "oMObjectClass", &val2, NULL);
if (ret != LDB_SUCCESS) {
return ret;
}
}
}
}
}
/* handle msDS-IntID attribute */
ret = samldb_add_handle_msDS_IntId(ac);
if (ret != LDB_SUCCESS) return ret;
ret = samldb_add_step(ac, samldb_add_entry);
if (ret != LDB_SUCCESS) return ret;
break;
}
default:
ldb_asprintf_errstring(ldb, "Invalid entry type!");
return LDB_ERR_OPERATIONS_ERROR;
break;
}
return samldb_first_step(ac);
}
|
CWE-264
| 10 | 10,851 |
332983770533932389897175590672491498967
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_find_for_defaultObjectCategory(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
struct ldb_result *res;
const char * const no_attrs[] = { NULL };
int ret;
ac->res_dn = NULL;
ret = dsdb_module_search(ac->module, ac, &res,
ac->dn, LDB_SCOPE_BASE, no_attrs,
DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT
| DSDB_FLAG_NEXT_MODULE,
ac->req,
"(objectClass=classSchema)");
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/* Don't be pricky when the DN doesn't exist if we have the */
/* RELAX control specified */
if (ldb_request_get_control(ac->req,
LDB_CONTROL_RELAX_OID) == NULL) {
ldb_set_errstring(ldb,
"samldb_find_defaultObjectCategory: "
"Invalid DN for 'defaultObjectCategory'!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
}
if ((ret != LDB_ERR_NO_SUCH_OBJECT) && (ret != LDB_SUCCESS)) {
return ret;
}
if (ret == LDB_SUCCESS) {
/* ensure the defaultObjectCategory has a full GUID */
struct ldb_message *m;
m = ldb_msg_new(ac->msg);
if (m == NULL) {
return ldb_oom(ldb);
}
m->dn = ac->msg->dn;
if (ldb_msg_add_string(m, "defaultObjectCategory",
ldb_dn_get_extended_linearized(m, res->msgs[0]->dn, 1)) !=
LDB_SUCCESS) {
return ldb_oom(ldb);
}
m->elements[0].flags = LDB_FLAG_MOD_REPLACE;
ret = dsdb_module_modify(ac->module, m,
DSDB_FLAG_NEXT_MODULE,
ac->req);
if (ret != LDB_SUCCESS) {
return ret;
}
}
ac->res_dn = ac->dn;
return samldb_next_step(ac);
}
|
CWE-264
| 11 | 10,852 |
16016152656821252791356816207997647468
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_generate_sAMAccountName(struct ldb_context *ldb,
struct ldb_message *msg)
{
char *name;
/* Format: $000000-000000000000 */
name = talloc_asprintf(msg, "$%.6X-%.6X%.6X",
(unsigned int)generate_random(),
(unsigned int)generate_random(),
(unsigned int)generate_random());
if (name == NULL) {
return ldb_oom(ldb);
}
return ldb_msg_add_steal_string(msg, "sAMAccountName", name);
}
|
CWE-264
| 13 | 10,853 |
144000559426107228113575444282809173073
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static bool samldb_krbtgtnumber_available(struct samldb_ctx *ac,
uint32_t krbtgt_number)
{
TALLOC_CTX *tmp_ctx = talloc_new(ac);
struct ldb_result *res;
const char * const no_attrs[] = { NULL };
int ret;
ret = dsdb_module_search(ac->module, tmp_ctx, &res,
ldb_get_default_basedn(ldb_module_get_ctx(ac->module)),
LDB_SCOPE_SUBTREE, no_attrs,
DSDB_FLAG_NEXT_MODULE,
ac->req,
"(msDC-SecondaryKrbTgtNumber=%u)",
krbtgt_number);
if (ret == LDB_SUCCESS && res->count == 0) {
talloc_free(tmp_ctx);
return true;
}
talloc_free(tmp_ctx);
return false;
}
|
CWE-264
| 14 | 10,854 |
114762117569192857002089061200131154758
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static bool samldb_msg_add_sid(struct ldb_message *msg,
const char *name,
const struct dom_sid *sid)
{
struct ldb_val v;
enum ndr_err_code ndr_err;
ndr_err = ndr_push_struct_blob(&v, msg, sid,
(ndr_push_flags_fn_t)ndr_push_dom_sid);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
return false;
}
return (ldb_msg_add_value(msg, name, &v, NULL) == 0);
}
|
CWE-264
| 15 | 10,855 |
151991456869611994955091355164934666804
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_next_step(struct samldb_ctx *ac)
{
if (ac->curstep->next) {
ac->curstep = ac->curstep->next;
return ac->curstep->fn(ac);
}
/* We exit the samldb module here. If someone set an "ares" to forward
* controls and response back to the caller, use them. */
if (ac->ares) {
return ldb_module_done(ac->req, ac->ares->controls,
ac->ares->response, LDB_SUCCESS);
} else {
return ldb_module_done(ac->req, NULL, NULL, LDB_SUCCESS);
}
}
|
CWE-264
| 16 | 10,856 |
201757716713846839990391257467248011220
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_prim_group_change(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const char * const attrs[] = {
"primaryGroupID",
"memberOf",
"userAccountControl",
NULL };
struct ldb_result *res, *group_res;
struct ldb_message_element *el;
struct ldb_message *msg;
uint32_t prev_rid, new_rid, uac;
struct dom_sid *prev_sid, *new_sid;
struct ldb_dn *prev_prim_group_dn, *new_prim_group_dn;
int ret;
const char * const noattrs[] = { NULL };
el = dsdb_get_single_valued_attr(ac->msg, "primaryGroupID",
ac->req->operation);
if (el == NULL) {
/* we are not affected */
return LDB_SUCCESS;
}
/* Fetch information from the existing object */
ret = dsdb_module_search_dn(ac->module, ac, &res, ac->msg->dn, attrs,
DSDB_FLAG_NEXT_MODULE, ac->req);
if (ret != LDB_SUCCESS) {
return ret;
}
uac = ldb_msg_find_attr_as_uint(res->msgs[0], "userAccountControl", 0);
/* Finds out the DN of the old primary group */
prev_rid = ldb_msg_find_attr_as_uint(res->msgs[0], "primaryGroupID",
(uint32_t) -1);
if (prev_rid == (uint32_t) -1) {
/* User objects do always have a mandatory "primaryGroupID"
* attribute. If this doesn't exist then the object is of the
* wrong type. This is the exact Windows error code */
return LDB_ERR_OBJECT_CLASS_VIOLATION;
}
prev_sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), prev_rid);
if (prev_sid == NULL) {
return ldb_operr(ldb);
}
/* Finds out the DN of the new primary group
* Notice: in order to parse the primary group ID correctly we create
* a temporary message here. */
msg = ldb_msg_new(ac->msg);
if (msg == NULL) {
return ldb_module_oom(ac->module);
}
ret = ldb_msg_add(msg, el, 0);
if (ret != LDB_SUCCESS) {
return ret;
}
new_rid = ldb_msg_find_attr_as_uint(msg, "primaryGroupID", (uint32_t) -1);
talloc_free(msg);
if (new_rid == (uint32_t) -1) {
/* we aren't affected of any primary group change */
return LDB_SUCCESS;
}
if (prev_rid == new_rid) {
return LDB_SUCCESS;
}
if ((uac & UF_SERVER_TRUST_ACCOUNT) && new_rid != DOMAIN_RID_DCS) {
ldb_asprintf_errstring(ldb,
"%08X: samldb: UF_SERVER_TRUST_ACCOUNT requires "
"primaryGroupID=%u!",
W_ERROR_V(WERR_DS_CANT_MOD_PRIMARYGROUPID),
DOMAIN_RID_DCS);
return LDB_ERR_UNWILLING_TO_PERFORM;
}
if ((uac & UF_PARTIAL_SECRETS_ACCOUNT) && new_rid != DOMAIN_RID_READONLY_DCS) {
ldb_asprintf_errstring(ldb,
"%08X: samldb: UF_PARTIAL_SECRETS_ACCOUNT requires "
"primaryGroupID=%u!",
W_ERROR_V(WERR_DS_CANT_MOD_PRIMARYGROUPID),
DOMAIN_RID_READONLY_DCS);
return LDB_ERR_UNWILLING_TO_PERFORM;
}
ret = dsdb_module_search(ac->module, ac, &group_res,
ldb_get_default_basedn(ldb),
LDB_SCOPE_SUBTREE,
noattrs, DSDB_FLAG_NEXT_MODULE,
ac->req,
"(objectSid=%s)",
ldap_encode_ndr_dom_sid(ac, prev_sid));
if (ret != LDB_SUCCESS) {
return ret;
}
if (group_res->count != 1) {
return ldb_operr(ldb);
}
prev_prim_group_dn = group_res->msgs[0]->dn;
new_sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), new_rid);
if (new_sid == NULL) {
return ldb_operr(ldb);
}
ret = dsdb_module_search(ac->module, ac, &group_res,
ldb_get_default_basedn(ldb),
LDB_SCOPE_SUBTREE,
noattrs, DSDB_FLAG_NEXT_MODULE,
ac->req,
"(objectSid=%s)",
ldap_encode_ndr_dom_sid(ac, new_sid));
if (ret != LDB_SUCCESS) {
return ret;
}
if (group_res->count != 1) {
/* Here we know if the specified new primary group candidate is
* valid or not. */
return LDB_ERR_UNWILLING_TO_PERFORM;
}
new_prim_group_dn = group_res->msgs[0]->dn;
/* We need to be already a normal member of the new primary
* group in order to be successful. */
el = samdb_find_attribute(ldb, res->msgs[0], "memberOf",
ldb_dn_get_linearized(new_prim_group_dn));
if (el == NULL) {
return LDB_ERR_UNWILLING_TO_PERFORM;
}
/* Remove the "member" attribute on the new primary group */
msg = ldb_msg_new(ac->msg);
if (msg == NULL) {
return ldb_module_oom(ac->module);
}
msg->dn = new_prim_group_dn;
ret = samdb_msg_add_delval(ldb, msg, msg, "member",
ldb_dn_get_linearized(ac->msg->dn));
if (ret != LDB_SUCCESS) {
return ret;
}
ret = dsdb_module_modify(ac->module, msg, DSDB_FLAG_NEXT_MODULE, ac->req);
if (ret != LDB_SUCCESS) {
return ret;
}
talloc_free(msg);
/* Add a "member" attribute for the previous primary group */
msg = ldb_msg_new(ac->msg);
if (msg == NULL) {
return ldb_module_oom(ac->module);
}
msg->dn = prev_prim_group_dn;
ret = samdb_msg_add_addval(ldb, msg, msg, "member",
ldb_dn_get_linearized(ac->msg->dn));
if (ret != LDB_SUCCESS) {
return ret;
}
ret = dsdb_module_modify(ac->module, msg, DSDB_FLAG_NEXT_MODULE, ac->req);
if (ret != LDB_SUCCESS) {
return ret;
}
talloc_free(msg);
return LDB_SUCCESS;
}
|
CWE-264
| 18 | 10,857 |
53071370069428719544350746304764764820
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_prim_group_set(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
uint32_t rid;
rid = ldb_msg_find_attr_as_uint(ac->msg, "primaryGroupID", (uint32_t) -1);
if (rid == (uint32_t) -1) {
/* we aren't affected of any primary group set */
return LDB_SUCCESS;
} else if (!ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
ldb_set_errstring(ldb,
"The primary group isn't settable on add operations!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
return samldb_prim_group_tester(ac, rid);
}
|
CWE-264
| 19 | 10,858 |
171439677298984702415103701585012421259
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_prim_group_trigger(struct samldb_ctx *ac)
{
int ret;
if (ac->req->operation == LDB_ADD) {
ret = samldb_prim_group_set(ac);
} else {
ret = samldb_prim_group_change(ac);
}
return ret;
}
|
CWE-264
| 21 | 10,859 |
67605757629056264991028916502662116078
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_rodc_add(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
uint32_t krbtgt_number, i_start, i;
int ret;
char *newpass;
struct ldb_val newpass_utf16;
/* find a unused msDC-SecondaryKrbTgtNumber */
i_start = generate_random() & 0xFFFF;
if (i_start == 0) {
i_start = 1;
}
for (i=i_start; i<=0xFFFF; i++) {
if (samldb_krbtgtnumber_available(ac, i)) {
krbtgt_number = i;
goto found;
}
}
for (i=1; i<i_start; i++) {
if (samldb_krbtgtnumber_available(ac, i)) {
krbtgt_number = i;
goto found;
}
}
ldb_asprintf_errstring(ldb,
"%08X: Unable to find available msDS-SecondaryKrbTgtNumber",
W_ERROR_V(WERR_NO_SYSTEM_RESOURCES));
return LDB_ERR_OTHER;
found:
ret = ldb_msg_add_empty(ac->msg, "msDS-SecondaryKrbTgtNumber",
LDB_FLAG_INTERNAL_DISABLE_VALIDATION, NULL);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
"msDS-SecondaryKrbTgtNumber", krbtgt_number);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
ret = ldb_msg_add_fmt(ac->msg, "sAMAccountName", "krbtgt_%u",
krbtgt_number);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
newpass = generate_random_password(ac->msg, 128, 255);
if (newpass == NULL) {
return ldb_operr(ldb);
}
if (!convert_string_talloc(ac,
CH_UNIX, CH_UTF16,
newpass, strlen(newpass),
(void *)&newpass_utf16.data,
&newpass_utf16.length)) {
ldb_asprintf_errstring(ldb,
"samldb_rodc_add: "
"failed to generate UTF16 password from random password");
return LDB_ERR_OPERATIONS_ERROR;
}
ret = ldb_msg_add_steal_value(ac->msg, "clearTextPassword", &newpass_utf16);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
return samldb_next_step(ac);
}
|
CWE-264
| 22 | 10,860 |
180235104119860086378601923104425100972
| null | null | null |
samba
|
b000da128b5fb519d2d3f2e7fd20e4a25b7dae7d
| 0 |
static int samldb_schema_info_update(struct samldb_ctx *ac)
{
int ret;
struct ldb_context *ldb;
struct dsdb_schema *schema;
/* replicated update should always go through */
if (ldb_request_get_control(ac->req,
DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
return LDB_SUCCESS;
}
/* do not update schemaInfo during provisioning */
if (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
return LDB_SUCCESS;
}
ldb = ldb_module_get_ctx(ac->module);
schema = dsdb_get_schema(ldb, NULL);
if (!schema) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
"samldb_schema_info_update: no dsdb_schema loaded");
DEBUG(0,(__location__ ": %s\n", ldb_errstring(ldb)));
return ldb_operr(ldb);
}
ret = dsdb_module_schema_info_update(ac->module, schema,
DSDB_FLAG_NEXT_MODULE|
DSDB_FLAG_AS_SYSTEM,
ac->req);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb,
"samldb_schema_info_update: dsdb_module_schema_info_update failed with %s",
ldb_errstring(ldb));
return ret;
}
return LDB_SUCCESS;
}
|
CWE-264
| 23 | 10,861 |
185734863583902113576699674447908279802
| null | null | null |
savannah
|
63451a06b7484d220750ed8574d3ee84e156daf5
| 0 |
int main(int argc, char *argv[])
{
int opt;
char *line;
progname = basename(argv[0]);
#if POSIXLY_CORRECT
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#else
if (getenv(POSIXLY_CORRECT_STR))
posixly_correct = 1;
if (!posixly_correct)
cmd_line_options = CMD_LINE_OPTIONS;
else
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#endif
setlocale(LC_CTYPE, "");
setlocale(LC_MESSAGES, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
/* Align `#effective:' comments to column 40 for tty's */
if (!posixly_correct && isatty(fileno(stdout)))
print_options |= TEXT_SMART_INDENT;
while ((opt = getopt_long(argc, argv, cmd_line_options,
long_options, NULL)) != -1) {
switch (opt) {
case 'a': /* acl only */
if (posixly_correct)
goto synopsis;
opt_print_acl = 1;
break;
case 'd': /* default acl only */
opt_print_default_acl = 1;
break;
case 'c': /* no comments */
if (posixly_correct)
goto synopsis;
opt_comments = 0;
break;
case 'e': /* all #effective comments */
if (posixly_correct)
goto synopsis;
print_options |= TEXT_ALL_EFFECTIVE;
break;
case 'E': /* no #effective comments */
if (posixly_correct)
goto synopsis;
print_options &= ~(TEXT_SOME_EFFECTIVE |
TEXT_ALL_EFFECTIVE);
break;
case 'R': /* recursive */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_RECURSIVE;
break;
case 'L': /* follow all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_LOGICAL;
walk_flags &= ~WALK_TREE_PHYSICAL;
break;
case 'P': /* skip all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_PHYSICAL;
walk_flags &= ~WALK_TREE_LOGICAL;
break;
case 's': /* skip files with only base entries */
if (posixly_correct)
goto synopsis;
opt_skip_base = 1;
break;
case 'p':
if (posixly_correct)
goto synopsis;
opt_strip_leading_slash = 0;
break;
case 't':
if (posixly_correct)
goto synopsis;
opt_tabular = 1;
break;
case 'n': /* numeric */
opt_numeric = 1;
print_options |= TEXT_NUMERIC_IDS;
break;
case 'v': /* print version */
printf("%s " VERSION "\n", progname);
return 0;
case 'h': /* help */
help();
return 0;
case ':': /* option missing */
case '?': /* unknown option */
default:
goto synopsis;
}
}
if (!(opt_print_acl || opt_print_default_acl)) {
opt_print_acl = 1;
if (!posixly_correct)
opt_print_default_acl = 1;
}
if ((optind == argc) && !posixly_correct)
goto synopsis;
do {
if (optind == argc ||
strcmp(argv[optind], "-") == 0) {
while ((line = next_line(stdin)) != NULL) {
if (*line == '\0')
continue;
had_errors += walk_tree(line, walk_flags, 0,
do_print, NULL);
}
if (!feof(stdin)) {
fprintf(stderr, _("%s: Standard input: %s\n"),
progname, strerror(errno));
had_errors++;
}
} else
had_errors += walk_tree(argv[optind], walk_flags, 0,
do_print, NULL);
optind++;
} while (optind < argc);
return had_errors ? 1 : 0;
synopsis:
fprintf(stderr, _("Usage: %s [-%s] file ...\n"),
progname, cmd_line_options);
fprintf(stderr, _("Try `%s --help' for more information.\n"),
progname);
return 2;
}
|
CWE-264
| 33 | 10,868 |
24592511408202601751363998357813553872
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
static char * MS_CALLBACK srp_password_from_info_cb(SSL *s, void *arg)
{
return BUF_strdup(s->srp_ctx.info) ;
}
|
CWE-310
| 76 | 10,871 |
83873800857306004330212817337297480940
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
{
int ret=0;
#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
if (
#ifndef OPENSSL_NO_RSA
cmd == SSL_CTRL_SET_TMP_RSA_CB ||
#endif
#ifndef OPENSSL_NO_DSA
cmd == SSL_CTRL_SET_TMP_DH_CB ||
#endif
0)
{
if (!ssl_cert_inst(&s->cert))
{
SSLerr(SSL_F_SSL3_CALLBACK_CTRL, ERR_R_MALLOC_FAILURE);
return(0);
}
}
#endif
switch (cmd)
{
#ifndef OPENSSL_NO_RSA
case SSL_CTRL_SET_TMP_RSA_CB:
{
s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
}
break;
#endif
#ifndef OPENSSL_NO_DH
case SSL_CTRL_SET_TMP_DH_CB:
{
s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
}
break;
#endif
#ifndef OPENSSL_NO_ECDH
case SSL_CTRL_SET_TMP_ECDH_CB:
{
s->cert->ecdh_tmp_cb = (EC_KEY *(*)(SSL *, int, int))fp;
}
break;
#endif
#ifndef OPENSSL_NO_TLSEXT
case SSL_CTRL_SET_TLSEXT_DEBUG_CB:
s->tlsext_debug_cb=(void (*)(SSL *,int ,int,
unsigned char *, int, void *))fp;
break;
#endif
default:
break;
}
return(ret);
}
|
CWE-310
| 77 | 10,872 |
156133537989166822799500351901289545949
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
STACK_OF(SSL_CIPHER) *srvr)
{
SSL_CIPHER *c,*ret=NULL;
STACK_OF(SSL_CIPHER) *prio, *allow;
int i,ii,ok;
#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_EC)
unsigned int j;
int ec_ok, ec_nid;
unsigned char ec_search1 = 0, ec_search2 = 0;
#endif
CERT *cert;
unsigned long alg_k,alg_a,mask_k,mask_a,emask_k,emask_a;
/* Let's see which ciphers we can support */
cert=s->cert;
#if 0
/* Do not set the compare functions, because this may lead to a
* reordering by "id". We want to keep the original ordering.
* We may pay a price in performance during sk_SSL_CIPHER_find(),
* but would have to pay with the price of sk_SSL_CIPHER_dup().
*/
sk_SSL_CIPHER_set_cmp_func(srvr, ssl_cipher_ptr_id_cmp);
sk_SSL_CIPHER_set_cmp_func(clnt, ssl_cipher_ptr_id_cmp);
#endif
#ifdef CIPHER_DEBUG
printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), (void *)srvr);
for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i)
{
c=sk_SSL_CIPHER_value(srvr,i);
printf("%p:%s\n",(void *)c,c->name);
}
printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), (void *)clnt);
for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i)
{
c=sk_SSL_CIPHER_value(clnt,i);
printf("%p:%s\n",(void *)c,c->name);
}
#endif
if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE)
{
prio = srvr;
allow = clnt;
}
else
{
prio = clnt;
allow = srvr;
}
for (i=0; i<sk_SSL_CIPHER_num(prio); i++)
{
c=sk_SSL_CIPHER_value(prio,i);
/* Skip TLS v1.2 only ciphersuites if lower than v1.2 */
if ((c->algorithm_ssl & SSL_TLSV1_2) &&
(TLS1_get_version(s) < TLS1_2_VERSION))
continue;
ssl_set_cert_masks(cert,c);
mask_k = cert->mask_k;
mask_a = cert->mask_a;
emask_k = cert->export_mask_k;
emask_a = cert->export_mask_a;
#ifndef OPENSSL_NO_SRP
mask_k=cert->mask_k | s->srp_ctx.srp_Mask;
emask_k=cert->export_mask_k | s->srp_ctx.srp_Mask;
#endif
#ifdef KSSL_DEBUG
/* printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);*/
#endif /* KSSL_DEBUG */
alg_k=c->algorithm_mkey;
alg_a=c->algorithm_auth;
#ifndef OPENSSL_NO_KRB5
if (alg_k & SSL_kKRB5)
{
if ( !kssl_keytab_is_available(s->kssl_ctx) )
continue;
}
#endif /* OPENSSL_NO_KRB5 */
#ifndef OPENSSL_NO_PSK
/* with PSK there must be server callback set */
if ((alg_k & SSL_kPSK) && s->psk_server_callback == NULL)
continue;
#endif /* OPENSSL_NO_PSK */
if (SSL_C_IS_EXPORT(c))
{
ok = (alg_k & emask_k) && (alg_a & emask_a);
#ifdef CIPHER_DEBUG
printf("%d:[%08lX:%08lX:%08lX:%08lX]%p:%s (export)\n",ok,alg_k,alg_a,emask_k,emask_a,
(void *)c,c->name);
#endif
}
else
{
ok = (alg_k & mask_k) && (alg_a & mask_a);
#ifdef CIPHER_DEBUG
printf("%d:[%08lX:%08lX:%08lX:%08lX]%p:%s\n",ok,alg_k,alg_a,mask_k,mask_a,(void *)c,
c->name);
#endif
}
#ifndef OPENSSL_NO_TLSEXT
#ifndef OPENSSL_NO_EC
if (
/* if we are considering an ECC cipher suite that uses our certificate */
(alg_a & SSL_aECDSA || alg_a & SSL_aECDH)
/* and we have an ECC certificate */
&& (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL)
/* and the client specified a Supported Point Formats extension */
&& ((s->session->tlsext_ecpointformatlist_length > 0) && (s->session->tlsext_ecpointformatlist != NULL))
/* and our certificate's point is compressed */
&& (
(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info != NULL)
&& (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key != NULL)
&& (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key != NULL)
&& (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data != NULL)
&& (
(*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED)
|| (*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED + 1)
)
)
)
{
ec_ok = 0;
/* if our certificate's curve is over a field type that the client does not support
* then do not allow this cipher suite to be negotiated */
if (
(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL)
&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL)
&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL)
&& (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field)
)
{
for (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++)
{
if (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime)
{
ec_ok = 1;
break;
}
}
}
else if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field)
{
for (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++)
{
if (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2)
{
ec_ok = 1;
break;
}
}
}
ok = ok && ec_ok;
}
if (
/* if we are considering an ECC cipher suite that uses our certificate */
(alg_a & SSL_aECDSA || alg_a & SSL_aECDH)
/* and we have an ECC certificate */
&& (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL)
/* and the client specified an EllipticCurves extension */
&& ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL))
)
{
ec_ok = 0;
if (
(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL)
&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL)
)
{
ec_nid = EC_GROUP_get_curve_name(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group);
if ((ec_nid == 0)
&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL)
)
{
if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field)
{
ec_search1 = 0xFF;
ec_search2 = 0x01;
}
else if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field)
{
ec_search1 = 0xFF;
ec_search2 = 0x02;
}
}
else
{
ec_search1 = 0x00;
ec_search2 = tls1_ec_nid2curve_id(ec_nid);
}
if ((ec_search1 != 0) || (ec_search2 != 0))
{
for (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++)
{
if ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2))
{
ec_ok = 1;
break;
}
}
}
}
ok = ok && ec_ok;
}
if (
/* if we are considering an ECC cipher suite that uses an ephemeral EC key */
(alg_k & SSL_kEECDH)
/* and we have an ephemeral EC key */
&& (s->cert->ecdh_tmp != NULL)
/* and the client specified an EllipticCurves extension */
&& ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL))
)
{
ec_ok = 0;
if (s->cert->ecdh_tmp->group != NULL)
{
ec_nid = EC_GROUP_get_curve_name(s->cert->ecdh_tmp->group);
if ((ec_nid == 0)
&& (s->cert->ecdh_tmp->group->meth != NULL)
)
{
if (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_prime_field)
{
ec_search1 = 0xFF;
ec_search2 = 0x01;
}
else if (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_characteristic_two_field)
{
ec_search1 = 0xFF;
ec_search2 = 0x02;
}
}
else
{
ec_search1 = 0x00;
ec_search2 = tls1_ec_nid2curve_id(ec_nid);
}
if ((ec_search1 != 0) || (ec_search2 != 0))
{
for (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++)
{
if ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2))
{
ec_ok = 1;
break;
}
}
}
}
ok = ok && ec_ok;
}
#endif /* OPENSSL_NO_EC */
#endif /* OPENSSL_NO_TLSEXT */
if (!ok) continue;
ii=sk_SSL_CIPHER_find(allow,c);
if (ii >= 0)
{
#if !defined(OPENSSL_NO_EC) && !defined(OPENSSL_NO_TLSEXT)
if ((alg_k & SSL_kEECDH) && (alg_a & SSL_aECDSA) && s->s3->is_probably_safari)
{
if (!ret) ret=sk_SSL_CIPHER_value(allow,ii);
continue;
}
#endif
ret=sk_SSL_CIPHER_value(allow,ii);
break;
}
}
return(ret);
}
|
CWE-310
| 78 | 10,873 |
109588182860342704100860220937740328887
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
void ssl3_clear(SSL *s)
{
unsigned char *rp,*wp;
size_t rlen, wlen;
int init_extra;
#ifdef TLSEXT_TYPE_opaque_prf_input
if (s->s3->client_opaque_prf_input != NULL)
OPENSSL_free(s->s3->client_opaque_prf_input);
s->s3->client_opaque_prf_input = NULL;
if (s->s3->server_opaque_prf_input != NULL)
OPENSSL_free(s->s3->server_opaque_prf_input);
s->s3->server_opaque_prf_input = NULL;
#endif
ssl3_cleanup_key_block(s);
if (s->s3->tmp.ca_names != NULL)
sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
if (s->s3->rrec.comp != NULL)
{
OPENSSL_free(s->s3->rrec.comp);
s->s3->rrec.comp=NULL;
}
#ifndef OPENSSL_NO_DH
if (s->s3->tmp.dh != NULL)
{
DH_free(s->s3->tmp.dh);
s->s3->tmp.dh = NULL;
}
#endif
#ifndef OPENSSL_NO_ECDH
if (s->s3->tmp.ecdh != NULL)
{
EC_KEY_free(s->s3->tmp.ecdh);
s->s3->tmp.ecdh = NULL;
}
#endif
#ifndef OPENSSL_NO_TLSEXT
#ifndef OPENSSL_NO_EC
s->s3->is_probably_safari = 0;
#endif /* !OPENSSL_NO_EC */
#endif /* !OPENSSL_NO_TLSEXT */
rp = s->s3->rbuf.buf;
wp = s->s3->wbuf.buf;
rlen = s->s3->rbuf.len;
wlen = s->s3->wbuf.len;
init_extra = s->s3->init_extra;
if (s->s3->handshake_buffer) {
BIO_free(s->s3->handshake_buffer);
s->s3->handshake_buffer = NULL;
}
if (s->s3->handshake_dgst) {
ssl3_free_digest_list(s);
}
memset(s->s3,0,sizeof *s->s3);
s->s3->rbuf.buf = rp;
s->s3->wbuf.buf = wp;
s->s3->rbuf.len = rlen;
s->s3->wbuf.len = wlen;
s->s3->init_extra = init_extra;
ssl_free_wbio_buffer(s);
s->packet_length=0;
s->s3->renegotiate=0;
s->s3->total_renegotiations=0;
s->s3->num_renegotiations=0;
s->s3->in_read_app_data=0;
s->version=SSL3_VERSION;
#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
if (s->next_proto_negotiated)
{
OPENSSL_free(s->next_proto_negotiated);
s->next_proto_negotiated = NULL;
s->next_proto_negotiated_len = 0;
}
#endif
}
|
CWE-310
| 79 | 10,874 |
107234555939230786328125689269171957202
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
{
int ret=0;
#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
if (
#ifndef OPENSSL_NO_RSA
cmd == SSL_CTRL_SET_TMP_RSA ||
cmd == SSL_CTRL_SET_TMP_RSA_CB ||
#endif
#ifndef OPENSSL_NO_DSA
cmd == SSL_CTRL_SET_TMP_DH ||
cmd == SSL_CTRL_SET_TMP_DH_CB ||
#endif
0)
{
if (!ssl_cert_inst(&s->cert))
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);
return(0);
}
}
#endif
switch (cmd)
{
case SSL_CTRL_GET_SESSION_REUSED:
ret=s->hit;
break;
case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
break;
case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
ret=s->s3->num_renegotiations;
break;
case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
ret=s->s3->num_renegotiations;
s->s3->num_renegotiations=0;
break;
case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
ret=s->s3->total_renegotiations;
break;
case SSL_CTRL_GET_FLAGS:
ret=(int)(s->s3->flags);
break;
#ifndef OPENSSL_NO_RSA
case SSL_CTRL_NEED_TMP_RSA:
if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) &&
((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
(EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))))
ret = 1;
break;
case SSL_CTRL_SET_TMP_RSA:
{
RSA *rsa = (RSA *)parg;
if (rsa == NULL)
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
return(ret);
}
if ((rsa = RSAPrivateKey_dup(rsa)) == NULL)
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
return(ret);
}
if (s->cert->rsa_tmp != NULL)
RSA_free(s->cert->rsa_tmp);
s->cert->rsa_tmp = rsa;
ret = 1;
}
break;
case SSL_CTRL_SET_TMP_RSA_CB:
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return(ret);
}
break;
#endif
#ifndef OPENSSL_NO_DH
case SSL_CTRL_SET_TMP_DH:
{
DH *dh = (DH *)parg;
if (dh == NULL)
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
return(ret);
}
if ((dh = DHparams_dup(dh)) == NULL)
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
return(ret);
}
if (!(s->options & SSL_OP_SINGLE_DH_USE))
{
if (!DH_generate_key(dh))
{
DH_free(dh);
SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
return(ret);
}
}
if (s->cert->dh_tmp != NULL)
DH_free(s->cert->dh_tmp);
s->cert->dh_tmp = dh;
ret = 1;
}
break;
case SSL_CTRL_SET_TMP_DH_CB:
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return(ret);
}
break;
#endif
#ifndef OPENSSL_NO_ECDH
case SSL_CTRL_SET_TMP_ECDH:
{
EC_KEY *ecdh = NULL;
if (parg == NULL)
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
return(ret);
}
if (!EC_KEY_up_ref((EC_KEY *)parg))
{
SSLerr(SSL_F_SSL3_CTRL,ERR_R_ECDH_LIB);
return(ret);
}
ecdh = (EC_KEY *)parg;
if (!(s->options & SSL_OP_SINGLE_ECDH_USE))
{
if (!EC_KEY_generate_key(ecdh))
{
EC_KEY_free(ecdh);
SSLerr(SSL_F_SSL3_CTRL,ERR_R_ECDH_LIB);
return(ret);
}
}
if (s->cert->ecdh_tmp != NULL)
EC_KEY_free(s->cert->ecdh_tmp);
s->cert->ecdh_tmp = ecdh;
ret = 1;
}
break;
case SSL_CTRL_SET_TMP_ECDH_CB:
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return(ret);
}
break;
#endif /* !OPENSSL_NO_ECDH */
#ifndef OPENSSL_NO_TLSEXT
case SSL_CTRL_SET_TLSEXT_HOSTNAME:
if (larg == TLSEXT_NAMETYPE_host_name)
{
if (s->tlsext_hostname != NULL)
OPENSSL_free(s->tlsext_hostname);
s->tlsext_hostname = NULL;
ret = 1;
if (parg == NULL)
break;
if (strlen((char *)parg) > TLSEXT_MAXLEN_host_name)
{
SSLerr(SSL_F_SSL3_CTRL, SSL_R_SSL3_EXT_INVALID_SERVERNAME);
return 0;
}
if ((s->tlsext_hostname = BUF_strdup((char *)parg)) == NULL)
{
SSLerr(SSL_F_SSL3_CTRL, ERR_R_INTERNAL_ERROR);
return 0;
}
}
else
{
SSLerr(SSL_F_SSL3_CTRL, SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE);
return 0;
}
break;
case SSL_CTRL_SET_TLSEXT_DEBUG_ARG:
s->tlsext_debug_arg=parg;
ret = 1;
break;
#ifdef TLSEXT_TYPE_opaque_prf_input
case SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT:
if (larg > 12288) /* actual internal limit is 2^16 for the complete hello message
* (including the cert chain and everything) */
{
SSLerr(SSL_F_SSL3_CTRL, SSL_R_OPAQUE_PRF_INPUT_TOO_LONG);
break;
}
if (s->tlsext_opaque_prf_input != NULL)
OPENSSL_free(s->tlsext_opaque_prf_input);
if ((size_t)larg == 0)
s->tlsext_opaque_prf_input = OPENSSL_malloc(1); /* dummy byte just to get non-NULL */
else
s->tlsext_opaque_prf_input = BUF_memdup(parg, (size_t)larg);
if (s->tlsext_opaque_prf_input != NULL)
{
s->tlsext_opaque_prf_input_len = (size_t)larg;
ret = 1;
}
else
s->tlsext_opaque_prf_input_len = 0;
break;
#endif
case SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE:
s->tlsext_status_type=larg;
ret = 1;
break;
case SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS:
*(STACK_OF(X509_EXTENSION) **)parg = s->tlsext_ocsp_exts;
ret = 1;
break;
case SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS:
s->tlsext_ocsp_exts = parg;
ret = 1;
break;
case SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS:
*(STACK_OF(OCSP_RESPID) **)parg = s->tlsext_ocsp_ids;
ret = 1;
break;
case SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS:
s->tlsext_ocsp_ids = parg;
ret = 1;
break;
case SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP:
*(unsigned char **)parg = s->tlsext_ocsp_resp;
return s->tlsext_ocsp_resplen;
case SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP:
if (s->tlsext_ocsp_resp)
OPENSSL_free(s->tlsext_ocsp_resp);
s->tlsext_ocsp_resp = parg;
s->tlsext_ocsp_resplen = larg;
ret = 1;
break;
#ifndef OPENSSL_NO_HEARTBEATS
case SSL_CTRL_TLS_EXT_SEND_HEARTBEAT:
if (SSL_version(s) == DTLS1_VERSION || SSL_version(s) == DTLS1_BAD_VER)
ret = dtls1_heartbeat(s);
else
ret = tls1_heartbeat(s);
break;
case SSL_CTRL_GET_TLS_EXT_HEARTBEAT_PENDING:
ret = s->tlsext_hb_pending;
break;
case SSL_CTRL_SET_TLS_EXT_HEARTBEAT_NO_REQUESTS:
if (larg)
s->tlsext_heartbeat |= SSL_TLSEXT_HB_DONT_RECV_REQUESTS;
else
s->tlsext_heartbeat &= ~SSL_TLSEXT_HB_DONT_RECV_REQUESTS;
ret = 1;
break;
#endif
#endif /* !OPENSSL_NO_TLSEXT */
default:
break;
}
return(ret);
}
|
CWE-310
| 80 | 10,875 |
16200999929990879835251368981878026716
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
{
CERT *cert;
cert=ctx->cert;
switch (cmd)
{
#ifndef OPENSSL_NO_RSA
case SSL_CTRL_SET_TMP_RSA_CB:
{
cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
}
break;
#endif
#ifndef OPENSSL_NO_DH
case SSL_CTRL_SET_TMP_DH_CB:
{
cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
}
break;
#endif
#ifndef OPENSSL_NO_ECDH
case SSL_CTRL_SET_TMP_ECDH_CB:
{
cert->ecdh_tmp_cb = (EC_KEY *(*)(SSL *, int, int))fp;
}
break;
#endif
#ifndef OPENSSL_NO_TLSEXT
case SSL_CTRL_SET_TLSEXT_SERVERNAME_CB:
ctx->tlsext_servername_callback=(int (*)(SSL *,int *,void *))fp;
break;
#ifdef TLSEXT_TYPE_opaque_prf_input
case SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB:
ctx->tlsext_opaque_prf_input_callback = (int (*)(SSL *,void *, size_t, void *))fp;
break;
#endif
case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB:
ctx->tlsext_status_cb=(int (*)(SSL *,void *))fp;
break;
case SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB:
ctx->tlsext_ticket_key_cb=(int (*)(SSL *,unsigned char *,
unsigned char *,
EVP_CIPHER_CTX *,
HMAC_CTX *, int))fp;
break;
#ifndef OPENSSL_NO_SRP
case SSL_CTRL_SET_SRP_VERIFY_PARAM_CB:
ctx->srp_ctx.srp_Mask|=SSL_kSRP;
ctx->srp_ctx.SRP_verify_param_callback=(int (*)(SSL *,void *))fp;
break;
case SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB:
ctx->srp_ctx.srp_Mask|=SSL_kSRP;
ctx->srp_ctx.TLS_ext_srp_username_callback=(int (*)(SSL *,int *,void *))fp;
break;
case SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB:
ctx->srp_ctx.srp_Mask|=SSL_kSRP;
ctx->srp_ctx.SRP_give_srp_client_pwd_callback=(char *(*)(SSL *,void *))fp;
break;
#endif
#endif
default:
return(0);
}
return(1);
}
|
CWE-310
| 81 | 10,876 |
62479080485106509365795814633929018045
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
{
CERT *cert;
cert=ctx->cert;
switch (cmd)
{
#ifndef OPENSSL_NO_RSA
case SSL_CTRL_NEED_TMP_RSA:
if ( (cert->rsa_tmp == NULL) &&
((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
(EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))
)
return(1);
else
return(0);
/* break; */
case SSL_CTRL_SET_TMP_RSA:
{
RSA *rsa;
int i;
rsa=(RSA *)parg;
i=1;
if (rsa == NULL)
i=0;
else
{
if ((rsa=RSAPrivateKey_dup(rsa)) == NULL)
i=0;
}
if (!i)
{
SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);
return(0);
}
else
{
if (cert->rsa_tmp != NULL)
RSA_free(cert->rsa_tmp);
cert->rsa_tmp=rsa;
return(1);
}
}
/* break; */
case SSL_CTRL_SET_TMP_RSA_CB:
{
SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return(0);
}
break;
#endif
#ifndef OPENSSL_NO_DH
case SSL_CTRL_SET_TMP_DH:
{
DH *new=NULL,*dh;
dh=(DH *)parg;
if ((new=DHparams_dup(dh)) == NULL)
{
SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
return 0;
}
if (!(ctx->options & SSL_OP_SINGLE_DH_USE))
{
if (!DH_generate_key(new))
{
SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
DH_free(new);
return 0;
}
}
if (cert->dh_tmp != NULL)
DH_free(cert->dh_tmp);
cert->dh_tmp=new;
return 1;
}
/*break; */
case SSL_CTRL_SET_TMP_DH_CB:
{
SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return(0);
}
break;
#endif
#ifndef OPENSSL_NO_ECDH
case SSL_CTRL_SET_TMP_ECDH:
{
EC_KEY *ecdh = NULL;
if (parg == NULL)
{
SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB);
return 0;
}
ecdh = EC_KEY_dup((EC_KEY *)parg);
if (ecdh == NULL)
{
SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_EC_LIB);
return 0;
}
if (!(ctx->options & SSL_OP_SINGLE_ECDH_USE))
{
if (!EC_KEY_generate_key(ecdh))
{
EC_KEY_free(ecdh);
SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB);
return 0;
}
}
if (cert->ecdh_tmp != NULL)
{
EC_KEY_free(cert->ecdh_tmp);
}
cert->ecdh_tmp = ecdh;
return 1;
}
/* break; */
case SSL_CTRL_SET_TMP_ECDH_CB:
{
SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return(0);
}
break;
#endif /* !OPENSSL_NO_ECDH */
#ifndef OPENSSL_NO_TLSEXT
case SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG:
ctx->tlsext_servername_arg=parg;
break;
case SSL_CTRL_SET_TLSEXT_TICKET_KEYS:
case SSL_CTRL_GET_TLSEXT_TICKET_KEYS:
{
unsigned char *keys = parg;
if (!keys)
return 48;
if (larg != 48)
{
SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_TICKET_KEYS_LENGTH);
return 0;
}
if (cmd == SSL_CTRL_SET_TLSEXT_TICKET_KEYS)
{
memcpy(ctx->tlsext_tick_key_name, keys, 16);
memcpy(ctx->tlsext_tick_hmac_key, keys + 16, 16);
memcpy(ctx->tlsext_tick_aes_key, keys + 32, 16);
}
else
{
memcpy(keys, ctx->tlsext_tick_key_name, 16);
memcpy(keys + 16, ctx->tlsext_tick_hmac_key, 16);
memcpy(keys + 32, ctx->tlsext_tick_aes_key, 16);
}
return 1;
}
#ifdef TLSEXT_TYPE_opaque_prf_input
case SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG:
ctx->tlsext_opaque_prf_input_callback_arg = parg;
return 1;
#endif
case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG:
ctx->tlsext_status_arg=parg;
return 1;
break;
#ifndef OPENSSL_NO_SRP
case SSL_CTRL_SET_TLS_EXT_SRP_USERNAME:
ctx->srp_ctx.srp_Mask|=SSL_kSRP;
if (ctx->srp_ctx.login != NULL)
OPENSSL_free(ctx->srp_ctx.login);
ctx->srp_ctx.login = NULL;
if (parg == NULL)
break;
if (strlen((const char *)parg) > 255 || strlen((const char *)parg) < 1)
{
SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_SRP_USERNAME);
return 0;
}
if ((ctx->srp_ctx.login = BUF_strdup((char *)parg)) == NULL)
{
SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_INTERNAL_ERROR);
return 0;
}
break;
case SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD:
ctx->srp_ctx.SRP_give_srp_client_pwd_callback=srp_password_from_info_cb;
ctx->srp_ctx.info=parg;
break;
case SSL_CTRL_SET_SRP_ARG:
ctx->srp_ctx.srp_Mask|=SSL_kSRP;
ctx->srp_ctx.SRP_cb_arg=parg;
break;
case SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH:
ctx->srp_ctx.strength=larg;
break;
#endif
#endif /* !OPENSSL_NO_TLSEXT */
/* A Thawte special :-) */
case SSL_CTRL_EXTRA_CHAIN_CERT:
if (ctx->extra_certs == NULL)
{
if ((ctx->extra_certs=sk_X509_new_null()) == NULL)
return(0);
}
sk_X509_push(ctx->extra_certs,(X509 *)parg);
break;
case SSL_CTRL_GET_EXTRA_CHAIN_CERTS:
*(STACK_OF(X509) **)parg = ctx->extra_certs;
break;
case SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS:
if (ctx->extra_certs)
{
sk_X509_pop_free(ctx->extra_certs, X509_free);
ctx->extra_certs = NULL;
}
break;
default:
return(0);
}
return(1);
}
|
CWE-310
| 82 | 10,877 |
194145129889191835416793754636702309565
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
long ssl3_default_timeout(void)
{
/* 2 hours, the 24 hours mentioned in the SSLv3 spec
* is way too long for http, the cache would over fill */
return(60*60*2);
}
|
CWE-310
| 83 | 10,878 |
129063646903961796578040813085437759613
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
const SSL_CIPHER *ssl3_get_cipher(unsigned int u)
{
if (u < SSL3_NUM_CIPHERS)
return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
else
return(NULL);
}
|
CWE-310
| 85 | 10,879 |
233184912941269420450438019488715600386
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
{
SSL_CIPHER c;
const SSL_CIPHER *cp;
unsigned long id;
id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
c.id=id;
cp = OBJ_bsearch_ssl_cipher_id(&c, ssl3_ciphers, SSL3_NUM_CIPHERS);
#ifdef DEBUG_PRINT_UNKNOWN_CIPHERSUITES
if (cp == NULL) fprintf(stderr, "Unknown cipher ID %x\n", (p[0] << 8) | p[1]);
#endif
if (cp == NULL || cp->valid == 0)
return NULL;
else
return cp;
}
|
CWE-310
| 86 | 10,880 |
85491662104860726054232609426639447890
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
{
int ret=0;
unsigned long alg_k;
alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
#ifndef OPENSSL_NO_GOST
if (s->version >= TLS1_VERSION)
{
if (alg_k & SSL_kGOST)
{
p[ret++]=TLS_CT_GOST94_SIGN;
p[ret++]=TLS_CT_GOST01_SIGN;
return(ret);
}
}
#endif
#ifndef OPENSSL_NO_DH
if (alg_k & (SSL_kDHr|SSL_kEDH))
{
# ifndef OPENSSL_NO_RSA
p[ret++]=SSL3_CT_RSA_FIXED_DH;
# endif
# ifndef OPENSSL_NO_DSA
p[ret++]=SSL3_CT_DSS_FIXED_DH;
# endif
}
if ((s->version == SSL3_VERSION) &&
(alg_k & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
{
# ifndef OPENSSL_NO_RSA
p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
# endif
# ifndef OPENSSL_NO_DSA
p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH;
# endif
}
#endif /* !OPENSSL_NO_DH */
#ifndef OPENSSL_NO_RSA
p[ret++]=SSL3_CT_RSA_SIGN;
#endif
#ifndef OPENSSL_NO_DSA
p[ret++]=SSL3_CT_DSS_SIGN;
#endif
#ifndef OPENSSL_NO_ECDH
if ((alg_k & (SSL_kECDHr|SSL_kECDHe)) && (s->version >= TLS1_VERSION))
{
p[ret++]=TLS_CT_RSA_FIXED_ECDH;
p[ret++]=TLS_CT_ECDSA_FIXED_ECDH;
}
#endif
#ifndef OPENSSL_NO_ECDSA
/* ECDSA certs can be used with RSA cipher suites as well
* so we don't need to check for SSL_kECDH or SSL_kEECDH
*/
if (s->version >= TLS1_VERSION)
{
p[ret++]=TLS_CT_ECDSA_SIGN;
}
#endif
return(ret);
}
|
CWE-310
| 87 | 10,881 |
198217309300273073075645598784339542558
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_num_ciphers(void)
{
return(SSL3_NUM_CIPHERS);
}
|
CWE-310
| 89 | 10,882 |
284648602599129384463728866613293345127
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_peek(SSL *s, void *buf, int len)
{
return ssl3_read_internal(s, buf, len, 1);
}
|
CWE-310
| 90 | 10,883 |
161283084861831027817505287772937422636
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_pending(const SSL *s)
{
if (s->rstate == SSL_ST_READ_BODY)
return 0;
return (s->s3->rrec.type == SSL3_RT_APPLICATION_DATA) ? s->s3->rrec.length : 0;
}
|
CWE-310
| 91 | 10,884 |
83010926611513157527423539917109466202
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
{
long l;
if (p != NULL)
{
l=c->id;
if ((l & 0xff000000) != 0x03000000) return(0);
p[0]=((unsigned char)(l>> 8L))&0xFF;
p[1]=((unsigned char)(l ))&0xFF;
}
return(2);
}
|
CWE-310
| 92 | 10,885 |
104695331918521476645082752622492398227
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_read(SSL *s, void *buf, int len)
{
return ssl3_read_internal(s, buf, len, 0);
}
|
CWE-310
| 93 | 10,886 |
254521170376596511382456525509950993369
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
{
int ret;
clear_sys_error();
if (s->s3->renegotiate) ssl3_renegotiate_check(s);
s->s3->in_read_app_data=1;
ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
if ((ret == -1) && (s->s3->in_read_app_data == 2))
{
/* ssl3_read_bytes decided to call s->handshake_func, which
* called ssl3_read_bytes to read handshake data.
* However, ssl3_read_bytes actually found application data
* and thinks that application data makes sense here; so disable
* handshake processing and try to read application data again. */
s->in_handshake++;
ret=s->method->ssl_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
s->in_handshake--;
}
else
s->s3->in_read_app_data=0;
return(ret);
}
|
CWE-310
| 94 | 10,887 |
259331538805733048214923463851177258621
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_renegotiate(SSL *s)
{
if (s->handshake_func == NULL)
return(1);
if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
return(0);
s->s3->renegotiate=1;
return(1);
}
|
CWE-310
| 95 | 10,888 |
126114022060016262750022615049352629869
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_shutdown(SSL *s)
{
int ret;
/* Don't do anything much if we have not done the handshake or
* we don't want to send messages :-) */
if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE))
{
s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
return(1);
}
if (!(s->shutdown & SSL_SENT_SHUTDOWN))
{
s->shutdown|=SSL_SENT_SHUTDOWN;
#if 1
ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY);
#endif
/* our shutdown alert has been sent now, and if it still needs
* to be written, s->s3->alert_dispatch will be true */
if (s->s3->alert_dispatch)
return(-1); /* return WANT_WRITE */
}
else if (s->s3->alert_dispatch)
{
/* resend it if not sent */
#if 1
ret=s->method->ssl_dispatch_alert(s);
if(ret == -1)
{
/* we only get to return -1 here the 2nd/Nth
* invocation, we must have already signalled
* return 0 upon a previous invoation,
* return WANT_WRITE */
return(ret);
}
#endif
}
else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
{
/* If we are waiting for a close from our peer, we are closed */
s->method->ssl_read_bytes(s,0,NULL,0,0);
if(!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
{
return(-1); /* return WANT_READ */
}
}
if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
!s->s3->alert_dispatch)
return(1);
else
return(0);
}
|
CWE-310
| 96 | 10,889 |
290380816740477832903351245298224138390
| null | null | null |
openssl
|
ca989269a2876bae79393bd54c3e72d49975fc75
| 0 |
int ssl3_write(SSL *s, const void *buf, int len)
{
int ret,n;
#if 0
if (s->shutdown & SSL_SEND_SHUTDOWN)
{
s->rwstate=SSL_NOTHING;
return(0);
}
#endif
clear_sys_error();
if (s->s3->renegotiate) ssl3_renegotiate_check(s);
/* This is an experimental flag that sends the
* last handshake message in the same packet as the first
* use data - used to see if it helps the TCP protocol during
* session-id reuse */
/* The second test is because the buffer may have been removed */
if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
{
/* First time through, we write into the buffer */
if (s->s3->delay_buf_pop_ret == 0)
{
ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
buf,len);
if (ret <= 0) return(ret);
s->s3->delay_buf_pop_ret=ret;
}
s->rwstate=SSL_WRITING;
n=BIO_flush(s->wbio);
if (n <= 0) return(n);
s->rwstate=SSL_NOTHING;
/* We have flushed the buffer, so remove it */
ssl_free_wbio_buffer(s);
s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
ret=s->s3->delay_buf_pop_ret;
s->s3->delay_buf_pop_ret=0;
}
else
{
ret=s->method->ssl_write_bytes(s,SSL3_RT_APPLICATION_DATA,
buf,len);
if (ret <= 0) return(ret);
}
return(ret);
}
|
CWE-310
| 97 | 10,890 |
214899927337244825558360465523114521544
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
freefileinfo (struct fileinfo *f)
{
while (f)
{
struct fileinfo *next = f->next;
xfree (f->name);
if (f->linkto)
xfree (f->linkto);
xfree (f);
f = next;
}
}
|
CWE-200
| 212 | 10,894 |
72979141031642508677041332358822156437
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_do_pasv (int csock, ip_address *addr, int *port)
{
uerr_t err;
/* We need to determine the address family and need to call
getpeername, so while we're at it, store the address to ADDR.
ftp_pasv and ftp_lpsv can simply override it. */
if (!socket_ip_address (csock, addr, ENDPOINT_PEER))
abort ();
/* If our control connection is over IPv6, then we first try EPSV and then
* LPSV if the former is not supported. If the control connection is over
* IPv4, we simply issue the good old PASV request. */
switch (addr->family)
{
case AF_INET:
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> PASV ... ");
err = ftp_pasv (csock, addr, port);
break;
case AF_INET6:
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> EPSV ... ");
err = ftp_epsv (csock, addr, port);
/* If EPSV is not supported try LPSV */
if (err == FTPNOPASV)
{
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> LPSV ... ");
err = ftp_lpsv (csock, addr, port);
}
break;
default:
abort ();
}
return err;
}
|
CWE-200
| 213 | 10,895 |
37760122740094001773051463420397987514
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_do_pasv (int csock, ip_address *addr, int *port)
{
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> PASV ... ");
return ftp_pasv (csock, addr, port);
}
|
CWE-200
| 214 | 10,896 |
139837436046034822971599839388749893386
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_do_port (int csock, int *local_sock)
{
uerr_t err;
ip_address cip;
if (!socket_ip_address (csock, &cip, ENDPOINT_PEER))
abort ();
/* If our control connection is over IPv6, then we first try EPRT and then
* LPRT if the former is not supported. If the control connection is over
* IPv4, we simply issue the good old PORT request. */
switch (cip.family)
{
case AF_INET:
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> PORT ... ");
err = ftp_port (csock, local_sock);
break;
case AF_INET6:
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> EPRT ... ");
err = ftp_eprt (csock, local_sock);
/* If EPRT is not supported try LPRT */
if (err == FTPPORTERR)
{
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> LPRT ... ");
err = ftp_lprt (csock, local_sock);
}
break;
default:
abort ();
}
return err;
}
|
CWE-200
| 215 | 10,897 |
122148607059221265848457701977378742462
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_do_port (int csock, int *local_sock)
{
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> PORT ... ");
return ftp_port (csock, local_sock);
}
|
CWE-200
| 216 | 10,898 |
35245619663142155016611174708201194612
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_get_listing (struct url *u, ccon *con, struct fileinfo **f)
{
uerr_t err;
char *uf; /* url file name */
char *lf; /* list file name */
char *old_target = con->target;
con->st &= ~ON_YOUR_OWN;
con->cmd |= (DO_LIST | LEAVE_PENDING);
con->cmd &= ~DO_RETR;
/* Find the listing file name. We do it by taking the file name of
the URL and replacing the last component with the listing file
name. */
uf = url_file_name (u, NULL);
lf = file_merge (uf, LIST_FILENAME);
xfree (uf);
DEBUGP ((_("Using %s as listing tmp file.\n"), quote (lf)));
con->target = xstrdup (lf);
xfree (lf);
err = ftp_loop_internal (u, NULL, con, NULL, false);
lf = xstrdup (con->target);
xfree (con->target);
con->target = old_target;
if (err == RETROK)
{
*f = ftp_parse_ls (lf, con->rs);
if (opt.remove_listing)
{
if (unlink (lf))
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
else
logprintf (LOG_VERBOSE, _("Removed %s.\n"), quote (lf));
}
}
else
*f = NULL;
xfree (lf);
con->cmd &= ~DO_LIST;
return err;
}
|
CWE-200
| 218 | 10,899 |
126315655955091892151900721425506482746
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_loop (struct url *u, char **local_file, int *dt, struct url *proxy,
bool recursive, bool glob)
{
ccon con; /* FTP connection */
uerr_t res;
*dt = 0;
xzero (con);
con.csock = -1;
con.st = ON_YOUR_OWN;
con.rs = ST_UNIX;
con.id = NULL;
con.proxy = proxy;
/* If the file name is empty, the user probably wants a directory
index. We'll provide one, properly HTML-ized. Unless
opt.htmlify is 0, of course. :-) */
if (!*u->file && !recursive)
{
struct fileinfo *f;
res = ftp_get_listing (u, &con, &f);
if (res == RETROK)
{
if (opt.htmlify && !opt.spider)
{
char *filename = (opt.output_document
? xstrdup (opt.output_document)
: (con.target ? xstrdup (con.target)
: url_file_name (u, NULL)));
res = ftp_index (filename, u, f);
if (res == FTPOK && opt.verbose)
{
if (!opt.output_document)
{
struct_stat st;
wgint sz;
if (stat (filename, &st) == 0)
sz = st.st_size;
else
sz = -1;
logprintf (LOG_NOTQUIET,
_("Wrote HTML-ized index to %s [%s].\n"),
quote (filename), number_to_static_string (sz));
}
else
logprintf (LOG_NOTQUIET,
_("Wrote HTML-ized index to %s.\n"),
quote (filename));
}
xfree (filename);
}
freefileinfo (f);
}
}
else
{
bool ispattern = false;
if (glob)
{
/* Treat the URL as a pattern if the file name part of the
URL path contains wildcards. (Don't check for u->file
because it is unescaped and therefore doesn't leave users
the option to escape literal '*' as %2A.) */
char *file_part = strrchr (u->path, '/');
if (!file_part)
file_part = u->path;
ispattern = has_wildcards_p (file_part);
}
if (ispattern || recursive || opt.timestamping || opt.preserve_perm)
{
/* ftp_retrieve_glob is a catch-all function that gets called
if we need globbing, time-stamping, recursion or preserve
permissions. Its third argument is just what we really need. */
res = ftp_retrieve_glob (u, &con,
ispattern ? GLOB_GLOBALL : GLOB_GETONE);
}
else
res = ftp_loop_internal (u, NULL, &con, local_file, false);
}
if (res == FTPOK)
res = RETROK;
if (res == RETROK)
*dt |= RETROKF;
/* If a connection was left, quench it. */
if (con.csock != -1)
fd_close (con.csock);
xfree (con.id);
xfree (con.target);
return res;
}
|
CWE-200
| 219 | 10,900 |
124529080091379944649221351362898120183
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con, char **local_file,
bool force_full_retrieve)
{
int count, orig_lp;
wgint restval, len = 0, qtyread = 0;
char *tms, *locf;
const char *tmrate = NULL;
uerr_t err;
struct_stat st;
/* Declare WARC variables. */
bool warc_enabled = (opt.warc_filename != NULL);
FILE *warc_tmp = NULL;
ip_address *warc_ip = NULL;
wgint last_expected_bytes = 0;
/* Get the target, and set the name for the message accordingly. */
if ((f == NULL) && (con->target))
{
/* Explicit file (like ".listing"). */
locf = con->target;
}
else
{
/* URL-derived file. Consider "-O file" name. */
xfree (con->target);
con->target = url_file_name (u, NULL);
if (!opt.output_document)
locf = con->target;
else
locf = opt.output_document;
}
/* If the output_document was given, then this check was already done and
the file didn't exist. Hence the !opt.output_document */
/* If we receive .listing file it is necessary to determine system type of the ftp
server even if opn.noclobber is given. Thus we must ignore opt.noclobber in
order to establish connection with the server and get system type. */
if (opt.noclobber && !opt.output_document && file_exists_p (con->target)
&& !((con->cmd & DO_LIST) && !(con->cmd & DO_RETR)))
{
logprintf (LOG_VERBOSE,
_("File %s already there; not retrieving.\n"), quote (con->target));
/* If the file is there, we suppose it's retrieved OK. */
return RETROK;
}
/* Remove it if it's a link. */
remove_link (con->target);
count = 0;
if (con->st & ON_YOUR_OWN)
con->st = ON_YOUR_OWN;
orig_lp = con->cmd & LEAVE_PENDING ? 1 : 0;
/* THE loop. */
do
{
/* Increment the pass counter. */
++count;
sleep_between_retrievals (count);
if (con->st & ON_YOUR_OWN)
{
con->cmd = 0;
con->cmd |= (DO_RETR | LEAVE_PENDING);
if (con->csock != -1)
con->cmd &= ~ (DO_LOGIN | DO_CWD);
else
con->cmd |= (DO_LOGIN | DO_CWD);
}
else /* not on your own */
{
if (con->csock != -1)
con->cmd &= ~DO_LOGIN;
else
con->cmd |= DO_LOGIN;
if (con->st & DONE_CWD)
con->cmd &= ~DO_CWD;
else
con->cmd |= DO_CWD;
}
/* For file RETR requests, we can write a WARC record.
We record the file contents to a temporary file. */
if (warc_enabled && (con->cmd & DO_RETR) && warc_tmp == NULL)
{
warc_tmp = warc_tempfile ();
if (warc_tmp == NULL)
return WARC_TMP_FOPENERR;
if (!con->proxy && con->csock != -1)
{
warc_ip = (ip_address *) alloca (sizeof (ip_address));
socket_ip_address (con->csock, warc_ip, ENDPOINT_PEER);
}
}
/* Decide whether or not to restart. */
if (con->cmd & DO_LIST)
restval = 0;
else if (force_full_retrieve)
restval = 0;
else if (opt.start_pos >= 0)
restval = opt.start_pos;
else if (opt.always_rest
&& stat (locf, &st) == 0
&& S_ISREG (st.st_mode))
/* When -c is used, continue from on-disk size. (Can't use
hstat.len even if count>1 because we don't want a failed
first attempt to clobber existing data.) */
restval = st.st_size;
else if (count > 1)
restval = qtyread; /* start where the previous run left off */
else
restval = 0;
/* Get the current time string. */
tms = datetime_str (time (NULL));
/* Print fetch message, if opt.verbose. */
if (opt.verbose)
{
char *hurl = url_string (u, URL_AUTH_HIDE_PASSWD);
char tmp[256];
strcpy (tmp, " ");
if (count > 1)
sprintf (tmp, _("(try:%2d)"), count);
logprintf (LOG_VERBOSE, "--%s-- %s\n %s => %s\n",
tms, hurl, tmp, quote (locf));
#ifdef WINDOWS
ws_changetitle (hurl);
#endif
xfree (hurl);
}
/* Send getftp the proper length, if fileinfo was provided. */
if (f && f->type != FT_SYMLINK)
len = f->size;
else
len = 0;
/* If we are working on a WARC record, getftp should also write
to the warc_tmp file. */
err = getftp (u, len, &qtyread, restval, con, count, &last_expected_bytes,
warc_tmp);
if (con->csock == -1)
con->st &= ~DONE_CWD;
else
con->st |= DONE_CWD;
switch (err)
{
case HOSTERR: case CONIMPOSSIBLE: case FWRITEERR: case FOPENERR:
case FTPNSFOD: case FTPLOGINC: case FTPNOPASV: case CONTNOTSUPPORTED:
case UNLINKERR: case WARC_TMP_FWRITEERR:
/* Fatal errors, give up. */
if (warc_tmp != NULL)
fclose (warc_tmp);
return err;
case CONSOCKERR: case CONERROR: case FTPSRVERR: case FTPRERR:
case WRITEFAILED: case FTPUNKNOWNTYPE: case FTPSYSERR:
case FTPPORTERR: case FTPLOGREFUSED: case FTPINVPASV:
case FOPEN_EXCL_ERR:
printwhat (count, opt.ntry);
/* non-fatal errors */
if (err == FOPEN_EXCL_ERR)
{
/* Re-determine the file name. */
xfree (con->target);
con->target = url_file_name (u, NULL);
locf = con->target;
}
continue;
case FTPRETRINT:
/* If the control connection was closed, the retrieval
will be considered OK if f->size == len. */
if (!f || qtyread != f->size)
{
printwhat (count, opt.ntry);
continue;
}
break;
case RETRFINISHED:
/* Great! */
break;
default:
/* Not as great. */
abort ();
}
tms = datetime_str (time (NULL));
if (!opt.spider)
tmrate = retr_rate (qtyread - restval, con->dltime);
/* If we get out of the switch above without continue'ing, we've
successfully downloaded a file. Remember this fact. */
downloaded_file (FILE_DOWNLOADED_NORMALLY, locf);
if (con->st & ON_YOUR_OWN)
{
fd_close (con->csock);
con->csock = -1;
}
if (!opt.spider)
{
bool write_to_stdout = (opt.output_document && HYPHENP (opt.output_document));
logprintf (LOG_VERBOSE,
write_to_stdout
? _("%s (%s) - written to stdout %s[%s]\n\n")
: _("%s (%s) - %s saved [%s]\n\n"),
tms, tmrate,
write_to_stdout ? "" : quote (locf),
number_to_static_string (qtyread));
}
if (!opt.verbose && !opt.quiet)
{
/* Need to hide the password from the URL. The `if' is here
so that we don't do the needless allocation every
time. */
char *hurl = url_string (u, URL_AUTH_HIDE_PASSWD);
logprintf (LOG_NONVERBOSE, "%s URL: %s [%s] -> \"%s\" [%d]\n",
tms, hurl, number_to_static_string (qtyread), locf, count);
xfree (hurl);
}
if (warc_enabled && (con->cmd & DO_RETR))
{
/* Create and store a WARC resource record for the retrieved file. */
bool warc_res;
warc_res = warc_write_resource_record (NULL, u->url, NULL, NULL,
warc_ip, NULL, warc_tmp, -1);
if (! warc_res)
return WARC_ERR;
/* warc_write_resource_record has also closed warc_tmp. */
warc_tmp = NULL;
}
if (con->cmd & DO_LIST)
/* This is a directory listing file. */
{
if (!opt.remove_listing)
/* --dont-remove-listing was specified, so do count this towards the
number of bytes and files downloaded. */
{
total_downloaded_bytes += qtyread;
numurls++;
}
/* Deletion of listing files is not controlled by --delete-after, but
by the more specific option --dont-remove-listing, and the code
to do this deletion is in another function. */
}
else if (!opt.spider)
/* This is not a directory listing file. */
{
/* Unlike directory listing files, don't pretend normal files weren't
downloaded if they're going to be deleted. People seeding proxies,
for instance, may want to know how many bytes and files they've
downloaded through it. */
total_downloaded_bytes += qtyread;
numurls++;
if (opt.delete_after && !input_file_url (opt.input_filename))
{
DEBUGP (("\
Removing file due to --delete-after in ftp_loop_internal():\n"));
logprintf (LOG_VERBOSE, _("Removing %s.\n"), locf);
if (unlink (locf))
logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno));
}
}
/* Restore the original leave-pendingness. */
if (orig_lp)
con->cmd |= LEAVE_PENDING;
else
con->cmd &= ~LEAVE_PENDING;
if (local_file)
*local_file = xstrdup (locf);
if (warc_tmp != NULL)
fclose (warc_tmp);
return RETROK;
} while (!opt.ntry || (count < opt.ntry));
if (con->csock != -1 && (con->st & ON_YOUR_OWN))
{
fd_close (con->csock);
con->csock = -1;
}
if (warc_tmp != NULL)
fclose (warc_tmp);
return TRYLIMEXC;
}
|
CWE-200
| 220 | 10,901 |
236599843773130370606355162563786776317
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_retrieve_dirs (struct url *u, struct fileinfo *f, ccon *con)
{
char *container = NULL;
int container_size = 0;
for (; f; f = f->next)
{
int size;
char *odir, *newdir;
if (opt.quota && total_downloaded_bytes > opt.quota)
break;
if (f->type != FT_DIRECTORY)
continue;
/* Allocate u->dir off stack, but reallocate only if a larger
string is needed. It's a pity there's no "realloca" for an
item on the bottom of the stack. */
size = strlen (u->dir) + 1 + strlen (f->name) + 1;
if (size > container_size)
container = (char *)alloca (size);
newdir = container;
odir = u->dir;
if (*odir == '\0'
|| (*odir == '/' && *(odir + 1) == '\0'))
/* If ODIR is empty or just "/", simply append f->name to
ODIR. (In the former case, to preserve u->dir being
relative; in the latter case, to avoid double slash.) */
sprintf (newdir, "%s%s", odir, f->name);
else
/* Else, use a separator. */
sprintf (newdir, "%s/%s", odir, f->name);
DEBUGP (("Composing new CWD relative to the initial directory.\n"));
DEBUGP ((" odir = '%s'\n f->name = '%s'\n newdir = '%s'\n\n",
odir, f->name, newdir));
if (!accdir (newdir))
{
logprintf (LOG_VERBOSE, _("\
Not descending to %s as it is excluded/not-included.\n"),
quote (newdir));
continue;
}
con->st &= ~DONE_CWD;
odir = xstrdup (u->dir); /* because url_set_dir will free
u->dir. */
url_set_dir (u, newdir);
ftp_retrieve_glob (u, con, GLOB_GETALL);
url_set_dir (u, odir);
xfree (odir);
/* Set the time-stamp? */
}
if (opt.quota && total_downloaded_bytes > opt.quota)
return QUOTEXC;
else
return RETROK;
}
|
CWE-200
| 221 | 10,902 |
319183586292658207562535314233017908702
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_retrieve_glob (struct url *u, ccon *con, int action)
{
struct fileinfo *f, *start;
uerr_t res;
con->cmd |= LEAVE_PENDING;
res = ftp_get_listing (u, con, &start);
if (res != RETROK)
return res;
/* First: weed out that do not conform the global rules given in
opt.accepts and opt.rejects. */
if (opt.accepts || opt.rejects)
{
f = start;
while (f)
{
if (f->type != FT_DIRECTORY && !acceptable (f->name))
{
logprintf (LOG_VERBOSE, _("Rejecting %s.\n"),
quote (f->name));
f = delelement (f, &start);
}
else
f = f->next;
}
}
/* Remove all files with possible harmful names or invalid entries. */
f = start;
while (f)
{
if (has_insecure_name_p (f->name) || is_invalid_entry (f))
{
logprintf (LOG_VERBOSE, _("Rejecting %s.\n"),
quote (f->name));
f = delelement (f, &start);
}
else
f = f->next;
}
/* Now weed out the files that do not match our globbing pattern.
If we are dealing with a globbing pattern, that is. */
if (*u->file)
{
if (action == GLOB_GLOBALL)
{
int (*matcher) (const char *, const char *, int)
= opt.ignore_case ? fnmatch_nocase : fnmatch;
int matchres = 0;
f = start;
while (f)
{
matchres = matcher (u->file, f->name, 0);
if (matchres == -1)
{
logprintf (LOG_NOTQUIET, _("Error matching %s against %s: %s\n"),
u->file, quotearg_style (escape_quoting_style, f->name),
strerror (errno));
break;
}
if (matchres == FNM_NOMATCH)
f = delelement (f, &start); /* delete the element from the list */
else
f = f->next; /* leave the element in the list */
}
if (matchres == -1)
{
freefileinfo (start);
return RETRBADPATTERN;
}
}
else if (action == GLOB_GETONE)
{
#ifdef __VMS
/* 2009-09-09 SMS.
* Odd-ball compiler ("HP C V7.3-009 on OpenVMS Alpha V7.3-2")
* bug causes spurious %CC-E-BADCONDIT complaint with this
* "?:" statement. (Different linkage attributes for strcmp()
* and strcasecmp().) Converting to "if" changes the
* complaint to %CC-W-PTRMISMATCH on "cmp = strcmp;". Adding
* the senseless type cast clears the complaint, and looks
* harmless.
*/
int (*cmp) (const char *, const char *)
= opt.ignore_case ? strcasecmp : (int (*)())strcmp;
#else /* def __VMS */
int (*cmp) (const char *, const char *)
= opt.ignore_case ? strcasecmp : strcmp;
#endif /* def __VMS [else] */
f = start;
while (f)
{
if (0 != cmp(u->file, f->name))
f = delelement (f, &start);
else
f = f->next;
}
}
}
if (start)
{
/* Just get everything. */
res = ftp_retrieve_list (u, start, con);
}
else
{
if (action == GLOB_GLOBALL)
{
/* No luck. */
/* #### This message SUCKS. We should see what was the
reason that nothing was retrieved. */
logprintf (LOG_VERBOSE, _("No matches on pattern %s.\n"),
quote (u->file));
}
else if (action == GLOB_GETONE) /* GLOB_GETONE or GLOB_GETALL */
{
/* Let's try retrieving it anyway. */
con->st |= ON_YOUR_OWN;
res = ftp_loop_internal (u, NULL, con, NULL, false);
return res;
}
/* If action == GLOB_GETALL, and the file list is empty, there's
no point in trying to download anything or in complaining about
it. (An empty directory should not cause complaints.)
*/
}
freefileinfo (start);
if (opt.quota && total_downloaded_bytes > opt.quota)
return QUOTEXC;
else
return res;
}
|
CWE-200
| 222 | 10,903 |
45365460528071725775586956410303036924
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
ftp_retrieve_list (struct url *u, struct fileinfo *f, ccon *con)
{
static int depth = 0;
uerr_t err;
struct fileinfo *orig;
wgint local_size;
time_t tml;
bool dlthis; /* Download this (file). */
const char *actual_target = NULL;
bool force_full_retrieve = false;
/* Increase the depth. */
++depth;
if (opt.reclevel != INFINITE_RECURSION && depth > opt.reclevel)
{
DEBUGP ((_("Recursion depth %d exceeded max. depth %d.\n"),
depth, opt.reclevel));
--depth;
return RECLEVELEXC;
}
assert (f != NULL);
orig = f;
con->st &= ~ON_YOUR_OWN;
if (!(con->st & DONE_CWD))
con->cmd |= DO_CWD;
else
con->cmd &= ~DO_CWD;
con->cmd |= (DO_RETR | LEAVE_PENDING);
if (con->csock < 0)
con->cmd |= DO_LOGIN;
else
con->cmd &= ~DO_LOGIN;
err = RETROK; /* in case it's not used */
while (f)
{
char *old_target, *ofile;
if (opt.quota && total_downloaded_bytes > opt.quota)
{
--depth;
return QUOTEXC;
}
old_target = con->target;
ofile = xstrdup (u->file);
url_set_file (u, f->name);
con->target = url_file_name (u, NULL);
err = RETROK;
dlthis = true;
if (opt.timestamping && f->type == FT_PLAINFILE)
{
struct_stat st;
/* If conversion of HTML files retrieved via FTP is ever implemented,
we'll need to stat() <file>.orig here when -K has been specified.
I'm not implementing it now since files on an FTP server are much
more likely than files on an HTTP server to legitimately have a
.orig suffix. */
if (!stat (con->target, &st))
{
bool eq_size;
bool cor_val;
/* Else, get it from the file. */
local_size = st.st_size;
tml = st.st_mtime;
#ifdef WINDOWS
/* Modification time granularity is 2 seconds for Windows, so
increase local time by 1 second for later comparison. */
tml++;
#endif
/* Compare file sizes only for servers that tell us correct
values. Assume sizes being equal for servers that lie
about file size. */
cor_val = (con->rs == ST_UNIX || con->rs == ST_WINNT);
eq_size = cor_val ? (local_size == f->size) : true;
if (f->tstamp <= tml && eq_size)
{
/* Remote file is older, file sizes can be compared and
are both equal. */
logprintf (LOG_VERBOSE, _("\
Remote file no newer than local file %s -- not retrieving.\n"), quote (con->target));
dlthis = false;
}
else if (f->tstamp > tml)
{
/* Remote file is newer */
force_full_retrieve = true;
logprintf (LOG_VERBOSE, _("\
Remote file is newer than local file %s -- retrieving.\n\n"),
quote (con->target));
}
else
{
/* Sizes do not match */
logprintf (LOG_VERBOSE, _("\
The sizes do not match (local %s) -- retrieving.\n\n"),
number_to_static_string (local_size));
}
}
} /* opt.timestamping && f->type == FT_PLAINFILE */
switch (f->type)
{
case FT_SYMLINK:
/* If opt.retr_symlinks is defined, we treat symlinks as
if they were normal files. There is currently no way
to distinguish whether they might be directories, and
follow them. */
if (!opt.retr_symlinks)
{
#ifdef HAVE_SYMLINK
if (!f->linkto)
logputs (LOG_NOTQUIET,
_("Invalid name of the symlink, skipping.\n"));
else
{
struct_stat st;
/* Check whether we already have the correct
symbolic link. */
int rc = lstat (con->target, &st);
if (rc == 0)
{
size_t len = strlen (f->linkto) + 1;
if (S_ISLNK (st.st_mode))
{
char *link_target = (char *)alloca (len);
size_t n = readlink (con->target, link_target, len);
if ((n == len - 1)
&& (memcmp (link_target, f->linkto, n) == 0))
{
logprintf (LOG_VERBOSE, _("\
Already have correct symlink %s -> %s\n\n"),
quote (con->target),
quote (f->linkto));
dlthis = false;
break;
}
}
}
logprintf (LOG_VERBOSE, _("Creating symlink %s -> %s\n"),
quote (con->target), quote (f->linkto));
/* Unlink before creating symlink! */
unlink (con->target);
if (symlink (f->linkto, con->target) == -1)
logprintf (LOG_NOTQUIET, "symlink: %s\n", strerror (errno));
logputs (LOG_VERBOSE, "\n");
} /* have f->linkto */
#else /* not HAVE_SYMLINK */
logprintf (LOG_NOTQUIET,
_("Symlinks not supported, skipping symlink %s.\n"),
quote (con->target));
#endif /* not HAVE_SYMLINK */
}
else /* opt.retr_symlinks */
{
if (dlthis)
err = ftp_loop_internal (u, f, con, NULL, force_full_retrieve);
} /* opt.retr_symlinks */
break;
case FT_DIRECTORY:
if (!opt.recursive)
logprintf (LOG_NOTQUIET, _("Skipping directory %s.\n"),
quote (f->name));
break;
case FT_PLAINFILE:
/* Call the retrieve loop. */
if (dlthis)
err = ftp_loop_internal (u, f, con, NULL, force_full_retrieve);
break;
case FT_UNKNOWN:
logprintf (LOG_NOTQUIET, _("%s: unknown/unsupported file type.\n"),
quote (f->name));
break;
} /* switch */
/* 2004-12-15 SMS.
* Set permissions _before_ setting the times, as setting the
* permissions changes the modified-time, at least on VMS.
* Also, use the opt.output_document name here, too, as
* appropriate. (Do the test once, and save the result.)
*/
set_local_file (&actual_target, con->target);
/* If downloading a plain file, and the user requested it, then
set valid (non-zero) permissions. */
if (dlthis && (actual_target != NULL) &&
(f->type == FT_PLAINFILE) && opt.preserve_perm)
{
if (f->perms)
chmod (actual_target, f->perms);
else
DEBUGP (("Unrecognized permissions for %s.\n", actual_target));
}
/* Set the time-stamp information to the local file. Symlinks
are not to be stamped because it sets the stamp on the
original. :( */
if (actual_target != NULL)
{
if (opt.useservertimestamps
&& !(f->type == FT_SYMLINK && !opt.retr_symlinks)
&& f->tstamp != -1
&& dlthis
&& file_exists_p (con->target))
{
touch (actual_target, f->tstamp);
}
else if (f->tstamp == -1)
logprintf (LOG_NOTQUIET, _("%s: corrupt time-stamp.\n"),
actual_target);
}
xfree (con->target);
con->target = old_target;
url_set_file (u, ofile);
xfree (ofile);
/* Break on fatals. */
if (err == QUOTEXC || err == HOSTERR || err == FWRITEERR
|| err == WARC_ERR || err == WARC_TMP_FOPENERR
|| err == WARC_TMP_FWRITEERR)
break;
con->cmd &= ~ (DO_CWD | DO_LOGIN);
f = f->next;
}
/* We do not want to call ftp_retrieve_dirs here */
if (opt.recursive &&
!(opt.reclevel != INFINITE_RECURSION && depth >= opt.reclevel))
err = ftp_retrieve_dirs (u, orig, con);
else if (opt.recursive)
DEBUGP ((_("Will not retrieve dirs since depth is %d (max %d).\n"),
depth, opt.reclevel));
--depth;
return err;
}
|
CWE-200
| 223 | 10,904 |
31859296699574411030814235941847384582
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
has_insecure_name_p (const char *s)
{
if (*s == '/')
return true;
if (strstr (s, "../") != 0)
return true;
return false;
}
|
CWE-200
| 224 | 10,905 |
219673299327885487060708391321943587923
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
is_invalid_entry (struct fileinfo *f)
{
struct fileinfo *cur = f;
char *f_name = f->name;
/* If the node we're currently checking has a duplicate later, we eliminate
* the current node and leave the next one intact. */
while (cur->next)
{
cur = cur->next;
if (strcmp(f_name, cur->name) == 0)
return true;
}
return false;
}
|
CWE-200
| 225 | 10,906 |
137291254496510405386230627860837742521
| null | null | null |
savannah
|
075d7556964f5a871a73c22ac4b69f5361295099
| 0 |
print_length (wgint size, wgint start, bool authoritative)
{
logprintf (LOG_VERBOSE, _("Length: %s"), number_to_static_string (size));
if (size >= 1024)
logprintf (LOG_VERBOSE, " (%s)", human_readable (size, 10, 1));
if (start > 0)
{
if (size - start >= 1024)
logprintf (LOG_VERBOSE, _(", %s (%s) remaining"),
number_to_static_string (size - start),
human_readable (size - start, 10, 1));
else
logprintf (LOG_VERBOSE, _(", %s remaining"),
number_to_static_string (size - start));
}
logputs (LOG_VERBOSE, !authoritative ? _(" (unauthoritative)\n") : "\n");
}
|
CWE-200
| 226 | 10,907 |
115651917033130684150591663382671686342
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
add_mrange(fz_context *ctx, pdf_cmap *cmap, unsigned int low, int *out, int len)
{
int out_pos;
if (cmap->dlen + len + 1 > cmap->dcap)
{
int new_cap = cmap->dcap ? cmap->dcap * 2 : 256;
cmap->dict = fz_resize_array(ctx, cmap->dict, new_cap, sizeof *cmap->dict);
cmap->dcap = new_cap;
}
out_pos = cmap->dlen;
cmap->dict[out_pos] = len;
memcpy(&cmap->dict[out_pos+1], out, sizeof(int)*len);
cmap->dlen += len + 1;
add_range(ctx, cmap, low, low, out_pos, 1, 1);
}
|
CWE-416
| 432 | 11,095 |
245120723377082039067724120969265591935
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
check_splay(cmap_splay *tree, unsigned int node, int depth)
{
if (node == EMPTY)
return;
assert(tree[node].parent == EMPTY);
walk_splay(tree, node, do_check, tree);
}
|
CWE-416
| 433 | 11,096 |
262420811719345368100497632144170644791
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
copy_node_types(cmap_splay *node, void *arg)
{
pdf_cmap *cmap = (pdf_cmap *)arg;
if (node->many)
{
assert(node->low == node->high);
cmap->mranges[cmap->mlen].low = node->low;
cmap->mranges[cmap->mlen].out = node->out;
cmap->mlen++;
}
else if (node->low <= 0xffff && node->high <= 0xFFFF && node->out <= 0xFFFF)
{
cmap->ranges[cmap->rlen].low = node->low;
cmap->ranges[cmap->rlen].high = node->high;
cmap->ranges[cmap->rlen].out = node->out;
cmap->rlen++;
}
else
{
cmap->xranges[cmap->xlen].low = node->low;
cmap->xranges[cmap->xlen].high = node->high;
cmap->xranges[cmap->xlen].out = node->out;
cmap->xlen++;
}
}
|
CWE-416
| 434 | 11,097 |
280744279127383314551567300607378518599
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
count_node_types(cmap_splay *node, void *arg)
{
int *counts = (int *)arg;
if (node->many)
counts[2]++;
else if (node->low <= 0xffff && node->high <= 0xFFFF && node->out <= 0xFFFF)
counts[0]++;
else
counts[1]++;
}
|
CWE-416
| 435 | 11,098 |
119504487091456039115315839138817378198
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
static unsigned int delete_node(pdf_cmap *cmap, unsigned int current)
{
cmap_splay *tree = cmap->tree;
unsigned int parent;
unsigned int replacement;
assert(current != EMPTY);
parent = tree[current].parent;
if (tree[current].right == EMPTY)
{
if (parent == EMPTY)
{
replacement = cmap->ttop = tree[current].left;
}
else if (tree[parent].left == current)
{
replacement = tree[parent].left = tree[current].left;
}
else
{
assert(tree[parent].right == current);
replacement = tree[parent].right = tree[current].left;
}
if (replacement != EMPTY)
tree[replacement].parent = parent;
else
replacement = parent;
}
else if (tree[current].left == EMPTY)
{
if (parent == EMPTY)
{
replacement = cmap->ttop = tree[current].right;
}
else if (tree[parent].left == current)
{
replacement = tree[parent].left = tree[current].right;
}
else
{
assert(tree[parent].right == current);
replacement = tree[parent].right = tree[current].right;
}
if (replacement != EMPTY)
tree[replacement].parent = parent;
else
replacement = parent;
}
else
{
/* Hard case, find the in-order predecessor of current */
int amputee = current;
replacement = tree[current].left;
while (tree[replacement].right != EMPTY) {
amputee = replacement;
replacement = tree[replacement].right;
}
/* Remove replacement from the tree */
if (amputee == current)
{
tree[amputee].left = tree[replacement].left;
if (tree[amputee].left != EMPTY)
tree[tree[amputee].left].parent = amputee;
}
else
{
tree[amputee].right = tree[replacement].left;
if (tree[amputee].right != EMPTY)
tree[tree[amputee].right].parent = amputee;
}
/* Insert replacement in place of current */
tree[replacement].parent = parent;
if (parent == EMPTY)
{
tree[replacement].parent = EMPTY;
cmap->ttop = replacement;
}
else if (tree[parent].left == current)
tree[parent].left = replacement;
else
{
assert(tree[parent].right == current);
tree[parent].right = replacement;
}
tree[replacement].left = tree[current].left;
if (tree[replacement].left != EMPTY)
tree[tree[replacement].left].parent = replacement;
tree[replacement].right = tree[current].right;
if (tree[replacement].right != EMPTY)
tree[tree[replacement].right].parent = replacement;
}
/* current is now unlinked. We need to remove it from our array. */
cmap->tlen--;
if (current != cmap->tlen)
{
if (replacement == cmap->tlen)
replacement = current;
tree[current] = tree[cmap->tlen];
parent = tree[current].parent;
if (parent == EMPTY)
cmap->ttop = current;
else if (tree[parent].left == cmap->tlen)
tree[parent].left = current;
else
{
assert(tree[parent].right == cmap->tlen);
tree[parent].right = current;
}
if (tree[current].left != EMPTY)
{
assert(tree[tree[current].left].parent == cmap->tlen);
tree[tree[current].left].parent = current;
}
if (tree[current].right != EMPTY)
{
assert(tree[tree[current].right].parent == cmap->tlen);
tree[tree[current].right].parent = current;
}
}
/* Return the node that we should continue searching from */
return replacement;
}
|
CWE-416
| 436 | 11,099 |
313425205842121002295100407509937709720
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
do_check(cmap_splay *node, void *arg)
{
cmap_splay *tree = arg;
unsigned int num = node - tree;
assert(!node->many || node->low == node->high);
assert(node->low <= node->high);
assert((node->left == EMPTY) || (tree[node->left].parent == num &&
tree[node->left].high < node->low));
assert(node->right == EMPTY || (tree[node->right].parent == num &&
node->high < tree[node->right].low));
}
|
CWE-416
| 437 | 11,100 |
309859418446105689527964527730976397935
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
dump_splay(cmap_splay *tree, unsigned int node, int depth, const char *pre)
{
int i;
if (node == EMPTY)
return;
for (i = 0; i < depth; i++)
fprintf(stderr, " ");
fprintf(stderr, "%s%d:", pre, node);
if (tree[node].parent == EMPTY)
fprintf(stderr, "^EMPTY");
else
fprintf(stderr, "^%d", tree[node].parent);
if (tree[node].left == EMPTY)
fprintf(stderr, "<EMPTY");
else
fprintf(stderr, "<%d", tree[node].left);
if (tree[node].right == EMPTY)
fprintf(stderr, ">EMPTY");
else
fprintf(stderr, ">%d", tree[node].right);
fprintf(stderr, "(%x,%x,%x,%d)\n", tree[node].low, tree[node].high, tree[node].out, tree[node].many);
assert(tree[node].parent == EMPTY || depth);
assert(tree[node].left == EMPTY || tree[tree[node].left].parent == node);
assert(tree[node].right == EMPTY || tree[tree[node].right].parent == node);
dump_splay(tree, tree[node].left, depth+1, "L");
dump_splay(tree, tree[node].right, depth+1, "R");
}
|
CWE-416
| 438 | 11,101 |
239325017151051497644758061762923896837
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
move_to_root(cmap_splay *tree, unsigned int x)
{
if (x == EMPTY)
return;
do
{
unsigned int z, zp;
unsigned int y = tree[x].parent;
if (y == EMPTY)
break;
z = tree[y].parent;
if (z == EMPTY)
{
/* Case 3 */
tree[x].parent = EMPTY;
tree[y].parent = x;
if (tree[y].left == x)
{
/* Case 3 */
tree[y].left = tree[x].right;
if (tree[y].left != EMPTY)
tree[tree[y].left].parent = y;
tree[x].right = y;
}
else
{
/* Case 3 - reflected */
assert(tree[y].right == x);
tree[y].right = tree[x].left;
if (tree[y].right != EMPTY)
tree[tree[y].right].parent = y;
tree[x].left = y;
}
break;
}
zp = tree[z].parent;
tree[x].parent = zp;
if (zp != EMPTY) {
if (tree[zp].left == z)
tree[zp].left = x;
else
{
assert(tree[zp].right == z);
tree[zp].right = x;
}
}
tree[y].parent = x;
if (tree[y].left == x)
{
tree[y].left = tree[x].right;
if (tree[y].left != EMPTY)
tree[tree[y].left].parent = y;
tree[x].right = y;
if (tree[z].left == y)
{
/* Case 1 */
tree[z].parent = y;
tree[z].left = tree[y].right;
if (tree[z].left != EMPTY)
tree[tree[z].left].parent = z;
tree[y].right = z;
}
else
{
/* Case 2 - reflected */
assert(tree[z].right == y);
tree[z].parent = x;
tree[z].right = tree[x].left;
if (tree[z].right != EMPTY)
tree[tree[z].right].parent = z;
tree[x].left = z;
}
}
else
{
assert(tree[y].right == x);
tree[y].right = tree[x].left;
if (tree[y].right != EMPTY)
tree[tree[y].right].parent = y;
tree[x].left = y;
if (tree[z].left == y)
{
/* Case 2 */
tree[z].parent = x;
tree[z].left = tree[x].right;
if (tree[z].left != EMPTY)
tree[tree[z].left].parent = z;
tree[x].right = z;
}
else
{
/* Case 1 - reflected */
assert(tree[z].right == y);
tree[z].parent = y;
tree[z].right = tree[y].left;
if (tree[z].right != EMPTY)
tree[tree[z].right].parent = z;
tree[y].left = z;
}
}
} while (1);
}
|
CWE-416
| 439 | 11,102 |
102683482583186003052768154687495591649
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_add_codespace(fz_context *ctx, pdf_cmap *cmap, unsigned int low, unsigned int high, int n)
{
if (cmap->codespace_len + 1 == nelem(cmap->codespace))
{
fz_warn(ctx, "assert: too many code space ranges");
return;
}
cmap->codespace[cmap->codespace_len].n = n;
cmap->codespace[cmap->codespace_len].low = low;
cmap->codespace[cmap->codespace_len].high = high;
cmap->codespace_len ++;
}
|
CWE-416
| 440 | 11,103 |
226413261127163335491073950786429428705
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_cmap_wmode(fz_context *ctx, pdf_cmap *cmap)
{
return cmap->wmode;
}
|
CWE-416
| 441 | 11,104 |
17045354751123714168617123858600950156
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_decode_cmap(pdf_cmap *cmap, unsigned char *buf, unsigned char *end, unsigned int *cpt)
{
unsigned int c;
int k, n;
int len = end - buf;
if (len > 4)
len = 4;
c = 0;
for (n = 0; n < len; n++)
{
c = (c << 8) | buf[n];
for (k = 0; k < cmap->codespace_len; k++)
{
if (cmap->codespace[k].n == n + 1)
{
if (c >= cmap->codespace[k].low && c <= cmap->codespace[k].high)
{
*cpt = c;
return n + 1;
}
}
}
}
*cpt = 0;
return 1;
}
|
CWE-416
| 442 | 11,105 |
294614808202277140484521625418883693643
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap)
{
fz_drop_storable(ctx, &cmap->storable);
}
|
CWE-416
| 443 | 11,106 |
106423036151926959215422343175673334589
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_drop_cmap_imp(fz_context *ctx, fz_storable *cmap_)
{
pdf_cmap *cmap = (pdf_cmap *)cmap_;
pdf_drop_cmap(ctx, cmap->usecmap);
fz_free(ctx, cmap->ranges);
fz_free(ctx, cmap->xranges);
fz_free(ctx, cmap->mranges);
fz_free(ctx, cmap->dict);
fz_free(ctx, cmap->tree);
fz_free(ctx, cmap);
}
|
CWE-416
| 444 | 11,107 |
5219694418050346164792057553720841238
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap)
{
return fz_keep_storable(ctx, &cmap->storable);
}
|
CWE-416
| 445 | 11,108 |
280184611007150271601856009686272180401
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_lookup_cmap(pdf_cmap *cmap, unsigned int cpt)
{
pdf_range *ranges = cmap->ranges;
pdf_xrange *xranges = cmap->xranges;
int l, r, m;
l = 0;
r = cmap->rlen - 1;
while (l <= r)
{
m = (l + r) >> 1;
if (cpt < ranges[m].low)
r = m - 1;
else if (cpt > ranges[m].high)
l = m + 1;
else
return cpt - ranges[m].low + ranges[m].out;
}
l = 0;
r = cmap->xlen - 1;
while (l <= r)
{
m = (l + r) >> 1;
if (cpt < xranges[m].low)
r = m - 1;
else if (cpt > xranges[m].high)
l = m + 1;
else
return cpt - xranges[m].low + xranges[m].out;
}
if (cmap->usecmap)
return pdf_lookup_cmap(cmap->usecmap, cpt);
return -1;
}
|
CWE-416
| 446 | 11,109 |
1103081474390576511515862783891827275
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_lookup_cmap_full(pdf_cmap *cmap, unsigned int cpt, int *out)
{
pdf_range *ranges = cmap->ranges;
pdf_xrange *xranges = cmap->xranges;
pdf_mrange *mranges = cmap->mranges;
unsigned int i;
int l, r, m;
l = 0;
r = cmap->rlen - 1;
while (l <= r)
{
m = (l + r) >> 1;
if (cpt < ranges[m].low)
r = m - 1;
else if (cpt > ranges[m].high)
l = m + 1;
else
{
out[0] = cpt - ranges[m].low + ranges[m].out;
return 1;
}
}
l = 0;
r = cmap->xlen - 1;
while (l <= r)
{
m = (l + r) >> 1;
if (cpt < xranges[m].low)
r = m - 1;
else if (cpt > xranges[m].high)
l = m + 1;
else
{
out[0] = cpt - xranges[m].low + xranges[m].out;
return 1;
}
}
l = 0;
r = cmap->mlen - 1;
while (l <= r)
{
m = (l + r) >> 1;
if (cpt < mranges[m].low)
r = m - 1;
else if (cpt > mranges[m].low)
l = m + 1;
else
{
int *ptr = &cmap->dict[cmap->mranges[m].out];
unsigned int len = (unsigned int)*ptr++;
for (i = 0; i < len; ++i)
out[i] = *ptr++;
return len;
}
}
if (cmap->usecmap)
return pdf_lookup_cmap_full(cmap->usecmap, cpt, out);
return 0;
}
|
CWE-416
| 447 | 11,110 |
145179250570449795141476936868687510083
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_map_one_to_many(fz_context *ctx, pdf_cmap *cmap, unsigned int low, int *values, int len)
{
if (len == 1)
{
add_range(ctx, cmap, low, low, values[0], 1, 0);
return;
}
/* Decode unicode surrogate pairs. */
/* Only the *-UCS2 CMaps use one-to-many mappings, so assuming unicode should be safe. */
if (len == 2 &&
values[0] >= 0xD800 && values[0] <= 0xDBFF &&
values[1] >= 0xDC00 && values[1] <= 0xDFFF)
{
int rune = ((values[0] - 0xD800) << 10) + (values[1] - 0xDC00) + 0x10000;
add_range(ctx, cmap, low, low, rune, 1, 0);
return;
}
if (len > PDF_MRANGE_CAP)
{
fz_warn(ctx, "ignoring one to many mapping in cmap %s", cmap->cmap_name);
return;
}
add_mrange(ctx, cmap, low, values, len);
}
|
CWE-416
| 448 | 11,111 |
151275068419370057629130131901431482884
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_map_range_to_range(fz_context *ctx, pdf_cmap *cmap, unsigned int low, unsigned int high, int out)
{
add_range(ctx, cmap, low, high, out, 1, 0);
}
|
CWE-416
| 449 | 11,112 |
180095435423895771387111226702954541590
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_new_cmap(fz_context *ctx)
{
pdf_cmap *cmap = fz_malloc_struct(ctx, pdf_cmap);
FZ_INIT_STORABLE(cmap, 1, pdf_drop_cmap_imp);
return cmap;
}
|
CWE-416
| 450 | 11,113 |
30786992688510971672312144055265612538
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap)
{
int i;
pdf_drop_cmap(ctx, cmap->usecmap);
cmap->usecmap = pdf_keep_cmap(ctx, usecmap);
if (cmap->codespace_len == 0)
{
cmap->codespace_len = usecmap->codespace_len;
for (i = 0; i < usecmap->codespace_len; i++)
cmap->codespace[i] = usecmap->codespace[i];
}
}
|
CWE-416
| 452 | 11,114 |
71641778282825090266388654892249409679
| null | null | null |
ghostscript
|
f597300439e62f5e921f0d7b1e880b5c1a1f1607
| 0 |
pdf_sort_cmap(fz_context *ctx, pdf_cmap *cmap)
{
int counts[3];
if (cmap->tree == NULL)
return;
counts[0] = 0;
counts[1] = 0;
counts[2] = 0;
walk_splay(cmap->tree, cmap->ttop, count_node_types, &counts);
cmap->ranges = fz_malloc_array(ctx, counts[0], sizeof(*cmap->ranges));
cmap->rcap = counts[0];
cmap->xranges = fz_malloc_array(ctx, counts[1], sizeof(*cmap->xranges));
cmap->xcap = counts[1];
cmap->mranges = fz_malloc_array(ctx, counts[2], sizeof(*cmap->mranges));
cmap->mcap = counts[2];
walk_splay(cmap->tree, cmap->ttop, copy_node_types, cmap);
fz_free(ctx, cmap->tree);
cmap->tree = NULL;
}
|
CWE-416
| 453 | 11,115 |
332720040698217901925660915895040217220
| null | null | null |
ghostscript
|
b2e7d38e845c7d4922d05e6e41f3a2dc1bc1b14a
| 0 |
begin_softmask(fz_context *ctx, pdf_run_processor *pr, softmask_save *save)
{
pdf_gstate *gstate = pr->gstate + pr->gtop;
pdf_xobject *softmask = gstate->softmask;
fz_rect mask_bbox;
fz_matrix tos_save[2], save_ctm;
fz_matrix mask_matrix;
fz_colorspace *mask_colorspace;
save->softmask = softmask;
if (softmask == NULL)
return gstate;
save->page_resources = gstate->softmask_resources;
save->ctm = gstate->softmask_ctm;
save_ctm = gstate->ctm;
pdf_xobject_bbox(ctx, softmask, &mask_bbox);
pdf_xobject_matrix(ctx, softmask, &mask_matrix);
pdf_tos_save(ctx, &pr->tos, tos_save);
if (gstate->luminosity)
mask_bbox = fz_infinite_rect;
else
{
fz_transform_rect(&mask_bbox, &mask_matrix);
fz_transform_rect(&mask_bbox, &gstate->softmask_ctm);
}
gstate->softmask = NULL;
gstate->softmask_resources = NULL;
gstate->ctm = gstate->softmask_ctm;
mask_colorspace = pdf_xobject_colorspace(ctx, softmask);
if (gstate->luminosity && !mask_colorspace)
mask_colorspace = fz_keep_colorspace(ctx, fz_device_gray(ctx));
fz_try(ctx)
{
fz_begin_mask(ctx, pr->dev, &mask_bbox, gstate->luminosity, mask_colorspace, gstate->softmask_bc, &gstate->fill.color_params);
pdf_run_xobject(ctx, pr, softmask, save->page_resources, &fz_identity, 1);
}
fz_always(ctx)
fz_drop_colorspace(ctx, mask_colorspace);
fz_catch(ctx)
{
fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
/* FIXME: Ignore error - nasty, but if we throw from
* here the clip stack would be messed up. */
/* TODO: pass cookie here to increase the cookie error count */
}
fz_end_mask(ctx, pr->dev);
pdf_tos_restore(ctx, &pr->tos, tos_save);
gstate = pr->gstate + pr->gtop;
gstate->ctm = save_ctm;
return gstate;
}
|
CWE-20
| 567 | 11,213 |
104260325680532728373517489399325290074
| null | null | null |
ghostscript
|
b2e7d38e845c7d4922d05e6e41f3a2dc1bc1b14a
| 0 |
fz_always(ctx)
{
fz_drop_path(ctx, path);
}
|
CWE-20
| 568 | 11,214 |
286612868306126853534978661542083660063
| null | null | null |
ghostscript
|
b2e7d38e845c7d4922d05e6e41f3a2dc1bc1b14a
| 0 |
fz_catch(ctx)
{
fz_rethrow(ctx);
}
|
CWE-20
| 569 | 11,215 |
79843115906685785845018483124859124280
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
check_data_region (struct tar_sparse_file *file, size_t i)
{
off_t size_left;
if (!lseek_or_error (file, file->stat_info->sparse_map[i].offset))
return false;
rdsize);
return false;
}
|
CWE-835
| 659 | 11,294 |
262796672957164632576662795092736995098
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
check_sparse_region (struct tar_sparse_file *file, off_t beg, off_t end)
{
if (!lseek_or_error (file, beg))
return false;
while (beg < end)
{
size_t bytes_read;
size_t rdsize = BLOCKSIZE < end - beg ? BLOCKSIZE : end - beg;
char diff_buffer[BLOCKSIZE];
bytes_read = safe_read (file->fd, diff_buffer, rdsize);
if (bytes_read == SAFE_READ_ERROR)
{
read_diag_details (file->stat_info->orig_file_name,
beg,
rdsize);
return false;
}
if (!zero_block_p (diff_buffer, bytes_read))
{
char begbuf[INT_BUFSIZE_BOUND (off_t)];
report_difference (file->stat_info,
_("File fragment at %s is not a hole"),
offtostr (beg, begbuf));
return false;
}
beg += bytes_read;
}
return true;
}
|
CWE-835
| 660 | 11,295 |
8228776884049814987060898066312291773
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
dump_zeros (struct tar_sparse_file *file, off_t offset)
{
static char const zero_buf[BLOCKSIZE];
if (offset < file->offset)
{
errno = EINVAL;
return false;
}
while (file->offset < offset)
{
size_t size = (BLOCKSIZE < offset - file->offset
? BLOCKSIZE
: offset - file->offset);
ssize_t wrbytes;
wrbytes = write (file->fd, zero_buf, size);
if (wrbytes <= 0)
{
if (wrbytes == 0)
errno = EINVAL;
return false;
}
file->offset += wrbytes;
}
return true;
}
|
CWE-835
| 661 | 11,296 |
327683830022348868947785826606709487333
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
lseek_or_error (struct tar_sparse_file *file, off_t offset)
{
if (file->seekable
? lseek (file->fd, offset, SEEK_SET) < 0
: ! dump_zeros (file, offset))
{
seek_diag_details (file->stat_info->orig_file_name, offset);
return false;
}
return true;
}
|
CWE-835
| 662 | 11,297 |
200300799182966158851353461268198698123
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_add_map (struct tar_stat_info *st, struct sp_array const *sp)
{
struct sp_array *sparse_map = st->sparse_map;
size_t avail = st->sparse_map_avail;
if (avail == st->sparse_map_size)
st->sparse_map = sparse_map =
x2nrealloc (sparse_map, &st->sparse_map_size, sizeof *sparse_map);
sparse_map[avail] = *sp;
st->sparse_map_avail = avail + 1;
}
|
CWE-835
| 663 | 11,298 |
133198796031614497515754044808852717782
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_extract_file (int fd, struct tar_stat_info *st, off_t *size)
{
bool rc = true;
struct tar_sparse_file file;
size_t i;
if (!tar_sparse_init (&file))
return dump_status_not_implemented;
file.stat_info = st;
file.fd = fd;
file.seekable = lseek (fd, 0, SEEK_SET) == 0;
file.offset = 0;
rc = tar_sparse_decode_header (&file);
for (i = 0; rc && i < file.stat_info->sparse_map_avail; i++)
rc = tar_sparse_extract_region (&file, i);
*size = file.stat_info->archive_file_size - file.dumped_size;
return (tar_sparse_done (&file) && rc) ? dump_status_ok : dump_status_short;
}
|
CWE-835
| 664 | 11,299 |
141251868747118656286963586236691757395
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_scan_file (struct tar_sparse_file *file)
{
/* always check for completely sparse files */
if (sparse_scan_file_wholesparse (file))
return true;
switch (hole_detection)
{
case HOLE_DETECTION_DEFAULT:
case HOLE_DETECTION_SEEK:
#ifdef SEEK_HOLE
if (sparse_scan_file_seek (file))
return true;
#else
if (hole_detection == HOLE_DETECTION_SEEK)
WARN((0, 0,
_("\"seek\" hole detection is not supported, using \"raw\".")));
/* fall back to "raw" for this and all other files */
hole_detection = HOLE_DETECTION_RAW;
#endif
FALLTHROUGH;
case HOLE_DETECTION_RAW:
if (sparse_scan_file_raw (file))
return true;
}
return false;
}
|
CWE-835
| 666 | 11,300 |
74478474468345034733436721331370205602
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_scan_file_raw (struct tar_sparse_file *file)
{
struct tar_stat_info *st = file->stat_info;
int fd = file->fd;
char buffer[BLOCKSIZE];
size_t count = 0;
off_t offset = 0;
struct sp_array sp = {0, 0};
st->archive_file_size = 0;
if (!tar_sparse_scan (file, scan_begin, NULL))
return false;
while ((count = blocking_read (fd, buffer, sizeof buffer)) != 0
&& count != SAFE_READ_ERROR)
{
/* Analyze the block. */
if (zero_block_p (buffer, count))
{
if (sp.numbytes)
{
sparse_add_map (st, &sp);
sp.numbytes = 0;
if (!tar_sparse_scan (file, scan_block, NULL))
return false;
}
}
else
{
if (sp.numbytes == 0)
sp.offset = offset;
sp.numbytes += count;
st->archive_file_size += count;
if (!tar_sparse_scan (file, scan_block, buffer))
return false;
}
offset += count;
}
/* save one more sparse segment of length 0 to indicate that
the file ends with a hole */
if (sp.numbytes == 0)
sp.offset = offset;
sparse_add_map (st, &sp);
st->archive_file_size += count;
return tar_sparse_scan (file, scan_end, NULL);
}
|
CWE-835
| 667 | 11,301 |
223710354877674081196701390553258922111
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_scan_file_seek (struct tar_sparse_file *file)
{
struct tar_stat_info *st = file->stat_info;
int fd = file->fd;
struct sp_array sp = {0, 0};
off_t offset = 0;
off_t data_offset;
off_t hole_offset;
st->archive_file_size = 0;
for (;;)
{
/* locate first chunk of data */
data_offset = lseek (fd, offset, SEEK_DATA);
if (data_offset == (off_t)-1)
/* ENXIO == EOF; error otherwise */
{
if (errno == ENXIO)
{
/* file ends with hole, add one more empty chunk of data */
sp.numbytes = 0;
sp.offset = st->stat.st_size;
sparse_add_map (st, &sp);
return true;
}
return false;
}
hole_offset = lseek (fd, data_offset, SEEK_HOLE);
/* according to specs, if FS does not fully support
SEEK_DATA/SEEK_HOLE it may just implement kind of "wrapper" around
classic lseek() call. We must detect it here and try to use other
hole-detection methods. */
if (offset == 0 /* first loop */
&& data_offset == 0
&& hole_offset == st->stat.st_size)
{
lseek (fd, 0, SEEK_SET);
return false;
}
sp.offset = data_offset;
sp.numbytes = hole_offset - data_offset;
sparse_add_map (st, &sp);
st->archive_file_size += sp.numbytes;
offset = hole_offset;
}
return true;
}
|
CWE-835
| 668 | 11,302 |
183179349104804232162708433984249028140
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_scan_file_wholesparse (struct tar_sparse_file *file)
{
struct tar_stat_info *st = file->stat_info;
struct sp_array sp = {0, 0};
/* Note that this function is called only for truly sparse files of size >= 1
block size (checked via ST_IS_SPARSE before). See the thread
http://www.mail-archive.com/bug-tar@gnu.org/msg04209.html for more info */
if (ST_NBLOCKS (st->stat) == 0)
{
st->archive_file_size = 0;
sp.offset = st->stat.st_size;
sparse_add_map (st, &sp);
return true;
}
return false;
}
|
CWE-835
| 669 | 11,303 |
101116579052339829483750978738805311968
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_select_optab (struct tar_sparse_file *file)
{
switch (current_format == DEFAULT_FORMAT ? archive_format : current_format)
{
case V7_FORMAT:
case USTAR_FORMAT:
return false;
case OLDGNU_FORMAT:
case GNU_FORMAT: /*FIXME: This one should disappear? */
file->optab = &oldgnu_optab;
break;
case POSIX_FORMAT:
file->optab = &pax_optab;
break;
case STAR_FORMAT:
file->optab = &star_optab;
break;
default:
return false;
}
return true;
}
|
CWE-835
| 670 | 11,304 |
174896022340243822567077118467873542143
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
sparse_skip_file (struct tar_stat_info *st)
{
bool rc = true;
struct tar_sparse_file file;
if (!tar_sparse_init (&file))
return dump_status_not_implemented;
file.stat_info = st;
file.fd = -1;
rc = tar_sparse_decode_header (&file);
skip_file (file.stat_info->archive_file_size - file.dumped_size);
return (tar_sparse_done (&file) && rc) ? dump_status_ok : dump_status_short;
}
|
CWE-835
| 671 | 11,305 |
49509729959645505408651463478231764456
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
tar_sparse_done (struct tar_sparse_file *file)
{
if (file->optab->done)
return file->optab->done (file);
return true;
}
|
CWE-835
| 672 | 11,306 |
9823830495952547325317587657619408901
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
tar_sparse_dump_header (struct tar_sparse_file *file)
{
if (file->optab->dump_header)
return file->optab->dump_header (file);
return false;
}
|
CWE-835
| 673 | 11,307 |
23843709900235878034392424749536602620
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
tar_sparse_dump_region (struct tar_sparse_file *file, size_t i)
{
if (file->optab->dump_region)
return file->optab->dump_region (file, i);
return false;
}
|
CWE-835
| 674 | 11,308 |
203685292815110676282071230969455292616
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
tar_sparse_init (struct tar_sparse_file *file)
{
memset (file, 0, sizeof *file);
if (!sparse_select_optab (file))
return false;
if (file->optab->init)
return file->optab->init (file);
return true;
}
|
CWE-835
| 677 | 11,309 |
46906667836433481518963161158379859183
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
tar_sparse_member_p (struct tar_sparse_file *file)
{
if (file->optab->sparse_member_p)
return file->optab->sparse_member_p (file);
return false;
}
|
CWE-835
| 678 | 11,310 |
303666196822997528284466887066405490408
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
tar_sparse_scan (struct tar_sparse_file *file, enum sparse_scan_state state,
void *block)
{
if (file->optab->scan_block)
return file->optab->scan_block (file, state, block);
return true;
}
|
CWE-835
| 679 | 11,311 |
266840471335513188551561632208438584412
| null | null | null |
savannah
|
c15c42ccd1e2377945fd0414eca1a49294bff454
| 0 |
zero_block_p (char const *buffer, size_t size)
{
while (size--)
if (*buffer++)
return false;
return true;
}
|
CWE-835
| 680 | 11,312 |
129221908368714886153633169628266201977
| null | null | null |
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
static const char *default_charset(void)
{
# if defined HAVE_LIBCHARSET_H && defined HAVE_LOCALE_CHARSET
return locale_charset();
# elif defined HAVE_LANGINFO_H && defined HAVE_NL_LANGINFO
return nl_langinfo(CODESET);
# else
return ""; /* Works with (at the very least) gnu iconv... */
# endif
}
| 689 | 11,320 |
282005334883347660407174604289620953453
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms,
int exists)
{
int new_mode;
/* If the file already exists, we'll return the local permissions,
* possibly tweaked by the --executability option. */
if (exists) {
new_mode = (flist_mode & ~CHMOD_BITS) | (stat_mode & CHMOD_BITS);
if (preserve_executability && S_ISREG(flist_mode)) {
/* If the source file is executable, grant execute
* rights to everyone who can read, but ONLY if the
* file isn't already executable. */
if (!(flist_mode & 0111))
new_mode &= ~0111;
else if (!(stat_mode & 0111))
new_mode |= (new_mode & 0444) >> 2;
}
} else {
/* Apply destination default permissions and turn
* off special permissions. */
new_mode = flist_mode & (~CHMOD_BITS | dflt_perms);
}
return new_mode;
}
| 690 | 11,321 |
333296055602515242616379635793833074637
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
struct file_list *flist_for_ndx(int ndx, const char *fatal_error_loc)
{
struct file_list *flist = cur_flist;
if (!flist && !(flist = first_flist))
goto not_found;
while (ndx < flist->ndx_start-1) {
if (flist == first_flist)
goto not_found;
flist = flist->prev;
}
while (ndx >= flist->ndx_start + flist->used) {
if (!(flist = flist->next))
goto not_found;
}
return flist;
not_found:
if (fatal_error_loc) {
int first, last;
if (first_flist) {
first = first_flist->ndx_start - 1;
last = first_flist->prev->ndx_start + first_flist->prev->used - 1;
} else {
first = 0;
last = -1;
}
rprintf(FERROR,
"File-list index %d not in %d - %d (%s) [%s]\n",
ndx, first, last, fatal_error_loc, who_am_i());
exit_cleanup(RERR_PROTOCOL);
}
return NULL;
}
| 692 | 11,322 |
265974073934216543553236084368690783704
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
void free_sums(struct sum_struct *s)
{
if (s->sums) free(s->sums);
free(s);
}
| 693 | 11,323 |
177654060566778943374232606913707371727
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
int iconvbufs(iconv_t ic, xbuf *in, xbuf *out, int flags)
{
ICONV_CONST char *ibuf;
size_t icnt, ocnt, opos;
char *obuf;
if (!out->size && flags & ICB_EXPAND_OUT) {
size_t siz = ROUND_UP_1024(in->len * 2);
alloc_xbuf(out, siz);
} else if (out->len+1 >= out->size) {
/* There is no room to even start storing data. */
if (!(flags & ICB_EXPAND_OUT) || flags & ICB_CIRCULAR_OUT) {
errno = E2BIG;
return -1;
}
realloc_xbuf(out, out->size + ROUND_UP_1024(in->len * 2));
}
if (flags & ICB_INIT)
iconv(ic, NULL, 0, NULL, 0);
ibuf = in->buf + in->pos;
icnt = in->len;
opos = out->pos + out->len;
if (flags & ICB_CIRCULAR_OUT) {
if (opos >= out->size) {
opos -= out->size;
/* We know that out->pos is not 0 due to the "no room" check
* above, so this can't go "negative". */
ocnt = out->pos - opos - 1;
} else {
/* Allow the use of all bytes to the physical end of the buffer
* unless pos is 0, in which case we reserve our trailing '\0'. */
ocnt = out->size - opos - (out->pos ? 0 : 1);
}
} else
ocnt = out->size - opos - 1;
obuf = out->buf + opos;
while (icnt) {
while (iconv(ic, &ibuf, &icnt, &obuf, &ocnt) == (size_t)-1) {
if (errno == EINTR)
continue;
if (errno == EINVAL) {
if (!(flags & ICB_INCLUDE_INCOMPLETE))
goto finish;
if (!ocnt)
goto e2big;
} else if (errno == EILSEQ) {
if (!(flags & ICB_INCLUDE_BAD))
goto finish;
if (!ocnt)
goto e2big;
} else if (errno == E2BIG) {
size_t siz;
e2big:
opos = obuf - out->buf;
if (flags & ICB_CIRCULAR_OUT && out->pos > 1 && opos > out->pos) {
/* We are in a divided circular buffer at the physical
* end with room to wrap to the start. If iconv() refused
* to use one or more trailing bytes in the buffer, we
* set the size to ignore the unused bytes. */
if (opos < out->size)
reduce_iobuf_size(out, opos);
obuf = out->buf;
ocnt = out->pos - 1;
continue;
}
if (!(flags & ICB_EXPAND_OUT) || flags & ICB_CIRCULAR_OUT) {
errno = E2BIG;
goto finish;
}
siz = ROUND_UP_1024(in->len * 2);
realloc_xbuf(out, out->size + siz);
obuf = out->buf + opos;
ocnt += siz;
continue;
} else {
rsyserr(FERROR, errno, "unexpected error from iconv()");
exit_cleanup(RERR_UNSUPPORTED);
}
*obuf++ = *ibuf++;
ocnt--, icnt--;
if (!icnt)
break;
}
}
errno = 0;
finish:
opos = obuf - out->buf;
if (flags & ICB_CIRCULAR_OUT && opos < out->pos)
opos += out->size;
out->len = opos - out->pos;
in->len = icnt;
in->pos = ibuf - in->buf;
return errno ? -1 : 0;
}
| 694 | 11,324 |
222076732695079732283836825717857032804
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
void send_protected_args(int fd, char *args[])
{
int i;
#ifdef ICONV_OPTION
int convert = ic_send != (iconv_t)-1;
xbuf outbuf, inbuf;
if (convert)
alloc_xbuf(&outbuf, 1024);
#endif
for (i = 0; args[i]; i++) {} /* find first NULL */
args[i] = "rsync"; /* set a new arg0 */
if (DEBUG_GTE(CMD, 1))
print_child_argv("protected args:", args + i + 1);
do {
if (!args[i][0])
write_buf(fd, ".", 2);
#ifdef ICONV_OPTION
else if (convert) {
INIT_XBUF_STRLEN(inbuf, args[i]);
iconvbufs(ic_send, &inbuf, &outbuf,
ICB_EXPAND_OUT | ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE | ICB_INIT);
outbuf.buf[outbuf.len] = '\0';
write_buf(fd, outbuf.buf, outbuf.len + 1);
outbuf.len = 0;
}
#endif
else
write_buf(fd, args[i], strlen(args[i]) + 1);
} while (args[++i]);
write_byte(fd, 0);
#ifdef ICONV_OPTION
if (convert)
free(outbuf.buf);
#endif
}
| 695 | 11,325 |
175982612026745488481742673201233481421
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
void setup_iconv(void)
{
const char *defset = default_charset();
# ifdef ICONV_OPTION
const char *charset;
char *cp;
# endif
if (!am_server && !allow_8bit_chars) {
/* It's OK if this fails... */
ic_chck = iconv_open(defset, defset);
if (DEBUG_GTE(ICONV, 2)) {
if (ic_chck == (iconv_t)-1) {
rprintf(FINFO,
"msg checking via isprint()"
" (iconv_open(\"%s\", \"%s\") errno: %d)\n",
defset, defset, errno);
} else {
rprintf(FINFO,
"msg checking charset: %s\n",
defset);
}
}
} else
ic_chck = (iconv_t)-1;
# ifdef ICONV_OPTION
if (!iconv_opt)
return;
if ((cp = strchr(iconv_opt, ',')) != NULL) {
if (am_server) /* A local transfer needs this. */
iconv_opt = cp + 1;
else
*cp = '\0';
}
if (!*iconv_opt || (*iconv_opt == '.' && iconv_opt[1] == '\0'))
charset = defset;
else
charset = iconv_opt;
if ((ic_send = iconv_open(UTF8_CHARSET, charset)) == (iconv_t)-1) {
rprintf(FERROR, "iconv_open(\"%s\", \"%s\") failed\n",
UTF8_CHARSET, charset);
exit_cleanup(RERR_UNSUPPORTED);
}
if ((ic_recv = iconv_open(charset, UTF8_CHARSET)) == (iconv_t)-1) {
rprintf(FERROR, "iconv_open(\"%s\", \"%s\") failed\n",
charset, UTF8_CHARSET);
exit_cleanup(RERR_UNSUPPORTED);
}
if (DEBUG_GTE(ICONV, 1)) {
rprintf(FINFO, "[%s] charset: %s\n",
who_am_i(), *charset ? charset : "[LOCALE]");
}
# endif
}
| 696 | 11,326 |
3589006063570100811798784027845962420
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
void sig_int(int sig_num)
{
/* KLUGE: if the user hits Ctrl-C while ssh is prompting
* for a password, then our cleanup's sending of a SIGUSR1
* signal to all our children may kill ssh before it has a
* chance to restore the tty settings (i.e. turn echo back
* on). By sleeping for a short time, ssh gets a bigger
* chance to do the right thing. If child processes are
* not ssh waiting for a password, then this tiny delay
* shouldn't hurt anything. */
msleep(400);
/* If we're an rsync daemon listener (not a daemon server),
* we'll exit with status 0 if we received SIGTERM. */
if (am_daemon && !am_server && sig_num == SIGTERM)
exit_cleanup(0);
/* If the signal arrived on the server side (or for the receiver
* process on the client), we want to try to do a controlled shutdown
* that lets the client side (generator process) know what happened.
* To do this, we set a flag and let the normal process handle the
* shutdown. We only attempt this if multiplexed IO is in effect and
* we didn't already set the flag. */
if (!got_kill_signal && (am_server || am_receiver)) {
got_kill_signal = sig_num;
return;
}
exit_cleanup(RERR_SIGNAL);
}
| 697 | 11,327 |
14327309829457428279353304848954587437
| null | null | null |
|
samba
|
70aeb5fddd1b2f8e143276f8d5a085db16c593b9
| 0 |
const char *who_am_i(void)
{
if (am_starting_up)
return am_server ? "server" : "client";
return am_sender ? "sender"
: am_generator ? "generator"
: am_receiver ? "receiver"
: "Receiver"; /* pre-forked receiver */
}
| 698 | 11,328 |
118098839665995166863024221034974865104
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.