idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
100
|
static void add_assoc_asn1_string(zval * val, char * key, ASN1_STRING * str) /* {{{ */
{
add_assoc_stringl(val, key, (char *)str->data, str->length, 1);
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void add_assoc_asn1_string(zval * val, char * key, ASN1_STRING * str) /* {{{ */
{
add_assoc_stringl(val, key, (char *)str->data, str->length, 1);
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
101
|
static void add_assoc_name_entry(zval * val, char * key, X509_NAME * name, int shortname TSRMLS_DC) /* {{{ */
{
zval *subitem, *subentries;
int i, j = -1, last = -1, obj_cnt = 0;
char *sname;
int nid;
X509_NAME_ENTRY * ne;
ASN1_STRING * str = NULL;
ASN1_OBJECT * obj;
if (key != NULL) {
MAKE_STD_ZVAL(subitem);
array_init(subitem);
} else {
subitem = val;
}
for (i = 0; i < X509_NAME_entry_count(name); i++) {
unsigned char *to_add;
int to_add_len;
ne = X509_NAME_get_entry(name, i);
obj = X509_NAME_ENTRY_get_object(ne);
nid = OBJ_obj2nid(obj);
obj_cnt = 0;
if (shortname) {
sname = (char *) OBJ_nid2sn(nid);
} else {
sname = (char *) OBJ_nid2ln(nid);
}
MAKE_STD_ZVAL(subentries);
array_init(subentries);
last = -1;
for (;;) {
j = X509_NAME_get_index_by_OBJ(name, obj, last);
if (j < 0) {
if (last != -1) break;
} else {
obj_cnt++;
ne = X509_NAME_get_entry(name, j);
str = X509_NAME_ENTRY_get_data(ne);
if (ASN1_STRING_type(str) != V_ASN1_UTF8STRING) {
to_add_len = ASN1_STRING_to_UTF8(&to_add, str);
if (to_add_len != -1) {
add_next_index_stringl(subentries, (char *)to_add, to_add_len, 1);
}
} else {
to_add = ASN1_STRING_data(str);
to_add_len = ASN1_STRING_length(str);
add_next_index_stringl(subentries, (char *)to_add, to_add_len, 1);
}
}
last = j;
}
i = last;
if (obj_cnt > 1) {
add_assoc_zval_ex(subitem, sname, strlen(sname) + 1, subentries);
} else {
zval_dtor(subentries);
FREE_ZVAL(subentries);
if (obj_cnt && str && to_add_len > -1) {
add_assoc_stringl(subitem, sname, (char *)to_add, to_add_len, 1);
}
}
}
if (key != NULL) {
zend_hash_update(HASH_OF(val), key, strlen(key) + 1, (void *)&subitem, sizeof(subitem), NULL);
}
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void add_assoc_name_entry(zval * val, char * key, X509_NAME * name, int shortname TSRMLS_DC) /* {{{ */
{
zval *subitem, *subentries;
int i, j = -1, last = -1, obj_cnt = 0;
char *sname;
int nid;
X509_NAME_ENTRY * ne;
ASN1_STRING * str = NULL;
ASN1_OBJECT * obj;
if (key != NULL) {
MAKE_STD_ZVAL(subitem);
array_init(subitem);
} else {
subitem = val;
}
for (i = 0; i < X509_NAME_entry_count(name); i++) {
unsigned char *to_add;
int to_add_len;
ne = X509_NAME_get_entry(name, i);
obj = X509_NAME_ENTRY_get_object(ne);
nid = OBJ_obj2nid(obj);
obj_cnt = 0;
if (shortname) {
sname = (char *) OBJ_nid2sn(nid);
} else {
sname = (char *) OBJ_nid2ln(nid);
}
MAKE_STD_ZVAL(subentries);
array_init(subentries);
last = -1;
for (;;) {
j = X509_NAME_get_index_by_OBJ(name, obj, last);
if (j < 0) {
if (last != -1) break;
} else {
obj_cnt++;
ne = X509_NAME_get_entry(name, j);
str = X509_NAME_ENTRY_get_data(ne);
if (ASN1_STRING_type(str) != V_ASN1_UTF8STRING) {
to_add_len = ASN1_STRING_to_UTF8(&to_add, str);
if (to_add_len != -1) {
add_next_index_stringl(subentries, (char *)to_add, to_add_len, 1);
}
} else {
to_add = ASN1_STRING_data(str);
to_add_len = ASN1_STRING_length(str);
add_next_index_stringl(subentries, (char *)to_add, to_add_len, 1);
}
}
last = j;
}
i = last;
if (obj_cnt > 1) {
add_assoc_zval_ex(subitem, sname, strlen(sname) + 1, subentries);
} else {
zval_dtor(subentries);
FREE_ZVAL(subentries);
if (obj_cnt && str && to_add_len > -1) {
add_assoc_stringl(subitem, sname, (char *)to_add, to_add_len, 1);
}
}
}
if (key != NULL) {
zend_hash_update(HASH_OF(val), key, strlen(key) + 1, (void *)&subitem, sizeof(subitem), NULL);
}
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
102
|
static int add_oid_section(struct php_x509_request * req TSRMLS_DC) /* {{{ */
{
char * str;
STACK_OF(CONF_VALUE) * sktmp;
CONF_VALUE * cnf;
int i;
str = CONF_get_string(req->req_config, NULL, "oid_section");
if (str == NULL) {
return SUCCESS;
}
sktmp = CONF_get_section(req->req_config, str);
if (sktmp == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "problem loading oid section %s", str);
return FAILURE;
}
for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
cnf = sk_CONF_VALUE_value(sktmp, i);
if (OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "problem creating object %s=%s", cnf->name, cnf->value);
return FAILURE;
}
}
return SUCCESS;
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static int add_oid_section(struct php_x509_request * req TSRMLS_DC) /* {{{ */
{
char * str;
STACK_OF(CONF_VALUE) * sktmp;
CONF_VALUE * cnf;
int i;
str = CONF_get_string(req->req_config, NULL, "oid_section");
if (str == NULL) {
return SUCCESS;
}
sktmp = CONF_get_section(req->req_config, str);
if (sktmp == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "problem loading oid section %s", str);
return FAILURE;
}
for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
cnf = sk_CONF_VALUE_value(sktmp, i);
if (OBJ_create(cnf->value, cnf->name, cnf->name) == NID_undef) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "problem creating object %s=%s", cnf->name, cnf->value);
return FAILURE;
}
}
return SUCCESS;
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
103
|
static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, int purpose)
{
int ret=0;
X509_STORE_CTX *csc;
TSRMLS_FETCH();
csc = X509_STORE_CTX_new();
if (csc == NULL) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "memory allocation failure");
return 0;
}
X509_STORE_CTX_init(csc, ctx, x, untrustedchain);
if(purpose >= 0) {
X509_STORE_CTX_set_purpose(csc, purpose);
}
ret = X509_verify_cert(csc);
X509_STORE_CTX_free(csc);
return ret;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static int check_cert(X509_STORE *ctx, X509 *x, STACK_OF(X509) *untrustedchain, int purpose)
{
int ret=0;
X509_STORE_CTX *csc;
TSRMLS_FETCH();
csc = X509_STORE_CTX_new();
if (csc == NULL) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "memory allocation failure");
return 0;
}
X509_STORE_CTX_init(csc, ctx, x, untrustedchain);
if(purpose >= 0) {
X509_STORE_CTX_set_purpose(csc, purpose);
}
ret = X509_verify_cert(csc);
X509_STORE_CTX_free(csc);
return ret;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
104
|
static STACK_OF(X509) * load_all_certs_from_file(char *certfile)
{
STACK_OF(X509_INFO) *sk=NULL;
STACK_OF(X509) *stack=NULL, *ret=NULL;
BIO *in=NULL;
X509_INFO *xi;
TSRMLS_FETCH();
if(!(stack = sk_X509_new_null())) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "memory allocation failure");
goto end;
}
if (php_openssl_safe_mode_chk(certfile TSRMLS_CC)) {
sk_X509_free(stack);
goto end;
}
if(!(in=BIO_new_file(certfile, "r"))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error opening the file, %s", certfile);
sk_X509_free(stack);
goto end;
}
/* This loads from a file, a stack of x509/crl/pkey sets */
if(!(sk=PEM_X509_INFO_read_bio(in, NULL, NULL, NULL))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error reading the file, %s", certfile);
sk_X509_free(stack);
goto end;
}
/* scan over it and pull out the certs */
while (sk_X509_INFO_num(sk)) {
xi=sk_X509_INFO_shift(sk);
if (xi->x509 != NULL) {
sk_X509_push(stack,xi->x509);
xi->x509=NULL;
}
X509_INFO_free(xi);
}
if(!sk_X509_num(stack)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no certificates in file, %s", certfile);
sk_X509_free(stack);
goto end;
}
ret=stack;
end:
BIO_free(in);
sk_X509_INFO_free(sk);
return ret;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static STACK_OF(X509) * load_all_certs_from_file(char *certfile)
{
STACK_OF(X509_INFO) *sk=NULL;
STACK_OF(X509) *stack=NULL, *ret=NULL;
BIO *in=NULL;
X509_INFO *xi;
TSRMLS_FETCH();
if(!(stack = sk_X509_new_null())) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "memory allocation failure");
goto end;
}
if (php_openssl_safe_mode_chk(certfile TSRMLS_CC)) {
sk_X509_free(stack);
goto end;
}
if(!(in=BIO_new_file(certfile, "r"))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error opening the file, %s", certfile);
sk_X509_free(stack);
goto end;
}
/* This loads from a file, a stack of x509/crl/pkey sets */
if(!(sk=PEM_X509_INFO_read_bio(in, NULL, NULL, NULL))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error reading the file, %s", certfile);
sk_X509_free(stack);
goto end;
}
/* scan over it and pull out the certs */
while (sk_X509_INFO_num(sk)) {
xi=sk_X509_INFO_shift(sk);
if (xi->x509 != NULL) {
sk_X509_push(stack,xi->x509);
xi->x509=NULL;
}
X509_INFO_free(xi);
}
if(!sk_X509_num(stack)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no certificates in file, %s", certfile);
sk_X509_free(stack);
goto end;
}
ret=stack;
end:
BIO_free(in);
sk_X509_INFO_free(sk);
return ret;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
105
|
static void openssl_add_method(const OBJ_NAME *name, void *arg) /* {{{ */
{
if (name->alias == 0) {
add_next_index_string((zval*)arg, (char*)name->name, 1);
}
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void openssl_add_method(const OBJ_NAME *name, void *arg) /* {{{ */
{
if (name->alias == 0) {
add_next_index_string((zval*)arg, (char*)name->name, 1);
}
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
106
|
static void openssl_add_method_or_alias(const OBJ_NAME *name, void *arg) /* {{{ */
{
add_next_index_string((zval*)arg, (char*)name->name, 1);
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void openssl_add_method_or_alias(const OBJ_NAME *name, void *arg) /* {{{ */
{
add_next_index_string((zval*)arg, (char*)name->name, 1);
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
107
|
static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension)
{
GENERAL_NAMES *names;
const X509V3_EXT_METHOD *method = NULL;
long i, length, num;
const unsigned char *p;
method = X509V3_EXT_get(extension);
if (method == NULL) {
return -1;
}
p = extension->value->data;
length = extension->value->length;
if (method->it) {
names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length,
ASN1_ITEM_ptr(method->it)));
} else {
names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length));
}
if (names == NULL) {
return -1;
}
num = sk_GENERAL_NAME_num(names);
for (i = 0; i < num; i++) {
GENERAL_NAME *name;
ASN1_STRING *as;
name = sk_GENERAL_NAME_value(names, i);
switch (name->type) {
case GEN_EMAIL:
BIO_puts(bio, "email:");
as = name->d.rfc822Name;
BIO_write(bio, ASN1_STRING_data(as),
ASN1_STRING_length(as));
break;
case GEN_DNS:
BIO_puts(bio, "DNS:");
as = name->d.dNSName;
BIO_write(bio, ASN1_STRING_data(as),
ASN1_STRING_length(as));
break;
case GEN_URI:
BIO_puts(bio, "URI:");
as = name->d.uniformResourceIdentifier;
BIO_write(bio, ASN1_STRING_data(as),
ASN1_STRING_length(as));
break;
default:
/* use builtin print for GEN_OTHERNAME, GEN_X400,
* GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID
*/
GENERAL_NAME_print(bio, name);
}
/* trailing ', ' except for last element */
if (i < (num - 1)) {
BIO_puts(bio, ", ");
}
}
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
return 0;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension)
{
GENERAL_NAMES *names;
const X509V3_EXT_METHOD *method = NULL;
long i, length, num;
const unsigned char *p;
method = X509V3_EXT_get(extension);
if (method == NULL) {
return -1;
}
p = extension->value->data;
length = extension->value->length;
if (method->it) {
names = (GENERAL_NAMES*)(ASN1_item_d2i(NULL, &p, length,
ASN1_ITEM_ptr(method->it)));
} else {
names = (GENERAL_NAMES*)(method->d2i(NULL, &p, length));
}
if (names == NULL) {
return -1;
}
num = sk_GENERAL_NAME_num(names);
for (i = 0; i < num; i++) {
GENERAL_NAME *name;
ASN1_STRING *as;
name = sk_GENERAL_NAME_value(names, i);
switch (name->type) {
case GEN_EMAIL:
BIO_puts(bio, "email:");
as = name->d.rfc822Name;
BIO_write(bio, ASN1_STRING_data(as),
ASN1_STRING_length(as));
break;
case GEN_DNS:
BIO_puts(bio, "DNS:");
as = name->d.dNSName;
BIO_write(bio, ASN1_STRING_data(as),
ASN1_STRING_length(as));
break;
case GEN_URI:
BIO_puts(bio, "URI:");
as = name->d.uniformResourceIdentifier;
BIO_write(bio, ASN1_STRING_data(as),
ASN1_STRING_length(as));
break;
default:
/* use builtin print for GEN_OTHERNAME, GEN_X400,
* GEN_EDIPARTY, GEN_DIRNAME, GEN_IPADD and GEN_RID
*/
GENERAL_NAME_print(bio, name);
}
/* trailing ', ' except for last element */
if (i < (num - 1)) {
BIO_puts(bio, ", ");
}
}
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
return 0;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
108
|
static STACK_OF(X509) * php_array_to_X509_sk(zval ** zcerts TSRMLS_DC) /* {{{ */
{
HashPosition hpos;
zval ** zcertval;
STACK_OF(X509) * sk = NULL;
X509 * cert;
long certresource;
sk = sk_X509_new_null();
/* get certs */
if (Z_TYPE_PP(zcerts) == IS_ARRAY) {
zend_hash_internal_pointer_reset_ex(HASH_OF(*zcerts), &hpos);
while(zend_hash_get_current_data_ex(HASH_OF(*zcerts), (void**)&zcertval, &hpos) == SUCCESS) {
cert = php_openssl_x509_from_zval(zcertval, 0, &certresource TSRMLS_CC);
if (cert == NULL) {
goto clean_exit;
}
if (certresource != -1) {
cert = X509_dup(cert);
if (cert == NULL) {
goto clean_exit;
}
}
sk_X509_push(sk, cert);
zend_hash_move_forward_ex(HASH_OF(*zcerts), &hpos);
}
} else {
/* a single certificate */
cert = php_openssl_x509_from_zval(zcerts, 0, &certresource TSRMLS_CC);
if (cert == NULL) {
goto clean_exit;
}
if (certresource != -1) {
cert = X509_dup(cert);
if (cert == NULL) {
goto clean_exit;
}
}
sk_X509_push(sk, cert);
}
clean_exit:
return sk;
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static STACK_OF(X509) * php_array_to_X509_sk(zval ** zcerts TSRMLS_DC) /* {{{ */
{
HashPosition hpos;
zval ** zcertval;
STACK_OF(X509) * sk = NULL;
X509 * cert;
long certresource;
sk = sk_X509_new_null();
/* get certs */
if (Z_TYPE_PP(zcerts) == IS_ARRAY) {
zend_hash_internal_pointer_reset_ex(HASH_OF(*zcerts), &hpos);
while(zend_hash_get_current_data_ex(HASH_OF(*zcerts), (void**)&zcertval, &hpos) == SUCCESS) {
cert = php_openssl_x509_from_zval(zcertval, 0, &certresource TSRMLS_CC);
if (cert == NULL) {
goto clean_exit;
}
if (certresource != -1) {
cert = X509_dup(cert);
if (cert == NULL) {
goto clean_exit;
}
}
sk_X509_push(sk, cert);
zend_hash_move_forward_ex(HASH_OF(*zcerts), &hpos);
}
} else {
/* a single certificate */
cert = php_openssl_x509_from_zval(zcerts, 0, &certresource TSRMLS_CC);
if (cert == NULL) {
goto clean_exit;
}
if (certresource != -1) {
cert = X509_dup(cert);
if (cert == NULL) {
goto clean_exit;
}
}
sk_X509_push(sk, cert);
}
clean_exit:
return sk;
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
109
|
static void php_csr_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
X509_REQ * csr = (X509_REQ*)rsrc->ptr;
X509_REQ_free(csr);
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void php_csr_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
X509_REQ * csr = (X509_REQ*)rsrc->ptr;
X509_REQ_free(csr);
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
110
|
static inline int php_openssl_config_check_syntax(const char * section_label, const char * config_filename, const char * section, LHASH_OF(CONF_VALUE) * config TSRMLS_DC) /* {{{ */
#else
static inline int php_openssl_config_check_syntax(const char * section_label, const char * config_filename, const char * section, LHASH * config TSRMLS_DC)
#endif
{
X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx);
X509V3_set_conf_lhash(&ctx, config);
if (!X509V3_EXT_add_conf(config, &ctx, (char *)section, NULL)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error loading %s section %s of %s",
section_label,
section,
config_filename);
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static inline int php_openssl_config_check_syntax(const char * section_label, const char * config_filename, const char * section, LHASH_OF(CONF_VALUE) * config TSRMLS_DC) /* {{{ */
#else
static inline int php_openssl_config_check_syntax(const char * section_label, const char * config_filename, const char * section, LHASH * config TSRMLS_DC)
#endif
{
X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx);
X509V3_set_conf_lhash(&ctx, config);
if (!X509V3_EXT_add_conf(config, &ctx, (char *)section, NULL)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error loading %s section %s of %s",
section_label,
section,
config_filename);
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
111
|
static X509_REQ * php_openssl_csr_from_zval(zval ** val, int makeresource, long * resourceval TSRMLS_DC)
{
X509_REQ * csr = NULL;
char * filename = NULL;
BIO * in;
if (resourceval) {
*resourceval = -1;
}
if (Z_TYPE_PP(val) == IS_RESOURCE) {
void * what;
int type;
what = zend_fetch_resource(val TSRMLS_CC, -1, "OpenSSL X.509 CSR", &type, 1, le_csr);
if (what) {
if (resourceval) {
*resourceval = Z_LVAL_PP(val);
}
return (X509_REQ*)what;
}
return NULL;
} else if (Z_TYPE_PP(val) != IS_STRING) {
return NULL;
}
if (Z_STRLEN_PP(val) > 7 && memcmp(Z_STRVAL_PP(val), "file://", sizeof("file://") - 1) == 0) {
filename = Z_STRVAL_PP(val) + (sizeof("file://") - 1);
}
if (filename) {
if (php_openssl_safe_mode_chk(filename TSRMLS_CC)) {
return NULL;
}
in = BIO_new_file(filename, "r");
} else {
in = BIO_new_mem_buf(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
}
csr = PEM_read_bio_X509_REQ(in, NULL,NULL,NULL);
BIO_free(in);
return csr;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static X509_REQ * php_openssl_csr_from_zval(zval ** val, int makeresource, long * resourceval TSRMLS_DC)
{
X509_REQ * csr = NULL;
char * filename = NULL;
BIO * in;
if (resourceval) {
*resourceval = -1;
}
if (Z_TYPE_PP(val) == IS_RESOURCE) {
void * what;
int type;
what = zend_fetch_resource(val TSRMLS_CC, -1, "OpenSSL X.509 CSR", &type, 1, le_csr);
if (what) {
if (resourceval) {
*resourceval = Z_LVAL_PP(val);
}
return (X509_REQ*)what;
}
return NULL;
} else if (Z_TYPE_PP(val) != IS_STRING) {
return NULL;
}
if (Z_STRLEN_PP(val) > 7 && memcmp(Z_STRVAL_PP(val), "file://", sizeof("file://") - 1) == 0) {
filename = Z_STRVAL_PP(val) + (sizeof("file://") - 1);
}
if (filename) {
if (php_openssl_safe_mode_chk(filename TSRMLS_CC)) {
return NULL;
}
in = BIO_new_file(filename, "r");
} else {
in = BIO_new_mem_buf(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
}
csr = PEM_read_bio_X509_REQ(in, NULL,NULL,NULL);
BIO_free(in);
return csr;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
112
|
static void php_openssl_dispose_config(struct php_x509_request * req TSRMLS_DC) /* {{{ */
{
if (req->priv_key) {
EVP_PKEY_free(req->priv_key);
req->priv_key = NULL;
}
if (req->global_config) {
CONF_free(req->global_config);
req->global_config = NULL;
}
if (req->req_config) {
CONF_free(req->req_config);
req->req_config = NULL;
}
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void php_openssl_dispose_config(struct php_x509_request * req TSRMLS_DC) /* {{{ */
{
if (req->priv_key) {
EVP_PKEY_free(req->priv_key);
req->priv_key = NULL;
}
if (req->global_config) {
CONF_free(req->global_config);
req->global_config = NULL;
}
if (req->req_config) {
CONF_free(req->req_config);
req->req_config = NULL;
}
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
113
|
static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req TSRMLS_DC)
{
char * randfile = NULL;
int egdsocket, seeded;
EVP_PKEY * return_val = NULL;
if (req->priv_key_bits < MIN_KEY_LENGTH) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "private key length is too short; it needs to be at least %d bits, not %d",
MIN_KEY_LENGTH, req->priv_key_bits);
return NULL;
}
randfile = CONF_get_string(req->req_config, req->section_name, "RANDFILE");
php_openssl_load_rand_file(randfile, &egdsocket, &seeded);
if ((req->priv_key = EVP_PKEY_new()) != NULL) {
switch(req->priv_key_type) {
case OPENSSL_KEYTYPE_RSA:
if (EVP_PKEY_assign_RSA(req->priv_key, RSA_generate_key(req->priv_key_bits, 0x10001, NULL, NULL))) {
return_val = req->priv_key;
}
break;
#if !defined(NO_DSA) && defined(HAVE_DSA_DEFAULT_METHOD)
case OPENSSL_KEYTYPE_DSA:
{
DSA *dsapar = DSA_generate_parameters(req->priv_key_bits, NULL, 0, NULL, NULL, NULL, NULL);
if (dsapar) {
DSA_set_method(dsapar, DSA_get_default_method());
if (DSA_generate_key(dsapar)) {
if (EVP_PKEY_assign_DSA(req->priv_key, dsapar)) {
return_val = req->priv_key;
}
} else {
DSA_free(dsapar);
}
}
}
break;
#endif
#if !defined(NO_DH)
case OPENSSL_KEYTYPE_DH:
{
DH *dhpar = DH_generate_parameters(req->priv_key_bits, 2, NULL, NULL);
int codes = 0;
if (dhpar) {
DH_set_method(dhpar, DH_get_default_method());
if (DH_check(dhpar, &codes) && codes == 0 && DH_generate_key(dhpar)) {
if (EVP_PKEY_assign_DH(req->priv_key, dhpar)) {
return_val = req->priv_key;
}
} else {
DH_free(dhpar);
}
}
}
break;
#endif
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported private key type");
}
}
php_openssl_write_rand_file(randfile, egdsocket, seeded);
if (return_val == NULL) {
EVP_PKEY_free(req->priv_key);
req->priv_key = NULL;
return NULL;
}
return return_val;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req TSRMLS_DC)
{
char * randfile = NULL;
int egdsocket, seeded;
EVP_PKEY * return_val = NULL;
if (req->priv_key_bits < MIN_KEY_LENGTH) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "private key length is too short; it needs to be at least %d bits, not %d",
MIN_KEY_LENGTH, req->priv_key_bits);
return NULL;
}
randfile = CONF_get_string(req->req_config, req->section_name, "RANDFILE");
php_openssl_load_rand_file(randfile, &egdsocket, &seeded);
if ((req->priv_key = EVP_PKEY_new()) != NULL) {
switch(req->priv_key_type) {
case OPENSSL_KEYTYPE_RSA:
if (EVP_PKEY_assign_RSA(req->priv_key, RSA_generate_key(req->priv_key_bits, 0x10001, NULL, NULL))) {
return_val = req->priv_key;
}
break;
#if !defined(NO_DSA) && defined(HAVE_DSA_DEFAULT_METHOD)
case OPENSSL_KEYTYPE_DSA:
{
DSA *dsapar = DSA_generate_parameters(req->priv_key_bits, NULL, 0, NULL, NULL, NULL, NULL);
if (dsapar) {
DSA_set_method(dsapar, DSA_get_default_method());
if (DSA_generate_key(dsapar)) {
if (EVP_PKEY_assign_DSA(req->priv_key, dsapar)) {
return_val = req->priv_key;
}
} else {
DSA_free(dsapar);
}
}
}
break;
#endif
#if !defined(NO_DH)
case OPENSSL_KEYTYPE_DH:
{
DH *dhpar = DH_generate_parameters(req->priv_key_bits, 2, NULL, NULL);
int codes = 0;
if (dhpar) {
DH_set_method(dhpar, DH_get_default_method());
if (DH_check(dhpar, &codes) && codes == 0 && DH_generate_key(dhpar)) {
if (EVP_PKEY_assign_DH(req->priv_key, dhpar)) {
return_val = req->priv_key;
}
} else {
DH_free(dhpar);
}
}
}
break;
#endif
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported private key type");
}
}
php_openssl_write_rand_file(randfile, egdsocket, seeded);
if (return_val == NULL) {
EVP_PKEY_free(req->priv_key);
req->priv_key = NULL;
return NULL;
}
return return_val;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
114
|
static const EVP_CIPHER * php_openssl_get_evp_cipher_from_algo(long algo) { /* {{{ */
switch (algo) {
#ifndef OPENSSL_NO_RC2
case PHP_OPENSSL_CIPHER_RC2_40:
return EVP_rc2_40_cbc();
break;
case PHP_OPENSSL_CIPHER_RC2_64:
return EVP_rc2_64_cbc();
break;
case PHP_OPENSSL_CIPHER_RC2_128:
return EVP_rc2_cbc();
break;
#endif
#ifndef OPENSSL_NO_DES
case PHP_OPENSSL_CIPHER_DES:
return EVP_des_cbc();
break;
case PHP_OPENSSL_CIPHER_3DES:
return EVP_des_ede3_cbc();
break;
#endif
default:
return NULL;
break;
}
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static const EVP_CIPHER * php_openssl_get_evp_cipher_from_algo(long algo) { /* {{{ */
switch (algo) {
#ifndef OPENSSL_NO_RC2
case PHP_OPENSSL_CIPHER_RC2_40:
return EVP_rc2_40_cbc();
break;
case PHP_OPENSSL_CIPHER_RC2_64:
return EVP_rc2_64_cbc();
break;
case PHP_OPENSSL_CIPHER_RC2_128:
return EVP_rc2_cbc();
break;
#endif
#ifndef OPENSSL_NO_DES
case PHP_OPENSSL_CIPHER_DES:
return EVP_des_cbc();
break;
case PHP_OPENSSL_CIPHER_3DES:
return EVP_des_ede3_cbc();
break;
#endif
default:
return NULL;
break;
}
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
115
|
static EVP_MD * php_openssl_get_evp_md_from_algo(long algo) { /* {{{ */
EVP_MD *mdtype;
switch (algo) {
case OPENSSL_ALGO_SHA1:
mdtype = (EVP_MD *) EVP_sha1();
break;
case OPENSSL_ALGO_MD5:
mdtype = (EVP_MD *) EVP_md5();
break;
case OPENSSL_ALGO_MD4:
mdtype = (EVP_MD *) EVP_md4();
break;
#ifdef HAVE_OPENSSL_MD2_H
case OPENSSL_ALGO_MD2:
mdtype = (EVP_MD *) EVP_md2();
break;
#endif
case OPENSSL_ALGO_DSS1:
mdtype = (EVP_MD *) EVP_dss1();
break;
default:
return NULL;
break;
}
return mdtype;
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static EVP_MD * php_openssl_get_evp_md_from_algo(long algo) { /* {{{ */
EVP_MD *mdtype;
switch (algo) {
case OPENSSL_ALGO_SHA1:
mdtype = (EVP_MD *) EVP_sha1();
break;
case OPENSSL_ALGO_MD5:
mdtype = (EVP_MD *) EVP_md5();
break;
case OPENSSL_ALGO_MD4:
mdtype = (EVP_MD *) EVP_md4();
break;
#ifdef HAVE_OPENSSL_MD2_H
case OPENSSL_ALGO_MD2:
mdtype = (EVP_MD *) EVP_md2();
break;
#endif
case OPENSSL_ALGO_DSS1:
mdtype = (EVP_MD *) EVP_dss1();
break;
default:
return NULL;
break;
}
return mdtype;
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
116
|
static int php_openssl_load_rand_file(const char * file, int *egdsocket, int *seeded) /* {{{ */
{
char buffer[MAXPATHLEN];
TSRMLS_FETCH();
*egdsocket = 0;
*seeded = 0;
if (file == NULL) {
file = RAND_file_name(buffer, sizeof(buffer));
} else if (RAND_egd(file) > 0) {
/* if the given filename is an EGD socket, don't
* write anything back to it */
*egdsocket = 1;
return SUCCESS;
}
if (file == NULL || !RAND_load_file(file, -1)) {
if (RAND_status() == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to load random state; not enough random data!");
return FAILURE;
}
return FAILURE;
}
*seeded = 1;
return SUCCESS;
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static int php_openssl_load_rand_file(const char * file, int *egdsocket, int *seeded) /* {{{ */
{
char buffer[MAXPATHLEN];
TSRMLS_FETCH();
*egdsocket = 0;
*seeded = 0;
if (file == NULL) {
file = RAND_file_name(buffer, sizeof(buffer));
} else if (RAND_egd(file) > 0) {
/* if the given filename is an EGD socket, don't
* write anything back to it */
*egdsocket = 1;
return SUCCESS;
}
if (file == NULL || !RAND_load_file(file, -1)) {
if (RAND_status() == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to load random state; not enough random data!");
return FAILURE;
}
return FAILURE;
}
*seeded = 1;
return SUCCESS;
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
117
|
static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, zval * dn, zval * attribs TSRMLS_DC)
{
STACK_OF(CONF_VALUE) * dn_sk, *attr_sk = NULL;
char * str, *dn_sect, *attr_sect;
dn_sect = CONF_get_string(req->req_config, req->section_name, "distinguished_name");
if (dn_sect == NULL) {
return FAILURE;
}
dn_sk = CONF_get_section(req->req_config, dn_sect);
if (dn_sk == NULL) {
return FAILURE;
}
attr_sect = CONF_get_string(req->req_config, req->section_name, "attributes");
if (attr_sect == NULL) {
attr_sk = NULL;
} else {
attr_sk = CONF_get_section(req->req_config, attr_sect);
if (attr_sk == NULL) {
return FAILURE;
}
}
/* setup the version number: version 1 */
if (X509_REQ_set_version(csr, 0L)) {
int i, nid;
char * type;
CONF_VALUE * v;
X509_NAME * subj;
HashPosition hpos;
zval ** item;
subj = X509_REQ_get_subject_name(csr);
/* apply values from the dn hash */
zend_hash_internal_pointer_reset_ex(HASH_OF(dn), &hpos);
while(zend_hash_get_current_data_ex(HASH_OF(dn), (void**)&item, &hpos) == SUCCESS) {
char * strindex = NULL;
uint strindexlen = 0;
ulong intindex;
zend_hash_get_current_key_ex(HASH_OF(dn), &strindex, &strindexlen, &intindex, 0, &hpos);
convert_to_string_ex(item);
if (strindex) {
int nid;
nid = OBJ_txt2nid(strindex);
if (nid != NID_undef) {
if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC,
(unsigned char*)Z_STRVAL_PP(item), -1, -1, 0))
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dn: add_entry_by_NID %d -> %s (failed)", nid, Z_STRVAL_PP(item));
return FAILURE;
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dn: %s is not a recognized name", strindex);
}
}
zend_hash_move_forward_ex(HASH_OF(dn), &hpos);
}
/* Finally apply defaults from config file */
for(i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) {
int len;
char buffer[200 + 1]; /*200 + \0 !*/
v = sk_CONF_VALUE_value(dn_sk, i);
type = v->name;
len = strlen(type);
if (len < sizeof("_default")) {
continue;
}
len -= sizeof("_default") - 1;
if (strcmp("_default", type + len) != 0) {
continue;
}
if (len > 200) {
len = 200;
}
memcpy(buffer, type, len);
buffer[len] = '\0';
type = buffer;
/* Skip past any leading X. X: X, etc to allow for multiple
* instances */
for (str = type; *str; str++) {
if (*str == ':' || *str == ',' || *str == '.') {
str++;
if (*str) {
type = str;
}
break;
}
}
/* if it is already set, skip this */
nid = OBJ_txt2nid(type);
if (X509_NAME_get_index_by_NID(subj, nid, -1) >= 0) {
continue;
}
if (!X509_NAME_add_entry_by_txt(subj, type, MBSTRING_ASC, (unsigned char*)v->value, -1, -1, 0)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_entry_by_txt %s -> %s (failed)", type, v->value);
return FAILURE;
}
if (!X509_NAME_entry_count(subj)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no objects specified in config file");
return FAILURE;
}
}
if (attribs) {
zend_hash_internal_pointer_reset_ex(HASH_OF(attribs), &hpos);
while(zend_hash_get_current_data_ex(HASH_OF(attribs), (void**)&item, &hpos) == SUCCESS) {
char *strindex = NULL;
uint strindexlen;
ulong intindex;
zend_hash_get_current_key_ex(HASH_OF(attribs), &strindex, &strindexlen, &intindex, 0, &hpos);
convert_to_string_ex(item);
if (strindex) {
int nid;
nid = OBJ_txt2nid(strindex);
if (nid != NID_undef) {
if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC, (unsigned char*)Z_STRVAL_PP(item), -1, -1, 0)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "attribs: add_entry_by_NID %d -> %s (failed)", nid, Z_STRVAL_PP(item));
return FAILURE;
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dn: %s is not a recognized name", strindex);
}
}
zend_hash_move_forward_ex(HASH_OF(attribs), &hpos);
}
for (i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) {
v = sk_CONF_VALUE_value(attr_sk, i);
/* if it is already set, skip this */
nid = OBJ_txt2nid(v->name);
if (X509_REQ_get_attr_by_NID(csr, nid, -1) >= 0) {
continue;
}
if (!X509_REQ_add1_attr_by_txt(csr, v->name, MBSTRING_ASC, (unsigned char*)v->value, -1)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "add1_attr_by_txt %s -> %s (failed)", v->name, v->value);
return FAILURE;
}
}
}
}
X509_REQ_set_pubkey(csr, req->priv_key);
return SUCCESS;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, zval * dn, zval * attribs TSRMLS_DC)
{
STACK_OF(CONF_VALUE) * dn_sk, *attr_sk = NULL;
char * str, *dn_sect, *attr_sect;
dn_sect = CONF_get_string(req->req_config, req->section_name, "distinguished_name");
if (dn_sect == NULL) {
return FAILURE;
}
dn_sk = CONF_get_section(req->req_config, dn_sect);
if (dn_sk == NULL) {
return FAILURE;
}
attr_sect = CONF_get_string(req->req_config, req->section_name, "attributes");
if (attr_sect == NULL) {
attr_sk = NULL;
} else {
attr_sk = CONF_get_section(req->req_config, attr_sect);
if (attr_sk == NULL) {
return FAILURE;
}
}
/* setup the version number: version 1 */
if (X509_REQ_set_version(csr, 0L)) {
int i, nid;
char * type;
CONF_VALUE * v;
X509_NAME * subj;
HashPosition hpos;
zval ** item;
subj = X509_REQ_get_subject_name(csr);
/* apply values from the dn hash */
zend_hash_internal_pointer_reset_ex(HASH_OF(dn), &hpos);
while(zend_hash_get_current_data_ex(HASH_OF(dn), (void**)&item, &hpos) == SUCCESS) {
char * strindex = NULL;
uint strindexlen = 0;
ulong intindex;
zend_hash_get_current_key_ex(HASH_OF(dn), &strindex, &strindexlen, &intindex, 0, &hpos);
convert_to_string_ex(item);
if (strindex) {
int nid;
nid = OBJ_txt2nid(strindex);
if (nid != NID_undef) {
if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC,
(unsigned char*)Z_STRVAL_PP(item), -1, -1, 0))
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dn: add_entry_by_NID %d -> %s (failed)", nid, Z_STRVAL_PP(item));
return FAILURE;
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dn: %s is not a recognized name", strindex);
}
}
zend_hash_move_forward_ex(HASH_OF(dn), &hpos);
}
/* Finally apply defaults from config file */
for(i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) {
int len;
char buffer[200 + 1]; /*200 + \0 !*/
v = sk_CONF_VALUE_value(dn_sk, i);
type = v->name;
len = strlen(type);
if (len < sizeof("_default")) {
continue;
}
len -= sizeof("_default") - 1;
if (strcmp("_default", type + len) != 0) {
continue;
}
if (len > 200) {
len = 200;
}
memcpy(buffer, type, len);
buffer[len] = '\0';
type = buffer;
/* Skip past any leading X. X: X, etc to allow for multiple
* instances */
for (str = type; *str; str++) {
if (*str == ':' || *str == ',' || *str == '.') {
str++;
if (*str) {
type = str;
}
break;
}
}
/* if it is already set, skip this */
nid = OBJ_txt2nid(type);
if (X509_NAME_get_index_by_NID(subj, nid, -1) >= 0) {
continue;
}
if (!X509_NAME_add_entry_by_txt(subj, type, MBSTRING_ASC, (unsigned char*)v->value, -1, -1, 0)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "add_entry_by_txt %s -> %s (failed)", type, v->value);
return FAILURE;
}
if (!X509_NAME_entry_count(subj)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "no objects specified in config file");
return FAILURE;
}
}
if (attribs) {
zend_hash_internal_pointer_reset_ex(HASH_OF(attribs), &hpos);
while(zend_hash_get_current_data_ex(HASH_OF(attribs), (void**)&item, &hpos) == SUCCESS) {
char *strindex = NULL;
uint strindexlen;
ulong intindex;
zend_hash_get_current_key_ex(HASH_OF(attribs), &strindex, &strindexlen, &intindex, 0, &hpos);
convert_to_string_ex(item);
if (strindex) {
int nid;
nid = OBJ_txt2nid(strindex);
if (nid != NID_undef) {
if (!X509_NAME_add_entry_by_NID(subj, nid, MBSTRING_ASC, (unsigned char*)Z_STRVAL_PP(item), -1, -1, 0)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "attribs: add_entry_by_NID %d -> %s (failed)", nid, Z_STRVAL_PP(item));
return FAILURE;
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "dn: %s is not a recognized name", strindex);
}
}
zend_hash_move_forward_ex(HASH_OF(attribs), &hpos);
}
for (i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) {
v = sk_CONF_VALUE_value(attr_sk, i);
/* if it is already set, skip this */
nid = OBJ_txt2nid(v->name);
if (X509_REQ_get_attr_by_NID(csr, nid, -1) >= 0) {
continue;
}
if (!X509_REQ_add1_attr_by_txt(csr, v->name, MBSTRING_ASC, (unsigned char*)v->value, -1)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "add1_attr_by_txt %s -> %s (failed)", v->name, v->value);
return FAILURE;
}
}
}
}
X509_REQ_set_pubkey(csr, req->priv_key);
return SUCCESS;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
118
|
static int php_openssl_write_rand_file(const char * file, int egdsocket, int seeded) /* {{{ */
{
char buffer[MAXPATHLEN];
TSRMLS_FETCH();
if (egdsocket || !seeded) {
/* if we did not manage to read the seed file, we should not write
* a low-entropy seed file back */
return FAILURE;
}
if (file == NULL) {
file = RAND_file_name(buffer, sizeof(buffer));
}
if (file == NULL || !RAND_write_file(file)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to write random state");
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static int php_openssl_write_rand_file(const char * file, int egdsocket, int seeded) /* {{{ */
{
char buffer[MAXPATHLEN];
TSRMLS_FETCH();
if (egdsocket || !seeded) {
/* if we did not manage to read the seed file, we should not write
* a low-entropy seed file back */
return FAILURE;
}
if (file == NULL) {
file = RAND_file_name(buffer, sizeof(buffer));
}
if (file == NULL || !RAND_write_file(file)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to write random state");
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
119
|
static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * resourceval TSRMLS_DC)
{
X509 *cert = NULL;
if (resourceval) {
*resourceval = -1;
}
if (Z_TYPE_PP(val) == IS_RESOURCE) {
/* is it an x509 resource ? */
void * what;
int type;
what = zend_fetch_resource(val TSRMLS_CC, -1, "OpenSSL X.509", &type, 1, le_x509);
if (!what) {
return NULL;
}
/* this is so callers can decide if they should free the X509 */
if (resourceval) {
*resourceval = Z_LVAL_PP(val);
}
if (type == le_x509) {
return (X509*)what;
}
/* other types could be used here - eg: file pointers and read in the data from them */
return NULL;
}
if (!(Z_TYPE_PP(val) == IS_STRING || Z_TYPE_PP(val) == IS_OBJECT)) {
return NULL;
}
/* force it to be a string and check if it refers to a file */
convert_to_string_ex(val);
if (Z_STRLEN_PP(val) > 7 && memcmp(Z_STRVAL_PP(val), "file://", sizeof("file://") - 1) == 0) {
/* read cert from the named file */
BIO *in;
if (php_openssl_safe_mode_chk(Z_STRVAL_PP(val) + (sizeof("file://") - 1) TSRMLS_CC)) {
return NULL;
}
in = BIO_new_file(Z_STRVAL_PP(val) + (sizeof("file://") - 1), "r");
if (in == NULL) {
return NULL;
}
cert = PEM_read_bio_X509(in, NULL, NULL, NULL);
BIO_free(in);
} else {
BIO *in;
in = BIO_new_mem_buf(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
if (in == NULL) {
return NULL;
}
#ifdef TYPEDEF_D2I_OF
cert = (X509 *) PEM_ASN1_read_bio((d2i_of_void *)d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL);
#else
cert = (X509 *) PEM_ASN1_read_bio((char *(*)())d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL);
#endif
BIO_free(in);
}
if (cert && makeresource && resourceval) {
*resourceval = zend_list_insert(cert, le_x509);
}
return cert;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * resourceval TSRMLS_DC)
{
X509 *cert = NULL;
if (resourceval) {
*resourceval = -1;
}
if (Z_TYPE_PP(val) == IS_RESOURCE) {
/* is it an x509 resource ? */
void * what;
int type;
what = zend_fetch_resource(val TSRMLS_CC, -1, "OpenSSL X.509", &type, 1, le_x509);
if (!what) {
return NULL;
}
/* this is so callers can decide if they should free the X509 */
if (resourceval) {
*resourceval = Z_LVAL_PP(val);
}
if (type == le_x509) {
return (X509*)what;
}
/* other types could be used here - eg: file pointers and read in the data from them */
return NULL;
}
if (!(Z_TYPE_PP(val) == IS_STRING || Z_TYPE_PP(val) == IS_OBJECT)) {
return NULL;
}
/* force it to be a string and check if it refers to a file */
convert_to_string_ex(val);
if (Z_STRLEN_PP(val) > 7 && memcmp(Z_STRVAL_PP(val), "file://", sizeof("file://") - 1) == 0) {
/* read cert from the named file */
BIO *in;
if (php_openssl_safe_mode_chk(Z_STRVAL_PP(val) + (sizeof("file://") - 1) TSRMLS_CC)) {
return NULL;
}
in = BIO_new_file(Z_STRVAL_PP(val) + (sizeof("file://") - 1), "r");
if (in == NULL) {
return NULL;
}
cert = PEM_read_bio_X509(in, NULL, NULL, NULL);
BIO_free(in);
} else {
BIO *in;
in = BIO_new_mem_buf(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
if (in == NULL) {
return NULL;
}
#ifdef TYPEDEF_D2I_OF
cert = (X509 *) PEM_ASN1_read_bio((d2i_of_void *)d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL);
#else
cert = (X509 *) PEM_ASN1_read_bio((char *(*)())d2i_X509, PEM_STRING_X509, in, NULL, NULL, NULL);
#endif
BIO_free(in);
}
if (cert && makeresource && resourceval) {
*resourceval = zend_list_insert(cert, le_x509);
}
return cert;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
120
|
static void php_pkey_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
EVP_PKEY *pkey = (EVP_PKEY *)rsrc->ptr;
assert(pkey != NULL);
EVP_PKEY_free(pkey);
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void php_pkey_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
EVP_PKEY *pkey = (EVP_PKEY *)rsrc->ptr;
assert(pkey != NULL);
EVP_PKEY_free(pkey);
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
121
|
static void php_x509_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
X509 *x509 = (X509 *)rsrc->ptr;
X509_free(x509);
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static void php_x509_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
X509 *x509 = (X509 *)rsrc->ptr;
X509_free(x509);
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
122
|
static X509_STORE * setup_verify(zval * calist TSRMLS_DC)
{
X509_STORE *store;
X509_LOOKUP * dir_lookup, * file_lookup;
HashPosition pos;
int ndirs = 0, nfiles = 0;
store = X509_STORE_new();
if (store == NULL) {
return NULL;
}
if (calist && (Z_TYPE_P(calist) == IS_ARRAY)) {
zend_hash_internal_pointer_reset_ex(HASH_OF(calist), &pos);
for (;; zend_hash_move_forward_ex(HASH_OF(calist), &pos)) {
zval ** item;
struct stat sb;
if (zend_hash_get_current_data_ex(HASH_OF(calist), (void**)&item, &pos) == FAILURE) {
break;
}
convert_to_string_ex(item);
if (VCWD_STAT(Z_STRVAL_PP(item), &sb) == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to stat %s", Z_STRVAL_PP(item));
continue;
}
if ((sb.st_mode & S_IFREG) == S_IFREG) {
file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
if (file_lookup == NULL || !X509_LOOKUP_load_file(file_lookup, Z_STRVAL_PP(item), X509_FILETYPE_PEM)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error loading file %s", Z_STRVAL_PP(item));
} else {
nfiles++;
}
file_lookup = NULL;
} else {
dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
if (dir_lookup == NULL || !X509_LOOKUP_add_dir(dir_lookup, Z_STRVAL_PP(item), X509_FILETYPE_PEM)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error loading directory %s", Z_STRVAL_PP(item));
} else {
ndirs++;
}
dir_lookup = NULL;
}
}
}
if (nfiles == 0) {
file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
if (file_lookup) {
X509_LOOKUP_load_file(file_lookup, NULL, X509_FILETYPE_DEFAULT);
}
}
if (ndirs == 0) {
dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
if (dir_lookup) {
X509_LOOKUP_add_dir(dir_lookup, NULL, X509_FILETYPE_DEFAULT);
}
}
return store;
}
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static X509_STORE * setup_verify(zval * calist TSRMLS_DC)
{
X509_STORE *store;
X509_LOOKUP * dir_lookup, * file_lookup;
HashPosition pos;
int ndirs = 0, nfiles = 0;
store = X509_STORE_new();
if (store == NULL) {
return NULL;
}
if (calist && (Z_TYPE_P(calist) == IS_ARRAY)) {
zend_hash_internal_pointer_reset_ex(HASH_OF(calist), &pos);
for (;; zend_hash_move_forward_ex(HASH_OF(calist), &pos)) {
zval ** item;
struct stat sb;
if (zend_hash_get_current_data_ex(HASH_OF(calist), (void**)&item, &pos) == FAILURE) {
break;
}
convert_to_string_ex(item);
if (VCWD_STAT(Z_STRVAL_PP(item), &sb) == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to stat %s", Z_STRVAL_PP(item));
continue;
}
if ((sb.st_mode & S_IFREG) == S_IFREG) {
file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
if (file_lookup == NULL || !X509_LOOKUP_load_file(file_lookup, Z_STRVAL_PP(item), X509_FILETYPE_PEM)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error loading file %s", Z_STRVAL_PP(item));
} else {
nfiles++;
}
file_lookup = NULL;
} else {
dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
if (dir_lookup == NULL || !X509_LOOKUP_add_dir(dir_lookup, Z_STRVAL_PP(item), X509_FILETYPE_PEM)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "error loading directory %s", Z_STRVAL_PP(item));
} else {
ndirs++;
}
dir_lookup = NULL;
}
}
}
if (nfiles == 0) {
file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
if (file_lookup) {
X509_LOOKUP_load_file(file_lookup, NULL, X509_FILETYPE_DEFAULT);
}
}
if (ndirs == 0) {
dir_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());
if (dir_lookup) {
X509_LOOKUP_add_dir(dir_lookup, NULL, X509_FILETYPE_DEFAULT);
}
}
return store;
}
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
123
|
static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) /* {{{ */
{
php_stream *stream;
SSL *ssl;
X509 *err_cert;
int err, depth, ret;
zval **val;
ret = preverify_ok;
/* determine the status for the current cert */
err_cert = X509_STORE_CTX_get_current_cert(ctx);
err = X509_STORE_CTX_get_error(ctx);
depth = X509_STORE_CTX_get_error_depth(ctx);
/* conjure the stream & context to use */
ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
stream = (php_stream*)SSL_get_ex_data(ssl, ssl_stream_data_index);
/* if allow_self_signed is set, make sure that verification succeeds */
if (err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT && GET_VER_OPT("allow_self_signed") && zval_is_true(*val)) {
ret = 1;
}
/* check the depth */
if (GET_VER_OPT("verify_depth")) {
convert_to_long_ex(val);
if (depth > Z_LVAL_PP(val)) {
ret = 0;
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_CHAIN_TOO_LONG);
}
}
return ret;
}
/* }}} */
|
DoS Exec Code Overflow Mem. Corr.
| 0
|
static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) /* {{{ */
{
php_stream *stream;
SSL *ssl;
X509 *err_cert;
int err, depth, ret;
zval **val;
ret = preverify_ok;
/* determine the status for the current cert */
err_cert = X509_STORE_CTX_get_current_cert(ctx);
err = X509_STORE_CTX_get_error(ctx);
depth = X509_STORE_CTX_get_error_depth(ctx);
/* conjure the stream & context to use */
ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
stream = (php_stream*)SSL_get_ex_data(ssl, ssl_stream_data_index);
/* if allow_self_signed is set, make sure that verification succeeds */
if (err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT && GET_VER_OPT("allow_self_signed") && zval_is_true(*val)) {
ret = 1;
}
/* check the depth */
if (GET_VER_OPT("verify_depth")) {
convert_to_long_ex(val);
if (depth > Z_LVAL_PP(val)) {
ret = 0;
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_CHAIN_TOO_LONG);
}
}
return ret;
}
/* }}} */
|
@@ -644,18 +644,28 @@ static time_t asn1_time_to_time_t(ASN1_UTCTIME * timestr TSRMLS_DC) /* {{{ */
char * thestr;
long gmadjust = 0;
- if (timestr->length < 13) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "extension author too lazy to parse %s correctly", timestr->data);
+ if (ASN1_STRING_type(timestr) != V_ASN1_UTCTIME) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal ASN1 data type for timestamp");
return (time_t)-1;
}
- strbuf = estrdup((char *)timestr->data);
+ if (ASN1_STRING_length(timestr) != strlen(ASN1_STRING_data(timestr))) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "illegal length in timestamp");
+ return (time_t)-1;
+ }
+
+ if (ASN1_STRING_length(timestr) < 13) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to parse time string %s correctly", timestr->data);
+ return (time_t)-1;
+ }
+
+ strbuf = estrdup((char *)ASN1_STRING_data(timestr));
memset(&thetime, 0, sizeof(thetime));
/* we work backwards so that we can use atoi more easily */
- thestr = strbuf + timestr->length - 3;
+ thestr = strbuf + ASN1_STRING_length(timestr) - 3;
thetime.tm_sec = atoi(thestr);
*thestr = '\0';
|
CWE-119
| null | null |
124
|
gnutls_session_get_data2 (gnutls_session_t session, gnutls_datum_t * data)
{
int ret;
if (data == NULL)
{
return GNUTLS_E_INVALID_REQUEST;
}
if (session->internals.resumable == RESUME_FALSE)
return GNUTLS_E_INVALID_SESSION;
ret = _gnutls_session_pack (session, data);
if (ret < 0)
{
gnutls_assert ();
return ret;
}
return 0;
}
|
DoS Overflow
| 0
|
gnutls_session_get_data2 (gnutls_session_t session, gnutls_datum_t * data)
{
int ret;
if (data == NULL)
{
return GNUTLS_E_INVALID_REQUEST;
}
if (session->internals.resumable == RESUME_FALSE)
return GNUTLS_E_INVALID_SESSION;
ret = _gnutls_session_pack (session, data);
if (ret < 0)
{
gnutls_assert ();
return ret;
}
return 0;
}
|
@@ -63,13 +63,13 @@ gnutls_session_get_data (gnutls_session_t session,
gnutls_assert ();
return ret;
}
- *session_data_size = psession.size;
if (psession.size > *session_data_size)
{
ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
goto error;
}
+ *session_data_size = psession.size;
if (session_data != NULL)
memcpy (session_data, psession.data, psession.size);
|
CWE-119
| null | null |
125
|
gnutls_session_get_id (gnutls_session_t session,
void *session_id, size_t * session_id_size)
{
size_t given_session_id_size = *session_id_size;
*session_id_size = session->security_parameters.session_id_size;
/* just return the session size */
if (session_id == NULL)
{
return 0;
}
if (given_session_id_size < session->security_parameters.session_id_size)
{
return GNUTLS_E_SHORT_MEMORY_BUFFER;
}
memcpy (session_id, &session->security_parameters.session_id,
*session_id_size);
return 0;
}
|
DoS Overflow
| 0
|
gnutls_session_get_id (gnutls_session_t session,
void *session_id, size_t * session_id_size)
{
size_t given_session_id_size = *session_id_size;
*session_id_size = session->security_parameters.session_id_size;
/* just return the session size */
if (session_id == NULL)
{
return 0;
}
if (given_session_id_size < session->security_parameters.session_id_size)
{
return GNUTLS_E_SHORT_MEMORY_BUFFER;
}
memcpy (session_id, &session->security_parameters.session_id,
*session_id_size);
return 0;
}
|
@@ -63,13 +63,13 @@ gnutls_session_get_data (gnutls_session_t session,
gnutls_assert ();
return ret;
}
- *session_data_size = psession.size;
if (psession.size > *session_data_size)
{
ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
goto error;
}
+ *session_data_size = psession.size;
if (session_data != NULL)
memcpy (session_data, psession.data, psession.size);
|
CWE-119
| null | null |
126
|
gnutls_session_set_data (gnutls_session_t session,
const void *session_data, size_t session_data_size)
{
int ret;
gnutls_datum_t psession;
psession.data = (opaque *) session_data;
psession.size = session_data_size;
if (session_data == NULL || session_data_size == 0)
{
gnutls_assert ();
return GNUTLS_E_INVALID_REQUEST;
}
ret = _gnutls_session_unpack (session, &psession);
if (ret < 0)
{
gnutls_assert ();
return ret;
}
return 0;
}
|
DoS Overflow
| 0
|
gnutls_session_set_data (gnutls_session_t session,
const void *session_data, size_t session_data_size)
{
int ret;
gnutls_datum_t psession;
psession.data = (opaque *) session_data;
psession.size = session_data_size;
if (session_data == NULL || session_data_size == 0)
{
gnutls_assert ();
return GNUTLS_E_INVALID_REQUEST;
}
ret = _gnutls_session_unpack (session, &psession);
if (ret < 0)
{
gnutls_assert ();
return ret;
}
return 0;
}
|
@@ -63,13 +63,13 @@ gnutls_session_get_data (gnutls_session_t session,
gnutls_assert ();
return ret;
}
- *session_data_size = psession.size;
if (psession.size > *session_data_size)
{
ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
goto error;
}
+ *session_data_size = psession.size;
if (session_data != NULL)
memcpy (session_data, psession.data, psession.size);
|
CWE-119
| null | null |
127
|
static int phar_compare_dir_name(const void *a, const void *b TSRMLS_DC) /* {{{ */
{
Bucket *f;
Bucket *s;
int result;
f = *((Bucket **) a);
s = *((Bucket **) b);
result = zend_binary_strcmp(f->arKey, f->nKeyLength, s->arKey, s->nKeyLength);
if (result < 0) {
return -1;
} else if (result > 0) {
return 1;
} else {
return 0;
}
}
/* }}} */
|
DoS
| 0
|
static int phar_compare_dir_name(const void *a, const void *b TSRMLS_DC) /* {{{ */
{
Bucket *f;
Bucket *s;
int result;
f = *((Bucket **) a);
s = *((Bucket **) b);
result = zend_binary_strcmp(f->arKey, f->nKeyLength, s->arKey, s->nKeyLength);
if (result < 0) {
return -1;
} else if (result > 0) {
return 1;
} else {
return 0;
}
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
128
|
static int phar_dir_close(php_stream *stream, int close_handle TSRMLS_DC) /* {{{ */
{
HashTable *data = (HashTable *)stream->abstract;
if (data && data->arBuckets) {
zend_hash_destroy(data);
data->arBuckets = 0;
FREE_HASHTABLE(data);
stream->abstract = NULL;
}
return 0;
}
/* }}} */
|
DoS
| 0
|
static int phar_dir_close(php_stream *stream, int close_handle TSRMLS_DC) /* {{{ */
{
HashTable *data = (HashTable *)stream->abstract;
if (data && data->arBuckets) {
zend_hash_destroy(data);
data->arBuckets = 0;
FREE_HASHTABLE(data);
stream->abstract = NULL;
}
return 0;
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
129
|
static int phar_dir_flush(php_stream *stream TSRMLS_DC) /* {{{ */
{
return EOF;
}
/* }}} */
|
DoS
| 0
|
static int phar_dir_flush(php_stream *stream TSRMLS_DC) /* {{{ */
{
return EOF;
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
130
|
static size_t phar_dir_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) /* {{{ */
{
size_t to_read;
HashTable *data = (HashTable *)stream->abstract;
phar_zstr key;
char *str_key;
uint keylen;
ulong unused;
if (FAILURE == zend_hash_has_more_elements(data)) {
return 0;
}
if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(data, &key, &keylen, &unused, 0, NULL)) {
return 0;
}
PHAR_STR(key, str_key);
zend_hash_move_forward(data);
to_read = MIN(keylen, count);
if (to_read == 0 || count < keylen) {
PHAR_STR_FREE(str_key);
return 0;
}
memset(buf, 0, sizeof(php_stream_dirent));
memcpy(((php_stream_dirent *) buf)->d_name, str_key, to_read);
PHAR_STR_FREE(str_key);
((php_stream_dirent *) buf)->d_name[to_read + 1] = '\0';
return sizeof(php_stream_dirent);
}
/* }}} */
|
DoS
| 0
|
static size_t phar_dir_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) /* {{{ */
{
size_t to_read;
HashTable *data = (HashTable *)stream->abstract;
phar_zstr key;
char *str_key;
uint keylen;
ulong unused;
if (FAILURE == zend_hash_has_more_elements(data)) {
return 0;
}
if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(data, &key, &keylen, &unused, 0, NULL)) {
return 0;
}
PHAR_STR(key, str_key);
zend_hash_move_forward(data);
to_read = MIN(keylen, count);
if (to_read == 0 || count < keylen) {
PHAR_STR_FREE(str_key);
return 0;
}
memset(buf, 0, sizeof(php_stream_dirent));
memcpy(((php_stream_dirent *) buf)->d_name, str_key, to_read);
PHAR_STR_FREE(str_key);
((php_stream_dirent *) buf)->d_name[to_read + 1] = '\0';
return sizeof(php_stream_dirent);
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
131
|
static int phar_dir_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) /* {{{ */
{
HashTable *data = (HashTable *)stream->abstract;
if (!data) {
return -1;
}
if (whence == SEEK_END) {
whence = SEEK_SET;
offset = zend_hash_num_elements(data) + offset;
}
if (whence == SEEK_SET) {
zend_hash_internal_pointer_reset(data);
}
if (offset < 0) {
return -1;
} else {
*newoffset = 0;
while (*newoffset < offset && zend_hash_move_forward(data) == SUCCESS) {
++(*newoffset);
}
return 0;
}
}
/* }}} */
|
DoS
| 0
|
static int phar_dir_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) /* {{{ */
{
HashTable *data = (HashTable *)stream->abstract;
if (!data) {
return -1;
}
if (whence == SEEK_END) {
whence = SEEK_SET;
offset = zend_hash_num_elements(data) + offset;
}
if (whence == SEEK_SET) {
zend_hash_internal_pointer_reset(data);
}
if (offset < 0) {
return -1;
} else {
*newoffset = 0;
while (*newoffset < offset && zend_hash_move_forward(data) == SUCCESS) {
++(*newoffset);
}
return 0;
}
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
132
|
static size_t phar_dir_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) /* {{{ */
{
return 0;
}
/* }}} */
|
DoS
| 0
|
static size_t phar_dir_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) /* {{{ */
{
return 0;
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
133
|
int phar_wrapper_mkdir(php_stream_wrapper *wrapper, char *url_from, int mode, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
{
phar_entry_info entry, *e;
phar_archive_data *phar = NULL;
char *error, *arch, *entry2;
int arch_len, entry_len;
php_url *resource = NULL;
uint host_len;
/* pre-readonly check, we need to know if this is a data phar */
if (FAILURE == phar_split_fname(url_from, strlen(url_from), &arch, &arch_len, &entry2, &entry_len, 2, 2 TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\", no phar archive specified", url_from);
return 0;
}
if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) {
phar = NULL;
}
efree(arch);
efree(entry2);
if (PHAR_G(readonly) && (!phar || !phar->is_data)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\", write operations disabled", url_from);
return 0;
}
if ((resource = phar_parse_url(wrapper, url_from, "w", options TSRMLS_CC)) == NULL) {
return 0;
}
/* we must have at the very least phar://alias.phar/internalfile.php */
if (!resource->scheme || !resource->host || !resource->path) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\"", url_from);
return 0;
}
if (strcasecmp("phar", resource->scheme)) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar stream url \"%s\"", url_from);
return 0;
}
host_len = strlen(resource->host);
if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
if ((e = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 2, &error, 1 TSRMLS_CC))) {
/* directory exists, or is a subdirectory of an existing file */
if (e->is_temp_dir) {
efree(e->filename);
efree(e);
}
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", directory already exists", resource->path+1, resource->host);
php_url_free(resource);
return 0;
}
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
if (phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 0, &error, 1 TSRMLS_CC)) {
/* entry exists as a file */
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", file already exists", resource->path+1, resource->host);
php_url_free(resource);
return 0;
}
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
memset((void *) &entry, 0, sizeof(phar_entry_info));
/* strip leading "/" */
if (phar->is_zip) {
entry.is_zip = 1;
}
entry.filename = estrdup(resource->path + 1);
if (phar->is_tar) {
entry.is_tar = 1;
entry.tar_type = TAR_DIR;
}
entry.filename_len = strlen(resource->path + 1);
php_url_free(resource);
entry.is_dir = 1;
entry.phar = phar;
entry.is_modified = 1;
entry.is_crc_checked = 1;
entry.flags = PHAR_ENT_PERM_DEF_DIR;
entry.old_flags = PHAR_ENT_PERM_DEF_DIR;
if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", adding to manifest failed", entry.filename, phar->fname);
efree(error);
efree(entry.filename);
return 0;
}
phar_flush(phar, 0, 0, 0, &error TSRMLS_CC);
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", entry.filename, phar->fname, error);
zend_hash_del(&phar->manifest, entry.filename, entry.filename_len);
efree(error);
return 0;
}
phar_add_virtual_dirs(phar, entry.filename, entry.filename_len TSRMLS_CC);
return 1;
}
/* }}} */
|
DoS
| 0
|
int phar_wrapper_mkdir(php_stream_wrapper *wrapper, char *url_from, int mode, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
{
phar_entry_info entry, *e;
phar_archive_data *phar = NULL;
char *error, *arch, *entry2;
int arch_len, entry_len;
php_url *resource = NULL;
uint host_len;
/* pre-readonly check, we need to know if this is a data phar */
if (FAILURE == phar_split_fname(url_from, strlen(url_from), &arch, &arch_len, &entry2, &entry_len, 2, 2 TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\", no phar archive specified", url_from);
return 0;
}
if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) {
phar = NULL;
}
efree(arch);
efree(entry2);
if (PHAR_G(readonly) && (!phar || !phar->is_data)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\", write operations disabled", url_from);
return 0;
}
if ((resource = phar_parse_url(wrapper, url_from, "w", options TSRMLS_CC)) == NULL) {
return 0;
}
/* we must have at the very least phar://alias.phar/internalfile.php */
if (!resource->scheme || !resource->host || !resource->path) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\"", url_from);
return 0;
}
if (strcasecmp("phar", resource->scheme)) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar stream url \"%s\"", url_from);
return 0;
}
host_len = strlen(resource->host);
if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
if ((e = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 2, &error, 1 TSRMLS_CC))) {
/* directory exists, or is a subdirectory of an existing file */
if (e->is_temp_dir) {
efree(e->filename);
efree(e);
}
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", directory already exists", resource->path+1, resource->host);
php_url_free(resource);
return 0;
}
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
if (phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 0, &error, 1 TSRMLS_CC)) {
/* entry exists as a file */
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", file already exists", resource->path+1, resource->host);
php_url_free(resource);
return 0;
}
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
memset((void *) &entry, 0, sizeof(phar_entry_info));
/* strip leading "/" */
if (phar->is_zip) {
entry.is_zip = 1;
}
entry.filename = estrdup(resource->path + 1);
if (phar->is_tar) {
entry.is_tar = 1;
entry.tar_type = TAR_DIR;
}
entry.filename_len = strlen(resource->path + 1);
php_url_free(resource);
entry.is_dir = 1;
entry.phar = phar;
entry.is_modified = 1;
entry.is_crc_checked = 1;
entry.flags = PHAR_ENT_PERM_DEF_DIR;
entry.old_flags = PHAR_ENT_PERM_DEF_DIR;
if (SUCCESS != zend_hash_add(&phar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", adding to manifest failed", entry.filename, phar->fname);
efree(error);
efree(entry.filename);
return 0;
}
phar_flush(phar, 0, 0, 0, &error TSRMLS_CC);
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", entry.filename, phar->fname, error);
zend_hash_del(&phar->manifest, entry.filename, entry.filename_len);
efree(error);
return 0;
}
phar_add_virtual_dirs(phar, entry.filename, entry.filename_len TSRMLS_CC);
return 1;
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
134
|
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
{
php_url *resource = NULL;
php_stream *ret;
char *internal_file, *error, *str_key;
phar_zstr key;
uint keylen;
ulong unused;
phar_archive_data *phar;
phar_entry_info *entry = NULL;
uint host_len;
if ((resource = phar_parse_url(wrapper, path, mode, options TSRMLS_CC)) == NULL) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar url \"%s\" is unknown", path);
return NULL;
}
/* we must have at the very least phar://alias.phar/ */
if (!resource->scheme || !resource->host || !resource->path) {
if (resource->host && !resource->path) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, resource->host);
php_url_free(resource);
return NULL;
}
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\", must have at least phar://%s/", path, path);
return NULL;
}
if (strcasecmp("phar", resource->scheme)) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar url \"%s\"", path);
return NULL;
}
host_len = strlen(resource->host);
phar_request_initialize(TSRMLS_C);
internal_file = resource->path + 1; /* strip leading "/" */
if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error TSRMLS_CC)) {
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", error);
efree(error);
} else {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar file \"%s\" is unknown", resource->host);
}
php_url_free(resource);
return NULL;
}
if (error) {
efree(error);
}
if (*internal_file == '\0') {
/* root directory requested */
internal_file = estrndup(internal_file - 1, 1);
ret = phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
php_url_free(resource);
return ret;
}
if (!phar->manifest.arBuckets) {
php_url_free(resource);
return NULL;
}
if (SUCCESS == zend_hash_find(&phar->manifest, internal_file, strlen(internal_file), (void**)&entry) && !entry->is_dir) {
php_url_free(resource);
return NULL;
} else if (entry && entry->is_dir) {
if (entry->is_mounted) {
php_url_free(resource);
return php_stream_opendir(entry->tmp, options, context);
}
internal_file = estrdup(internal_file);
php_url_free(resource);
return phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
} else {
int i_len = strlen(internal_file);
/* search for directory */
zend_hash_internal_pointer_reset(&phar->manifest);
while (FAILURE != zend_hash_has_more_elements(&phar->manifest)) {
if (HASH_KEY_NON_EXISTENT !=
zend_hash_get_current_key_ex(
&phar->manifest, &key, &keylen, &unused, 0, NULL)) {
PHAR_STR(key, str_key);
if (keylen > (uint)i_len && 0 == memcmp(str_key, internal_file, i_len)) {
PHAR_STR_FREE(str_key);
/* directory found */
internal_file = estrndup(internal_file,
i_len);
php_url_free(resource);
return phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
}
PHAR_STR_FREE(str_key);
}
if (SUCCESS != zend_hash_move_forward(&phar->manifest)) {
break;
}
}
}
php_url_free(resource);
return NULL;
}
/* }}} */
|
DoS
| 0
|
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
{
php_url *resource = NULL;
php_stream *ret;
char *internal_file, *error, *str_key;
phar_zstr key;
uint keylen;
ulong unused;
phar_archive_data *phar;
phar_entry_info *entry = NULL;
uint host_len;
if ((resource = phar_parse_url(wrapper, path, mode, options TSRMLS_CC)) == NULL) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar url \"%s\" is unknown", path);
return NULL;
}
/* we must have at the very least phar://alias.phar/ */
if (!resource->scheme || !resource->host || !resource->path) {
if (resource->host && !resource->path) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, resource->host);
php_url_free(resource);
return NULL;
}
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\", must have at least phar://%s/", path, path);
return NULL;
}
if (strcasecmp("phar", resource->scheme)) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar url \"%s\"", path);
return NULL;
}
host_len = strlen(resource->host);
phar_request_initialize(TSRMLS_C);
internal_file = resource->path + 1; /* strip leading "/" */
if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error TSRMLS_CC)) {
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", error);
efree(error);
} else {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar file \"%s\" is unknown", resource->host);
}
php_url_free(resource);
return NULL;
}
if (error) {
efree(error);
}
if (*internal_file == '\0') {
/* root directory requested */
internal_file = estrndup(internal_file - 1, 1);
ret = phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
php_url_free(resource);
return ret;
}
if (!phar->manifest.arBuckets) {
php_url_free(resource);
return NULL;
}
if (SUCCESS == zend_hash_find(&phar->manifest, internal_file, strlen(internal_file), (void**)&entry) && !entry->is_dir) {
php_url_free(resource);
return NULL;
} else if (entry && entry->is_dir) {
if (entry->is_mounted) {
php_url_free(resource);
return php_stream_opendir(entry->tmp, options, context);
}
internal_file = estrdup(internal_file);
php_url_free(resource);
return phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
} else {
int i_len = strlen(internal_file);
/* search for directory */
zend_hash_internal_pointer_reset(&phar->manifest);
while (FAILURE != zend_hash_has_more_elements(&phar->manifest)) {
if (HASH_KEY_NON_EXISTENT !=
zend_hash_get_current_key_ex(
&phar->manifest, &key, &keylen, &unused, 0, NULL)) {
PHAR_STR(key, str_key);
if (keylen > (uint)i_len && 0 == memcmp(str_key, internal_file, i_len)) {
PHAR_STR_FREE(str_key);
/* directory found */
internal_file = estrndup(internal_file,
i_len);
php_url_free(resource);
return phar_make_dirstream(internal_file, &phar->manifest TSRMLS_CC);
}
PHAR_STR_FREE(str_key);
}
if (SUCCESS != zend_hash_move_forward(&phar->manifest)) {
break;
}
}
}
php_url_free(resource);
return NULL;
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
135
|
int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
{
phar_entry_info *entry;
phar_archive_data *phar = NULL;
char *error, *arch, *entry2;
int arch_len, entry_len;
php_url *resource = NULL;
uint host_len;
phar_zstr key;
char *str_key;
uint key_len;
ulong unused;
uint path_len;
/* pre-readonly check, we need to know if this is a data phar */
if (FAILURE == phar_split_fname(url, strlen(url), &arch, &arch_len, &entry2, &entry_len, 2, 2 TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\", no phar archive specified, or phar archive does not exist", url);
return 0;
}
if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) {
phar = NULL;
}
efree(arch);
efree(entry2);
if (PHAR_G(readonly) && (!phar || !phar->is_data)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot rmdir directory \"%s\", write operations disabled", url);
return 0;
}
if ((resource = phar_parse_url(wrapper, url, "w", options TSRMLS_CC)) == NULL) {
return 0;
}
/* we must have at the very least phar://alias.phar/internalfile.php */
if (!resource->scheme || !resource->host || !resource->path) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\"", url);
return 0;
}
if (strcasecmp("phar", resource->scheme)) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar stream url \"%s\"", url);
return 0;
}
host_len = strlen(resource->host);
if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
path_len = strlen(resource->path+1);
if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, path_len, 2, &error, 1 TSRMLS_CC))) {
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error);
efree(error);
} else {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", directory does not exist", resource->path+1, resource->host);
}
php_url_free(resource);
return 0;
}
if (!entry->is_deleted) {
for (zend_hash_internal_pointer_reset(&phar->manifest);
HASH_KEY_NON_EXISTENT != zend_hash_get_current_key_ex(&phar->manifest, &key, &key_len, &unused, 0, NULL);
zend_hash_move_forward(&phar->manifest)) {
PHAR_STR(key, str_key);
if (key_len > path_len &&
memcmp(str_key, resource->path+1, path_len) == 0 &&
IS_SLASH(str_key[path_len])) {
PHAR_STR_FREE(str_key);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: Directory not empty");
if (entry->is_temp_dir) {
efree(entry->filename);
efree(entry);
}
php_url_free(resource);
return 0;
}
PHAR_STR_FREE(str_key);
}
for (zend_hash_internal_pointer_reset(&phar->virtual_dirs);
HASH_KEY_NON_EXISTENT != zend_hash_get_current_key_ex(&phar->virtual_dirs, &key, &key_len, &unused, 0, NULL);
zend_hash_move_forward(&phar->virtual_dirs)) {
PHAR_STR(key, str_key);
if (key_len > path_len &&
memcmp(str_key, resource->path+1, path_len) == 0 &&
IS_SLASH(str_key[path_len])) {
PHAR_STR_FREE(str_key);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: Directory not empty");
if (entry->is_temp_dir) {
efree(entry->filename);
efree(entry);
}
php_url_free(resource);
return 0;
}
PHAR_STR_FREE(str_key);
}
}
if (entry->is_temp_dir) {
zend_hash_del(&phar->virtual_dirs, resource->path+1, path_len);
efree(entry->filename);
efree(entry);
} else {
entry->is_deleted = 1;
entry->is_modified = 1;
phar_flush(phar, 0, 0, 0, &error TSRMLS_CC);
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", entry->filename, phar->fname, error);
php_url_free(resource);
efree(error);
return 0;
}
}
php_url_free(resource);
return 1;
}
/* }}} */
|
DoS
| 0
|
int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) /* {{{ */
{
phar_entry_info *entry;
phar_archive_data *phar = NULL;
char *error, *arch, *entry2;
int arch_len, entry_len;
php_url *resource = NULL;
uint host_len;
phar_zstr key;
char *str_key;
uint key_len;
ulong unused;
uint path_len;
/* pre-readonly check, we need to know if this is a data phar */
if (FAILURE == phar_split_fname(url, strlen(url), &arch, &arch_len, &entry2, &entry_len, 2, 2 TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\", no phar archive specified, or phar archive does not exist", url);
return 0;
}
if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL TSRMLS_CC)) {
phar = NULL;
}
efree(arch);
efree(entry2);
if (PHAR_G(readonly) && (!phar || !phar->is_data)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot rmdir directory \"%s\", write operations disabled", url);
return 0;
}
if ((resource = phar_parse_url(wrapper, url, "w", options TSRMLS_CC)) == NULL) {
return 0;
}
/* we must have at the very least phar://alias.phar/internalfile.php */
if (!resource->scheme || !resource->host || !resource->path) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: invalid url \"%s\"", url);
return 0;
}
if (strcasecmp("phar", resource->scheme)) {
php_url_free(resource);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: not a phar stream url \"%s\"", url);
return 0;
}
host_len = strlen(resource->host);
if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error TSRMLS_CC)) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error);
efree(error);
php_url_free(resource);
return 0;
}
path_len = strlen(resource->path+1);
if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, path_len, 2, &error, 1 TSRMLS_CC))) {
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error);
efree(error);
} else {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", directory does not exist", resource->path+1, resource->host);
}
php_url_free(resource);
return 0;
}
if (!entry->is_deleted) {
for (zend_hash_internal_pointer_reset(&phar->manifest);
HASH_KEY_NON_EXISTENT != zend_hash_get_current_key_ex(&phar->manifest, &key, &key_len, &unused, 0, NULL);
zend_hash_move_forward(&phar->manifest)) {
PHAR_STR(key, str_key);
if (key_len > path_len &&
memcmp(str_key, resource->path+1, path_len) == 0 &&
IS_SLASH(str_key[path_len])) {
PHAR_STR_FREE(str_key);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: Directory not empty");
if (entry->is_temp_dir) {
efree(entry->filename);
efree(entry);
}
php_url_free(resource);
return 0;
}
PHAR_STR_FREE(str_key);
}
for (zend_hash_internal_pointer_reset(&phar->virtual_dirs);
HASH_KEY_NON_EXISTENT != zend_hash_get_current_key_ex(&phar->virtual_dirs, &key, &key_len, &unused, 0, NULL);
zend_hash_move_forward(&phar->virtual_dirs)) {
PHAR_STR(key, str_key);
if (key_len > path_len &&
memcmp(str_key, resource->path+1, path_len) == 0 &&
IS_SLASH(str_key[path_len])) {
PHAR_STR_FREE(str_key);
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: Directory not empty");
if (entry->is_temp_dir) {
efree(entry->filename);
efree(entry);
}
php_url_free(resource);
return 0;
}
PHAR_STR_FREE(str_key);
}
}
if (entry->is_temp_dir) {
zend_hash_del(&phar->virtual_dirs, resource->path+1, path_len);
efree(entry->filename);
efree(entry);
} else {
entry->is_deleted = 1;
entry->is_modified = 1;
phar_flush(phar, 0, 0, 0, &error TSRMLS_CC);
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", entry->filename, phar->fname, error);
php_url_free(resource);
efree(error);
return 0;
}
}
php_url_free(resource);
return 1;
}
/* }}} */
|
@@ -207,7 +207,7 @@ static php_stream *phar_make_dirstream(char *dir, HashTable *manifest TSRMLS_DC)
zend_hash_internal_pointer_reset(manifest);
while (FAILURE != zend_hash_has_more_elements(manifest)) {
- if (HASH_KEY_IS_STRING != zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
break;
}
|
CWE-189
| null | null |
136
|
char * phar_compress_filter(phar_entry_info * entry, int return_unknown) /* {{{ */
{
switch (entry->flags & PHAR_ENT_COMPRESSION_MASK) {
case PHAR_ENT_COMPRESSED_GZ:
return "zlib.deflate";
case PHAR_ENT_COMPRESSED_BZ2:
return "bzip2.compress";
default:
return return_unknown ? "unknown" : NULL;
}
}
/* }}} */
|
DoS
| 0
|
char * phar_compress_filter(phar_entry_info * entry, int return_unknown) /* {{{ */
{
switch (entry->flags & PHAR_ENT_COMPRESSION_MASK) {
case PHAR_ENT_COMPRESSED_GZ:
return "zlib.deflate";
case PHAR_ENT_COMPRESSED_BZ2:
return "bzip2.compress";
default:
return return_unknown ? "unknown" : NULL;
}
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
137
|
static void phar_copy_cached_phar(phar_archive_data **pphar TSRMLS_DC) /* {{{ */
{
phar_archive_data *phar;
HashTable newmanifest;
char *fname;
phar_archive_object **objphar;
phar = (phar_archive_data *) emalloc(sizeof(phar_archive_data));
*phar = **pphar;
phar->is_persistent = 0;
fname = phar->fname;
phar->fname = estrndup(phar->fname, phar->fname_len);
phar->ext = phar->fname + (phar->ext - fname);
if (phar->alias) {
phar->alias = estrndup(phar->alias, phar->alias_len);
}
if (phar->signature) {
phar->signature = estrdup(phar->signature);
}
if (phar->metadata) {
/* assume success, we would have failed before */
if (phar->metadata_len) {
char *buf = estrndup((char *) phar->metadata, phar->metadata_len);
phar_parse_metadata(&buf, &phar->metadata, phar->metadata_len TSRMLS_CC);
efree(buf);
} else {
zval *t;
t = phar->metadata;
ALLOC_ZVAL(phar->metadata);
*phar->metadata = *t;
zval_copy_ctor(phar->metadata);
Z_SET_REFCOUNT_P(phar->metadata, 1);
}
}
zend_hash_init(&newmanifest, sizeof(phar_entry_info),
zend_get_hash_value, destroy_phar_manifest_entry, 0);
zend_hash_copy(&newmanifest, &(*pphar)->manifest, NULL, NULL, sizeof(phar_entry_info));
zend_hash_apply_with_argument(&newmanifest, (apply_func_arg_t) phar_update_cached_entry, (void *)phar TSRMLS_CC);
phar->manifest = newmanifest;
zend_hash_init(&phar->mounted_dirs, sizeof(char *),
zend_get_hash_value, NULL, 0);
zend_hash_init(&phar->virtual_dirs, sizeof(char *),
zend_get_hash_value, NULL, 0);
zend_hash_copy(&phar->virtual_dirs, &(*pphar)->virtual_dirs, NULL, NULL, sizeof(void *));
*pphar = phar;
/* now, scan the list of persistent Phar objects referencing this phar and update the pointers */
for (zend_hash_internal_pointer_reset(&PHAR_GLOBALS->phar_persist_map);
SUCCESS == zend_hash_get_current_data(&PHAR_GLOBALS->phar_persist_map, (void **) &objphar);
zend_hash_move_forward(&PHAR_GLOBALS->phar_persist_map)) {
if (objphar[0]->arc.archive->fname_len == phar->fname_len && !memcmp(objphar[0]->arc.archive->fname, phar->fname, phar->fname_len)) {
objphar[0]->arc.archive = phar;
}
}
}
/* }}} */
|
DoS
| 0
|
static void phar_copy_cached_phar(phar_archive_data **pphar TSRMLS_DC) /* {{{ */
{
phar_archive_data *phar;
HashTable newmanifest;
char *fname;
phar_archive_object **objphar;
phar = (phar_archive_data *) emalloc(sizeof(phar_archive_data));
*phar = **pphar;
phar->is_persistent = 0;
fname = phar->fname;
phar->fname = estrndup(phar->fname, phar->fname_len);
phar->ext = phar->fname + (phar->ext - fname);
if (phar->alias) {
phar->alias = estrndup(phar->alias, phar->alias_len);
}
if (phar->signature) {
phar->signature = estrdup(phar->signature);
}
if (phar->metadata) {
/* assume success, we would have failed before */
if (phar->metadata_len) {
char *buf = estrndup((char *) phar->metadata, phar->metadata_len);
phar_parse_metadata(&buf, &phar->metadata, phar->metadata_len TSRMLS_CC);
efree(buf);
} else {
zval *t;
t = phar->metadata;
ALLOC_ZVAL(phar->metadata);
*phar->metadata = *t;
zval_copy_ctor(phar->metadata);
Z_SET_REFCOUNT_P(phar->metadata, 1);
}
}
zend_hash_init(&newmanifest, sizeof(phar_entry_info),
zend_get_hash_value, destroy_phar_manifest_entry, 0);
zend_hash_copy(&newmanifest, &(*pphar)->manifest, NULL, NULL, sizeof(phar_entry_info));
zend_hash_apply_with_argument(&newmanifest, (apply_func_arg_t) phar_update_cached_entry, (void *)phar TSRMLS_CC);
phar->manifest = newmanifest;
zend_hash_init(&phar->mounted_dirs, sizeof(char *),
zend_get_hash_value, NULL, 0);
zend_hash_init(&phar->virtual_dirs, sizeof(char *),
zend_get_hash_value, NULL, 0);
zend_hash_copy(&phar->virtual_dirs, &(*pphar)->virtual_dirs, NULL, NULL, sizeof(void *));
*pphar = phar;
/* now, scan the list of persistent Phar objects referencing this phar and update the pointers */
for (zend_hash_internal_pointer_reset(&PHAR_GLOBALS->phar_persist_map);
SUCCESS == zend_hash_get_current_data(&PHAR_GLOBALS->phar_persist_map, (void **) &objphar);
zend_hash_move_forward(&PHAR_GLOBALS->phar_persist_map)) {
if (objphar[0]->arc.archive->fname_len == phar->fname_len && !memcmp(objphar[0]->arc.archive->fname, phar->fname, phar->fname_len)) {
objphar[0]->arc.archive = phar;
}
}
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
138
|
int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error TSRMLS_DC) /* {{{ */
{
phar_entry_info *link;
if (FAILURE == phar_open_entry_fp(source, error, 1 TSRMLS_CC)) {
return FAILURE;
}
if (dest->link) {
efree(dest->link);
dest->link = NULL;
dest->tar_type = (dest->is_tar ? TAR_FILE : '\0');
}
dest->fp_type = PHAR_MOD;
dest->offset = 0;
dest->is_modified = 1;
dest->fp = php_stream_fopen_tmpfile();
if (dest->fp == NULL) {
spprintf(error, 0, "phar error: unable to create temporary file");
return EOF;
}
phar_seek_efp(source, 0, SEEK_SET, 0, 1 TSRMLS_CC);
link = phar_get_link_source(source TSRMLS_CC);
if (!link) {
link = source;
}
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), dest->fp, link->uncompressed_filesize, NULL)) {
php_stream_close(dest->fp);
dest->fp_type = PHAR_FP;
if (error) {
spprintf(error, 4096, "phar error: unable to copy contents of file \"%s\" to \"%s\" in phar archive \"%s\"", source->filename, dest->filename, source->phar->fname);
}
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
DoS
| 0
|
int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **error TSRMLS_DC) /* {{{ */
{
phar_entry_info *link;
if (FAILURE == phar_open_entry_fp(source, error, 1 TSRMLS_CC)) {
return FAILURE;
}
if (dest->link) {
efree(dest->link);
dest->link = NULL;
dest->tar_type = (dest->is_tar ? TAR_FILE : '\0');
}
dest->fp_type = PHAR_MOD;
dest->offset = 0;
dest->is_modified = 1;
dest->fp = php_stream_fopen_tmpfile();
if (dest->fp == NULL) {
spprintf(error, 0, "phar error: unable to create temporary file");
return EOF;
}
phar_seek_efp(source, 0, SEEK_SET, 0, 1 TSRMLS_CC);
link = phar_get_link_source(source TSRMLS_CC);
if (!link) {
link = source;
}
if (SUCCESS != phar_stream_copy_to_stream(phar_get_efp(link, 0 TSRMLS_CC), dest->fp, link->uncompressed_filesize, NULL)) {
php_stream_close(dest->fp);
dest->fp_type = PHAR_FP;
if (error) {
spprintf(error, 4096, "phar error: unable to copy contents of file \"%s\" to \"%s\" in phar archive \"%s\"", source->filename, dest->filename, source->phar->fname);
}
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
139
|
int phar_copy_on_write(phar_archive_data **pphar TSRMLS_DC) /* {{{ */
{
phar_archive_data **newpphar, *newphar = NULL;
if (SUCCESS != zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), (*pphar)->fname, (*pphar)->fname_len, (void *)&newphar, sizeof(phar_archive_data *), (void **)&newpphar)) {
return FAILURE;
}
*newpphar = *pphar;
phar_copy_cached_phar(newpphar TSRMLS_CC);
/* invalidate phar cache */
PHAR_G(last_phar) = NULL;
PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL;
if (newpphar[0]->alias_len && FAILURE == zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), newpphar[0]->alias, newpphar[0]->alias_len, (void*)newpphar, sizeof(phar_archive_data*), NULL)) {
zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), (*pphar)->fname, (*pphar)->fname_len);
return FAILURE;
}
*pphar = *newpphar;
return SUCCESS;
}
/* }}} */
|
DoS
| 0
|
int phar_copy_on_write(phar_archive_data **pphar TSRMLS_DC) /* {{{ */
{
phar_archive_data **newpphar, *newphar = NULL;
if (SUCCESS != zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), (*pphar)->fname, (*pphar)->fname_len, (void *)&newphar, sizeof(phar_archive_data *), (void **)&newpphar)) {
return FAILURE;
}
*newpphar = *pphar;
phar_copy_cached_phar(newpphar TSRMLS_CC);
/* invalidate phar cache */
PHAR_G(last_phar) = NULL;
PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL;
if (newpphar[0]->alias_len && FAILURE == zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), newpphar[0]->alias, newpphar[0]->alias_len, (void*)newpphar, sizeof(phar_archive_data*), NULL)) {
zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), (*pphar)->fname, (*pphar)->fname_len);
return FAILURE;
}
*pphar = *newpphar;
return SUCCESS;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
140
|
int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error TSRMLS_DC) /* {{{ */
{
unsigned char buf[1024];
int sig_len;
php_stream_rewind(fp);
if (phar->signature) {
efree(phar->signature);
phar->signature = NULL;
}
switch(phar->sig_flags) {
#ifdef PHAR_HASH_OK
case PHAR_SIG_SHA512: {
unsigned char digest[64];
PHP_SHA512_CTX context;
PHP_SHA512Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_SHA512Update(&context, buf, sig_len);
}
PHP_SHA512Final(digest, &context);
*signature = estrndup((char *) digest, 64);
*signature_length = 64;
break;
}
case PHAR_SIG_SHA256: {
unsigned char digest[32];
PHP_SHA256_CTX context;
PHP_SHA256Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_SHA256Update(&context, buf, sig_len);
}
PHP_SHA256Final(digest, &context);
*signature = estrndup((char *) digest, 32);
*signature_length = 32;
break;
}
#else
case PHAR_SIG_SHA512:
case PHAR_SIG_SHA256:
if (error) {
spprintf(error, 0, "unable to write to phar \"%s\" with requested hash type", phar->fname);
}
return FAILURE;
#endif
case PHAR_SIG_OPENSSL: {
int siglen;
unsigned char *sigbuf;
#ifdef PHAR_HAVE_OPENSSL
BIO *in;
EVP_PKEY *key;
EVP_MD_CTX *md_ctx;
in = BIO_new_mem_buf(PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len));
if (in == NULL) {
if (error) {
spprintf(error, 0, "unable to write to phar \"%s\" with requested openssl signature", phar->fname);
}
return FAILURE;
}
key = PEM_read_bio_PrivateKey(in, NULL,NULL, "");
BIO_free(in);
if (!key) {
if (error) {
spprintf(error, 0, "unable to process private key");
}
return FAILURE;
}
md_ctx = EVP_MD_CTX_create();
siglen = EVP_PKEY_size(key);
sigbuf = emalloc(siglen + 1);
if (!EVP_SignInit(md_ctx, EVP_sha1())) {
efree(sigbuf);
if (error) {
spprintf(error, 0, "unable to initialize openssl signature for phar \"%s\"", phar->fname);
}
return FAILURE;
}
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
if (!EVP_SignUpdate(md_ctx, buf, sig_len)) {
efree(sigbuf);
if (error) {
spprintf(error, 0, "unable to update the openssl signature for phar \"%s\"", phar->fname);
}
return FAILURE;
}
}
if (!EVP_SignFinal (md_ctx, sigbuf,(unsigned int *)&siglen, key)) {
efree(sigbuf);
if (error) {
spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", phar->fname);
}
return FAILURE;
}
sigbuf[siglen] = '\0';
EVP_MD_CTX_destroy(md_ctx);
#else
sigbuf = NULL;
siglen = 0;
php_stream_seek(fp, 0, SEEK_END);
if (FAILURE == phar_call_openssl_signverify(1, fp, php_stream_tell(fp), PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len), (char **)&sigbuf, &siglen TSRMLS_CC)) {
if (error) {
spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", phar->fname);
}
return FAILURE;
}
#endif
*signature = (char *) sigbuf;
*signature_length = siglen;
}
break;
default:
phar->sig_flags = PHAR_SIG_SHA1;
case PHAR_SIG_SHA1: {
unsigned char digest[20];
PHP_SHA1_CTX context;
PHP_SHA1Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_SHA1Update(&context, buf, sig_len);
}
PHP_SHA1Final(digest, &context);
*signature = estrndup((char *) digest, 20);
*signature_length = 20;
break;
}
case PHAR_SIG_MD5: {
unsigned char digest[16];
PHP_MD5_CTX context;
PHP_MD5Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_MD5Update(&context, buf, sig_len);
}
PHP_MD5Final(digest, &context);
*signature = estrndup((char *) digest, 16);
*signature_length = 16;
break;
}
}
phar->sig_len = phar_hex_str((const char *)*signature, *signature_length, &phar->signature TSRMLS_CC);
return SUCCESS;
}
/* }}} */
|
DoS
| 0
|
int phar_create_signature(phar_archive_data *phar, php_stream *fp, char **signature, int *signature_length, char **error TSRMLS_DC) /* {{{ */
{
unsigned char buf[1024];
int sig_len;
php_stream_rewind(fp);
if (phar->signature) {
efree(phar->signature);
phar->signature = NULL;
}
switch(phar->sig_flags) {
#ifdef PHAR_HASH_OK
case PHAR_SIG_SHA512: {
unsigned char digest[64];
PHP_SHA512_CTX context;
PHP_SHA512Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_SHA512Update(&context, buf, sig_len);
}
PHP_SHA512Final(digest, &context);
*signature = estrndup((char *) digest, 64);
*signature_length = 64;
break;
}
case PHAR_SIG_SHA256: {
unsigned char digest[32];
PHP_SHA256_CTX context;
PHP_SHA256Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_SHA256Update(&context, buf, sig_len);
}
PHP_SHA256Final(digest, &context);
*signature = estrndup((char *) digest, 32);
*signature_length = 32;
break;
}
#else
case PHAR_SIG_SHA512:
case PHAR_SIG_SHA256:
if (error) {
spprintf(error, 0, "unable to write to phar \"%s\" with requested hash type", phar->fname);
}
return FAILURE;
#endif
case PHAR_SIG_OPENSSL: {
int siglen;
unsigned char *sigbuf;
#ifdef PHAR_HAVE_OPENSSL
BIO *in;
EVP_PKEY *key;
EVP_MD_CTX *md_ctx;
in = BIO_new_mem_buf(PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len));
if (in == NULL) {
if (error) {
spprintf(error, 0, "unable to write to phar \"%s\" with requested openssl signature", phar->fname);
}
return FAILURE;
}
key = PEM_read_bio_PrivateKey(in, NULL,NULL, "");
BIO_free(in);
if (!key) {
if (error) {
spprintf(error, 0, "unable to process private key");
}
return FAILURE;
}
md_ctx = EVP_MD_CTX_create();
siglen = EVP_PKEY_size(key);
sigbuf = emalloc(siglen + 1);
if (!EVP_SignInit(md_ctx, EVP_sha1())) {
efree(sigbuf);
if (error) {
spprintf(error, 0, "unable to initialize openssl signature for phar \"%s\"", phar->fname);
}
return FAILURE;
}
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
if (!EVP_SignUpdate(md_ctx, buf, sig_len)) {
efree(sigbuf);
if (error) {
spprintf(error, 0, "unable to update the openssl signature for phar \"%s\"", phar->fname);
}
return FAILURE;
}
}
if (!EVP_SignFinal (md_ctx, sigbuf,(unsigned int *)&siglen, key)) {
efree(sigbuf);
if (error) {
spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", phar->fname);
}
return FAILURE;
}
sigbuf[siglen] = '\0';
EVP_MD_CTX_destroy(md_ctx);
#else
sigbuf = NULL;
siglen = 0;
php_stream_seek(fp, 0, SEEK_END);
if (FAILURE == phar_call_openssl_signverify(1, fp, php_stream_tell(fp), PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len), (char **)&sigbuf, &siglen TSRMLS_CC)) {
if (error) {
spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", phar->fname);
}
return FAILURE;
}
#endif
*signature = (char *) sigbuf;
*signature_length = siglen;
}
break;
default:
phar->sig_flags = PHAR_SIG_SHA1;
case PHAR_SIG_SHA1: {
unsigned char digest[20];
PHP_SHA1_CTX context;
PHP_SHA1Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_SHA1Update(&context, buf, sig_len);
}
PHP_SHA1Final(digest, &context);
*signature = estrndup((char *) digest, 20);
*signature_length = 20;
break;
}
case PHAR_SIG_MD5: {
unsigned char digest[16];
PHP_MD5_CTX context;
PHP_MD5Init(&context);
while ((sig_len = php_stream_read(fp, (char*)buf, sizeof(buf))) > 0) {
PHP_MD5Update(&context, buf, sig_len);
}
PHP_MD5Final(digest, &context);
*signature = estrndup((char *) digest, 16);
*signature_length = 16;
break;
}
}
phar->sig_len = phar_hex_str((const char *)*signature, *signature_length, &phar->signature TSRMLS_CC);
return SUCCESS;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
141
|
int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */
{
if (entry->fp_type == PHAR_MOD) {
/* already newly created, truncate */
php_stream_truncate_set_size(entry->fp, 0);
entry->old_flags = entry->flags;
entry->is_modified = 1;
phar->is_modified = 1;
/* reset file size */
entry->uncompressed_filesize = 0;
entry->compressed_filesize = 0;
entry->crc32 = 0;
entry->flags = PHAR_ENT_PERM_DEF_FILE;
entry->fp_type = PHAR_MOD;
entry->offset = 0;
return SUCCESS;
}
if (error) {
*error = NULL;
}
/* open a new temp file for writing */
if (entry->link) {
efree(entry->link);
entry->link = NULL;
entry->tar_type = (entry->is_tar ? TAR_FILE : '\0');
}
entry->fp = php_stream_fopen_tmpfile();
if (!entry->fp) {
if (error) {
spprintf(error, 0, "phar error: unable to create temporary file");
}
return FAILURE;
}
entry->old_flags = entry->flags;
entry->is_modified = 1;
phar->is_modified = 1;
/* reset file size */
entry->uncompressed_filesize = 0;
entry->compressed_filesize = 0;
entry->crc32 = 0;
entry->flags = PHAR_ENT_PERM_DEF_FILE;
entry->fp_type = PHAR_MOD;
entry->offset = 0;
return SUCCESS;
}
/* }}} */
|
DoS
| 0
|
int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */
{
if (entry->fp_type == PHAR_MOD) {
/* already newly created, truncate */
php_stream_truncate_set_size(entry->fp, 0);
entry->old_flags = entry->flags;
entry->is_modified = 1;
phar->is_modified = 1;
/* reset file size */
entry->uncompressed_filesize = 0;
entry->compressed_filesize = 0;
entry->crc32 = 0;
entry->flags = PHAR_ENT_PERM_DEF_FILE;
entry->fp_type = PHAR_MOD;
entry->offset = 0;
return SUCCESS;
}
if (error) {
*error = NULL;
}
/* open a new temp file for writing */
if (entry->link) {
efree(entry->link);
entry->link = NULL;
entry->tar_type = (entry->is_tar ? TAR_FILE : '\0');
}
entry->fp = php_stream_fopen_tmpfile();
if (!entry->fp) {
if (error) {
spprintf(error, 0, "phar error: unable to create temporary file");
}
return FAILURE;
}
entry->old_flags = entry->flags;
entry->is_modified = 1;
phar->is_modified = 1;
/* reset file size */
entry->uncompressed_filesize = 0;
entry->compressed_filesize = 0;
entry->crc32 = 0;
entry->flags = PHAR_ENT_PERM_DEF_FILE;
entry->fp_type = PHAR_MOD;
entry->offset = 0;
return SUCCESS;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
142
|
int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len TSRMLS_DC) /* {{{ */
{
if (phar->refcount || phar->is_persistent) {
return FAILURE;
}
/* this archive has no open references, so emit an E_STRICT and remove it */
if (zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), phar->fname, phar->fname_len) != SUCCESS) {
return FAILURE;
}
/* invalidate phar cache */
PHAR_G(last_phar) = NULL;
PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL;
return SUCCESS;
}
/* }}} */
|
DoS
| 0
|
int phar_free_alias(phar_archive_data *phar, char *alias, int alias_len TSRMLS_DC) /* {{{ */
{
if (phar->refcount || phar->is_persistent) {
return FAILURE;
}
/* this archive has no open references, so emit an E_STRICT and remove it */
if (zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), phar->fname, phar->fname_len) != SUCCESS) {
return FAILURE;
}
/* invalidate phar cache */
PHAR_G(last_phar) = NULL;
PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL;
return SUCCESS;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
143
|
int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error TSRMLS_DC) /* {{{ */
{
phar_archive_data *fd, **fd_ptr;
char *my_realpath, *save;
int save_len;
ulong fhash, ahash = 0;
phar_request_initialize(TSRMLS_C);
if (error) {
*error = NULL;
}
*archive = NULL;
if (PHAR_G(last_phar) && fname_len == PHAR_G(last_phar_name_len) && !memcmp(fname, PHAR_G(last_phar_name), fname_len)) {
*archive = PHAR_G(last_phar);
if (alias && alias_len) {
if (!PHAR_G(last_phar)->is_temporary_alias && (alias_len != PHAR_G(last_phar)->alias_len || memcmp(PHAR_G(last_phar)->alias, alias, alias_len))) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, PHAR_G(last_phar)->fname, fname);
}
*archive = NULL;
return FAILURE;
}
if (PHAR_G(last_phar)->alias_len && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len, (void**)&fd_ptr)) {
zend_hash_del(&(PHAR_GLOBALS->phar_alias_map), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len);
}
zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, (void*)&(*archive), sizeof(phar_archive_data*), NULL);
PHAR_G(last_alias) = alias;
PHAR_G(last_alias_len) = alias_len;
}
return SUCCESS;
}
if (alias && alias_len && PHAR_G(last_phar) && alias_len == PHAR_G(last_alias_len) && !memcmp(alias, PHAR_G(last_alias), alias_len)) {
fd = PHAR_G(last_phar);
fd_ptr = &fd;
goto alias_success;
}
if (alias && alias_len) {
ahash = zend_inline_hash_func(alias, alias_len);
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void**)&fd_ptr)) {
alias_success:
if (fname && (fname_len != (*fd_ptr)->fname_len || strncmp(fname, (*fd_ptr)->fname, fname_len))) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
}
if (SUCCESS == phar_free_alias(*fd_ptr, alias, alias_len TSRMLS_CC)) {
if (error) {
efree(*error);
*error = NULL;
}
}
return FAILURE;
}
*archive = *fd_ptr;
fd = *fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = alias;
PHAR_G(last_alias_len) = alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_alias, alias, alias_len, ahash, (void **)&fd_ptr)) {
goto alias_success;
}
}
fhash = zend_inline_hash_func(fname, fname_len);
my_realpath = NULL;
save = fname;
save_len = fname_len;
if (fname && fname_len) {
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, fhash, (void**)&fd_ptr)) {
*archive = *fd_ptr;
fd = *fd_ptr;
if (alias && alias_len) {
if (!fd->is_temporary_alias && (alias_len != fd->alias_len || memcmp(fd->alias, alias, alias_len))) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
}
return FAILURE;
}
if (fd->alias_len && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), fd->alias, fd->alias_len, (void**)&fd_ptr)) {
zend_hash_del(&(PHAR_GLOBALS->phar_alias_map), fd->alias, fd->alias_len);
}
zend_hash_quick_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void*)&fd, sizeof(phar_archive_data*), NULL);
}
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_phars, fname, fname_len, fhash, (void**)&fd_ptr)) {
*archive = *fd_ptr;
fd = *fd_ptr;
/* this could be problematic - alias should never be different from manifest alias
for cached phars */
if (!fd->is_temporary_alias && alias && alias_len) {
if (alias_len != fd->alias_len || memcmp(fd->alias, alias, alias_len)) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
}
return FAILURE;
}
}
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_alias_map), save, save_len, fhash, (void**)&fd_ptr)) {
fd = *archive = *fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_alias, save, save_len, fhash, (void**)&fd_ptr)) {
fd = *archive = *fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
/* not found, try converting \ to / */
my_realpath = expand_filepath(fname, my_realpath TSRMLS_CC);
if (my_realpath) {
fname_len = strlen(my_realpath);
fname = my_realpath;
} else {
return FAILURE;
}
#ifdef PHP_WIN32
phar_unixify_path_separators(fname, fname_len);
#endif
fhash = zend_inline_hash_func(fname, fname_len);
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, fhash, (void**)&fd_ptr)) {
realpath_success:
*archive = *fd_ptr;
fd = *fd_ptr;
if (alias && alias_len) {
zend_hash_quick_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void*)&fd, sizeof(phar_archive_data*), NULL);
}
efree(my_realpath);
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_phars, fname, fname_len, fhash, (void**)&fd_ptr)) {
goto realpath_success;
}
efree(my_realpath);
}
return FAILURE;
}
/* }}} */
|
DoS
| 0
|
int phar_get_archive(phar_archive_data **archive, char *fname, int fname_len, char *alias, int alias_len, char **error TSRMLS_DC) /* {{{ */
{
phar_archive_data *fd, **fd_ptr;
char *my_realpath, *save;
int save_len;
ulong fhash, ahash = 0;
phar_request_initialize(TSRMLS_C);
if (error) {
*error = NULL;
}
*archive = NULL;
if (PHAR_G(last_phar) && fname_len == PHAR_G(last_phar_name_len) && !memcmp(fname, PHAR_G(last_phar_name), fname_len)) {
*archive = PHAR_G(last_phar);
if (alias && alias_len) {
if (!PHAR_G(last_phar)->is_temporary_alias && (alias_len != PHAR_G(last_phar)->alias_len || memcmp(PHAR_G(last_phar)->alias, alias, alias_len))) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, PHAR_G(last_phar)->fname, fname);
}
*archive = NULL;
return FAILURE;
}
if (PHAR_G(last_phar)->alias_len && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len, (void**)&fd_ptr)) {
zend_hash_del(&(PHAR_GLOBALS->phar_alias_map), PHAR_G(last_phar)->alias, PHAR_G(last_phar)->alias_len);
}
zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, (void*)&(*archive), sizeof(phar_archive_data*), NULL);
PHAR_G(last_alias) = alias;
PHAR_G(last_alias_len) = alias_len;
}
return SUCCESS;
}
if (alias && alias_len && PHAR_G(last_phar) && alias_len == PHAR_G(last_alias_len) && !memcmp(alias, PHAR_G(last_alias), alias_len)) {
fd = PHAR_G(last_phar);
fd_ptr = &fd;
goto alias_success;
}
if (alias && alias_len) {
ahash = zend_inline_hash_func(alias, alias_len);
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void**)&fd_ptr)) {
alias_success:
if (fname && (fname_len != (*fd_ptr)->fname_len || strncmp(fname, (*fd_ptr)->fname, fname_len))) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
}
if (SUCCESS == phar_free_alias(*fd_ptr, alias, alias_len TSRMLS_CC)) {
if (error) {
efree(*error);
*error = NULL;
}
}
return FAILURE;
}
*archive = *fd_ptr;
fd = *fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = alias;
PHAR_G(last_alias_len) = alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_alias, alias, alias_len, ahash, (void **)&fd_ptr)) {
goto alias_success;
}
}
fhash = zend_inline_hash_func(fname, fname_len);
my_realpath = NULL;
save = fname;
save_len = fname_len;
if (fname && fname_len) {
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, fhash, (void**)&fd_ptr)) {
*archive = *fd_ptr;
fd = *fd_ptr;
if (alias && alias_len) {
if (!fd->is_temporary_alias && (alias_len != fd->alias_len || memcmp(fd->alias, alias, alias_len))) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
}
return FAILURE;
}
if (fd->alias_len && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), fd->alias, fd->alias_len, (void**)&fd_ptr)) {
zend_hash_del(&(PHAR_GLOBALS->phar_alias_map), fd->alias, fd->alias_len);
}
zend_hash_quick_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void*)&fd, sizeof(phar_archive_data*), NULL);
}
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_phars, fname, fname_len, fhash, (void**)&fd_ptr)) {
*archive = *fd_ptr;
fd = *fd_ptr;
/* this could be problematic - alias should never be different from manifest alias
for cached phars */
if (!fd->is_temporary_alias && alias && alias_len) {
if (alias_len != fd->alias_len || memcmp(fd->alias, alias, alias_len)) {
if (error) {
spprintf(error, 0, "alias \"%s\" is already used for archive \"%s\" cannot be overloaded with \"%s\"", alias, (*fd_ptr)->fname, fname);
}
return FAILURE;
}
}
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_alias_map), save, save_len, fhash, (void**)&fd_ptr)) {
fd = *archive = *fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_alias, save, save_len, fhash, (void**)&fd_ptr)) {
fd = *archive = *fd_ptr;
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
/* not found, try converting \ to / */
my_realpath = expand_filepath(fname, my_realpath TSRMLS_CC);
if (my_realpath) {
fname_len = strlen(my_realpath);
fname = my_realpath;
} else {
return FAILURE;
}
#ifdef PHP_WIN32
phar_unixify_path_separators(fname, fname_len);
#endif
fhash = zend_inline_hash_func(fname, fname_len);
if (SUCCESS == zend_hash_quick_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, fhash, (void**)&fd_ptr)) {
realpath_success:
*archive = *fd_ptr;
fd = *fd_ptr;
if (alias && alias_len) {
zend_hash_quick_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, ahash, (void*)&fd, sizeof(phar_archive_data*), NULL);
}
efree(my_realpath);
PHAR_G(last_phar) = fd;
PHAR_G(last_phar_name) = fd->fname;
PHAR_G(last_phar_name_len) = fd->fname_len;
PHAR_G(last_alias) = fd->alias;
PHAR_G(last_alias_len) = fd->alias_len;
return SUCCESS;
}
if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_quick_find(&cached_phars, fname, fname_len, fhash, (void**)&fd_ptr)) {
goto realpath_success;
}
efree(my_realpath);
}
return FAILURE;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
144
|
php_stream *phar_get_efp(phar_entry_info *entry, int follow_links TSRMLS_DC) /* {{{ */
{
if (follow_links && entry->link) {
phar_entry_info *link_entry = phar_get_link_source(entry TSRMLS_CC);
if (link_entry && link_entry != entry) {
return phar_get_efp(link_entry, 1 TSRMLS_CC);
}
}
if (phar_get_fp_type(entry TSRMLS_CC) == PHAR_FP) {
if (!phar_get_entrypfp(entry TSRMLS_CC)) {
/* re-open just in time for cases where our refcount reached 0 on the phar archive */
phar_open_archive_fp(entry->phar TSRMLS_CC);
}
return phar_get_entrypfp(entry TSRMLS_CC);
} else if (phar_get_fp_type(entry TSRMLS_CC) == PHAR_UFP) {
return phar_get_entrypufp(entry TSRMLS_CC);
} else if (entry->fp_type == PHAR_MOD) {
return entry->fp;
} else {
/* temporary manifest entry */
if (!entry->fp) {
entry->fp = php_stream_open_wrapper(entry->tmp, "rb", STREAM_MUST_SEEK|0, NULL);
}
return entry->fp;
}
}
/* }}} */
|
DoS
| 0
|
php_stream *phar_get_efp(phar_entry_info *entry, int follow_links TSRMLS_DC) /* {{{ */
{
if (follow_links && entry->link) {
phar_entry_info *link_entry = phar_get_link_source(entry TSRMLS_CC);
if (link_entry && link_entry != entry) {
return phar_get_efp(link_entry, 1 TSRMLS_CC);
}
}
if (phar_get_fp_type(entry TSRMLS_CC) == PHAR_FP) {
if (!phar_get_entrypfp(entry TSRMLS_CC)) {
/* re-open just in time for cases where our refcount reached 0 on the phar archive */
phar_open_archive_fp(entry->phar TSRMLS_CC);
}
return phar_get_entrypfp(entry TSRMLS_CC);
} else if (phar_get_fp_type(entry TSRMLS_CC) == PHAR_UFP) {
return phar_get_entrypufp(entry TSRMLS_CC);
} else if (entry->fp_type == PHAR_MOD) {
return entry->fp;
} else {
/* temporary manifest entry */
if (!entry->fp) {
entry->fp = php_stream_open_wrapper(entry->tmp, "rb", STREAM_MUST_SEEK|0, NULL);
}
return entry->fp;
}
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
145
|
int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char *path, int path_len, char *mode, char allow_dir, char **error, int security TSRMLS_DC) /* {{{ */
{
phar_archive_data *phar;
phar_entry_info *entry;
int for_write = mode[0] != 'r' || mode[1] == '+';
int for_append = mode[0] == 'a';
int for_create = mode[0] != 'r';
int for_trunc = mode[0] == 'w';
if (!ret) {
return FAILURE;
}
*ret = NULL;
if (error) {
*error = NULL;
}
if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error TSRMLS_CC)) {
return FAILURE;
}
if (for_write && PHAR_G(readonly) && !phar->is_data) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, fname);
}
return FAILURE;
}
if (!path_len) {
if (error) {
spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" cannot be empty", fname);
}
return FAILURE;
}
really_get_entry:
if (allow_dir) {
if ((entry = phar_get_entry_info_dir(phar, path, path_len, allow_dir, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security TSRMLS_CC)) == NULL) {
if (for_create && (!PHAR_G(readonly) || phar->is_data)) {
return SUCCESS;
}
return FAILURE;
}
} else {
if ((entry = phar_get_entry_info(phar, path, path_len, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security TSRMLS_CC)) == NULL) {
if (for_create && (!PHAR_G(readonly) || phar->is_data)) {
return SUCCESS;
}
return FAILURE;
}
}
if (for_write && phar->is_persistent) {
if (FAILURE == phar_copy_on_write(&phar TSRMLS_CC)) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, could not make cached phar writeable", path, fname);
}
return FAILURE;
} else {
goto really_get_entry;
}
}
if (entry->is_modified && !for_write) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for reading, writable file pointers are open", path, fname);
}
return FAILURE;
}
if (entry->fp_refcount && for_write) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, readable file pointers are open", path, fname);
}
return FAILURE;
}
if (entry->is_deleted) {
if (!for_create) {
return FAILURE;
}
entry->is_deleted = 0;
}
if (entry->is_dir) {
*ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
(*ret)->position = 0;
(*ret)->fp = NULL;
(*ret)->phar = phar;
(*ret)->for_write = for_write;
(*ret)->internal_file = entry;
(*ret)->is_zip = entry->is_zip;
(*ret)->is_tar = entry->is_tar;
if (!phar->is_persistent) {
++(entry->phar->refcount);
++(entry->fp_refcount);
}
return SUCCESS;
}
if (entry->fp_type == PHAR_MOD) {
if (for_trunc) {
if (FAILURE == phar_create_writeable_entry(phar, entry, error TSRMLS_CC)) {
return FAILURE;
}
} else if (for_append) {
phar_seek_efp(entry, 0, SEEK_END, 0, 0 TSRMLS_CC);
}
} else {
if (for_write) {
if (entry->link) {
efree(entry->link);
entry->link = NULL;
entry->tar_type = (entry->is_tar ? TAR_FILE : '\0');
}
if (for_trunc) {
if (FAILURE == phar_create_writeable_entry(phar, entry, error TSRMLS_CC)) {
return FAILURE;
}
} else {
if (FAILURE == phar_separate_entry_fp(entry, error TSRMLS_CC)) {
return FAILURE;
}
}
} else {
if (FAILURE == phar_open_entry_fp(entry, error, 1 TSRMLS_CC)) {
return FAILURE;
}
}
}
*ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
(*ret)->position = 0;
(*ret)->phar = phar;
(*ret)->for_write = for_write;
(*ret)->internal_file = entry;
(*ret)->is_zip = entry->is_zip;
(*ret)->is_tar = entry->is_tar;
(*ret)->fp = phar_get_efp(entry, 1 TSRMLS_CC);
if (entry->link) {
phar_entry_info *link = phar_get_link_source(entry TSRMLS_CC);
if(!link) {
efree(*ret);
return FAILURE;
}
(*ret)->zero = phar_get_fp_offset(link TSRMLS_CC);
} else {
(*ret)->zero = phar_get_fp_offset(entry TSRMLS_CC);
}
if (!phar->is_persistent) {
++(entry->fp_refcount);
++(entry->phar->refcount);
}
return SUCCESS;
}
/* }}} */
|
DoS
| 0
|
int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char *path, int path_len, char *mode, char allow_dir, char **error, int security TSRMLS_DC) /* {{{ */
{
phar_archive_data *phar;
phar_entry_info *entry;
int for_write = mode[0] != 'r' || mode[1] == '+';
int for_append = mode[0] == 'a';
int for_create = mode[0] != 'r';
int for_trunc = mode[0] == 'w';
if (!ret) {
return FAILURE;
}
*ret = NULL;
if (error) {
*error = NULL;
}
if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error TSRMLS_CC)) {
return FAILURE;
}
if (for_write && PHAR_G(readonly) && !phar->is_data) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, fname);
}
return FAILURE;
}
if (!path_len) {
if (error) {
spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" cannot be empty", fname);
}
return FAILURE;
}
really_get_entry:
if (allow_dir) {
if ((entry = phar_get_entry_info_dir(phar, path, path_len, allow_dir, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security TSRMLS_CC)) == NULL) {
if (for_create && (!PHAR_G(readonly) || phar->is_data)) {
return SUCCESS;
}
return FAILURE;
}
} else {
if ((entry = phar_get_entry_info(phar, path, path_len, for_create && !PHAR_G(readonly) && !phar->is_data ? NULL : error, security TSRMLS_CC)) == NULL) {
if (for_create && (!PHAR_G(readonly) || phar->is_data)) {
return SUCCESS;
}
return FAILURE;
}
}
if (for_write && phar->is_persistent) {
if (FAILURE == phar_copy_on_write(&phar TSRMLS_CC)) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, could not make cached phar writeable", path, fname);
}
return FAILURE;
} else {
goto really_get_entry;
}
}
if (entry->is_modified && !for_write) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for reading, writable file pointers are open", path, fname);
}
return FAILURE;
}
if (entry->fp_refcount && for_write) {
if (error) {
spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, readable file pointers are open", path, fname);
}
return FAILURE;
}
if (entry->is_deleted) {
if (!for_create) {
return FAILURE;
}
entry->is_deleted = 0;
}
if (entry->is_dir) {
*ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
(*ret)->position = 0;
(*ret)->fp = NULL;
(*ret)->phar = phar;
(*ret)->for_write = for_write;
(*ret)->internal_file = entry;
(*ret)->is_zip = entry->is_zip;
(*ret)->is_tar = entry->is_tar;
if (!phar->is_persistent) {
++(entry->phar->refcount);
++(entry->fp_refcount);
}
return SUCCESS;
}
if (entry->fp_type == PHAR_MOD) {
if (for_trunc) {
if (FAILURE == phar_create_writeable_entry(phar, entry, error TSRMLS_CC)) {
return FAILURE;
}
} else if (for_append) {
phar_seek_efp(entry, 0, SEEK_END, 0, 0 TSRMLS_CC);
}
} else {
if (for_write) {
if (entry->link) {
efree(entry->link);
entry->link = NULL;
entry->tar_type = (entry->is_tar ? TAR_FILE : '\0');
}
if (for_trunc) {
if (FAILURE == phar_create_writeable_entry(phar, entry, error TSRMLS_CC)) {
return FAILURE;
}
} else {
if (FAILURE == phar_separate_entry_fp(entry, error TSRMLS_CC)) {
return FAILURE;
}
}
} else {
if (FAILURE == phar_open_entry_fp(entry, error, 1 TSRMLS_CC)) {
return FAILURE;
}
}
}
*ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
(*ret)->position = 0;
(*ret)->phar = phar;
(*ret)->for_write = for_write;
(*ret)->internal_file = entry;
(*ret)->is_zip = entry->is_zip;
(*ret)->is_tar = entry->is_tar;
(*ret)->fp = phar_get_efp(entry, 1 TSRMLS_CC);
if (entry->link) {
phar_entry_info *link = phar_get_link_source(entry TSRMLS_CC);
if(!link) {
efree(*ret);
return FAILURE;
}
(*ret)->zero = phar_get_fp_offset(link TSRMLS_CC);
} else {
(*ret)->zero = phar_get_fp_offset(entry TSRMLS_CC);
}
if (!phar->is_persistent) {
++(entry->fp_refcount);
++(entry->phar->refcount);
}
return SUCCESS;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
146
|
phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security TSRMLS_DC) /* {{{ */
{
return phar_get_entry_info_dir(phar, path, path_len, 0, error, security TSRMLS_CC);
}
/* }}} */
|
DoS
| 0
|
phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error, int security TSRMLS_DC) /* {{{ */
{
return phar_get_entry_info_dir(phar, path, path_len, 0, error, security TSRMLS_CC);
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
147
|
phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security TSRMLS_DC) /* {{{ */
{
const char *pcr_error;
phar_entry_info *entry;
int is_dir;
#ifdef PHP_WIN32
phar_unixify_path_separators(path, path_len);
#endif
is_dir = (path_len && (path[path_len - 1] == '/')) ? 1 : 0;
if (error) {
*error = NULL;
}
if (security && path_len >= sizeof(".phar")-1 && !memcmp(path, ".phar", sizeof(".phar")-1)) {
if (error) {
spprintf(error, 4096, "phar error: cannot directly access magic \".phar\" directory or files within it");
}
return NULL;
}
if (!path_len && !dir) {
if (error) {
spprintf(error, 4096, "phar error: invalid path \"%s\" must not be empty", path);
}
return NULL;
}
if (phar_path_check(&path, &path_len, &pcr_error) > pcr_is_ok) {
if (error) {
spprintf(error, 4096, "phar error: invalid path \"%s\" contains %s", path, pcr_error);
}
return NULL;
}
if (!phar->manifest.arBuckets) {
return NULL;
}
if (is_dir) {
if (!path_len || path_len == 1) {
return NULL;
}
path_len--;
}
if (SUCCESS == zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) {
if (entry->is_deleted) {
/* entry is deleted, but has not been flushed to disk yet */
return NULL;
}
if (entry->is_dir && !dir) {
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" is a directory", path);
}
return NULL;
}
if (!entry->is_dir && dir == 2) {
/* user requested a directory, we must return one */
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists and is a not a directory", path);
}
return NULL;
}
return entry;
}
if (dir) {
if (zend_hash_exists(&phar->virtual_dirs, path, path_len)) {
/* a file or directory exists in a sub-directory of this path */
entry = (phar_entry_info *) ecalloc(1, sizeof(phar_entry_info));
/* this next line tells PharFileInfo->__destruct() to efree the filename */
entry->is_temp_dir = entry->is_dir = 1;
entry->filename = (char *) estrndup(path, path_len + 1);
entry->filename_len = path_len;
entry->phar = phar;
return entry;
}
}
if (phar->mounted_dirs.arBuckets && zend_hash_num_elements(&phar->mounted_dirs)) {
phar_zstr key;
char *str_key;
ulong unused;
uint keylen;
zend_hash_internal_pointer_reset(&phar->mounted_dirs);
while (FAILURE != zend_hash_has_more_elements(&phar->mounted_dirs)) {
if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(&phar->mounted_dirs, &key, &keylen, &unused, 0, NULL)) {
break;
}
PHAR_STR(key, str_key);
if ((int)keylen >= path_len || strncmp(str_key, path, keylen)) {
PHAR_STR_FREE(str_key);
continue;
} else {
char *test;
int test_len;
php_stream_statbuf ssb;
if (SUCCESS != zend_hash_find(&phar->manifest, str_key, keylen, (void **) &entry)) {
if (error) {
spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", str_key);
}
PHAR_STR_FREE(str_key);
return NULL;
}
if (!entry->tmp || !entry->is_mounted) {
if (error) {
spprintf(error, 4096, "phar internal error: mounted path \"%s\" is not properly initialized as a mounted path", str_key);
}
PHAR_STR_FREE(str_key);
return NULL;
}
PHAR_STR_FREE(str_key);
test_len = spprintf(&test, MAXPATHLEN, "%s%s", entry->tmp, path + keylen);
if (SUCCESS != php_stream_stat_path(test, &ssb)) {
efree(test);
return NULL;
}
if (ssb.sb.st_mode & S_IFDIR && !dir) {
efree(test);
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" is a directory", path);
}
return NULL;
}
if ((ssb.sb.st_mode & S_IFDIR) == 0 && dir) {
efree(test);
/* user requested a directory, we must return one */
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists and is a not a directory", path);
}
return NULL;
}
/* mount the file just in time */
if (SUCCESS != phar_mount_entry(phar, test, test_len, path, path_len TSRMLS_CC)) {
efree(test);
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists as file \"%s\" and could not be mounted", path, test);
}
return NULL;
}
efree(test);
if (SUCCESS != zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) {
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists as file \"%s\" and could not be retrieved after being mounted", path, test);
}
return NULL;
}
return entry;
}
}
}
return NULL;
}
/* }}} */
|
DoS
| 0
|
phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error, int security TSRMLS_DC) /* {{{ */
{
const char *pcr_error;
phar_entry_info *entry;
int is_dir;
#ifdef PHP_WIN32
phar_unixify_path_separators(path, path_len);
#endif
is_dir = (path_len && (path[path_len - 1] == '/')) ? 1 : 0;
if (error) {
*error = NULL;
}
if (security && path_len >= sizeof(".phar")-1 && !memcmp(path, ".phar", sizeof(".phar")-1)) {
if (error) {
spprintf(error, 4096, "phar error: cannot directly access magic \".phar\" directory or files within it");
}
return NULL;
}
if (!path_len && !dir) {
if (error) {
spprintf(error, 4096, "phar error: invalid path \"%s\" must not be empty", path);
}
return NULL;
}
if (phar_path_check(&path, &path_len, &pcr_error) > pcr_is_ok) {
if (error) {
spprintf(error, 4096, "phar error: invalid path \"%s\" contains %s", path, pcr_error);
}
return NULL;
}
if (!phar->manifest.arBuckets) {
return NULL;
}
if (is_dir) {
if (!path_len || path_len == 1) {
return NULL;
}
path_len--;
}
if (SUCCESS == zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) {
if (entry->is_deleted) {
/* entry is deleted, but has not been flushed to disk yet */
return NULL;
}
if (entry->is_dir && !dir) {
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" is a directory", path);
}
return NULL;
}
if (!entry->is_dir && dir == 2) {
/* user requested a directory, we must return one */
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists and is a not a directory", path);
}
return NULL;
}
return entry;
}
if (dir) {
if (zend_hash_exists(&phar->virtual_dirs, path, path_len)) {
/* a file or directory exists in a sub-directory of this path */
entry = (phar_entry_info *) ecalloc(1, sizeof(phar_entry_info));
/* this next line tells PharFileInfo->__destruct() to efree the filename */
entry->is_temp_dir = entry->is_dir = 1;
entry->filename = (char *) estrndup(path, path_len + 1);
entry->filename_len = path_len;
entry->phar = phar;
return entry;
}
}
if (phar->mounted_dirs.arBuckets && zend_hash_num_elements(&phar->mounted_dirs)) {
phar_zstr key;
char *str_key;
ulong unused;
uint keylen;
zend_hash_internal_pointer_reset(&phar->mounted_dirs);
while (FAILURE != zend_hash_has_more_elements(&phar->mounted_dirs)) {
if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key_ex(&phar->mounted_dirs, &key, &keylen, &unused, 0, NULL)) {
break;
}
PHAR_STR(key, str_key);
if ((int)keylen >= path_len || strncmp(str_key, path, keylen)) {
PHAR_STR_FREE(str_key);
continue;
} else {
char *test;
int test_len;
php_stream_statbuf ssb;
if (SUCCESS != zend_hash_find(&phar->manifest, str_key, keylen, (void **) &entry)) {
if (error) {
spprintf(error, 4096, "phar internal error: mounted path \"%s\" could not be retrieved from manifest", str_key);
}
PHAR_STR_FREE(str_key);
return NULL;
}
if (!entry->tmp || !entry->is_mounted) {
if (error) {
spprintf(error, 4096, "phar internal error: mounted path \"%s\" is not properly initialized as a mounted path", str_key);
}
PHAR_STR_FREE(str_key);
return NULL;
}
PHAR_STR_FREE(str_key);
test_len = spprintf(&test, MAXPATHLEN, "%s%s", entry->tmp, path + keylen);
if (SUCCESS != php_stream_stat_path(test, &ssb)) {
efree(test);
return NULL;
}
if (ssb.sb.st_mode & S_IFDIR && !dir) {
efree(test);
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" is a directory", path);
}
return NULL;
}
if ((ssb.sb.st_mode & S_IFDIR) == 0 && dir) {
efree(test);
/* user requested a directory, we must return one */
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists and is a not a directory", path);
}
return NULL;
}
/* mount the file just in time */
if (SUCCESS != phar_mount_entry(phar, test, test_len, path, path_len TSRMLS_CC)) {
efree(test);
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists as file \"%s\" and could not be mounted", path, test);
}
return NULL;
}
efree(test);
if (SUCCESS != zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) {
if (error) {
spprintf(error, 4096, "phar error: path \"%s\" exists as file \"%s\" and could not be retrieved after being mounted", path, test);
}
return NULL;
}
return entry;
}
}
}
return NULL;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
148
|
static char *phar_get_link_location(phar_entry_info *entry TSRMLS_DC) /* {{{ */
{
char *p, *ret = NULL;
if (!entry->link) {
return NULL;
}
if (entry->link[0] == '/') {
return estrdup(entry->link + 1);
}
p = strrchr(entry->filename, '/');
if (p) {
*p = '\0';
spprintf(&ret, 0, "%s/%s", entry->filename, entry->link);
return ret;
}
return entry->link;
}
/* }}} */
|
DoS
| 0
|
static char *phar_get_link_location(phar_entry_info *entry TSRMLS_DC) /* {{{ */
{
char *p, *ret = NULL;
if (!entry->link) {
return NULL;
}
if (entry->link[0] == '/') {
return estrdup(entry->link + 1);
}
p = strrchr(entry->filename, '/');
if (p) {
*p = '\0';
spprintf(&ret, 0, "%s/%s", entry->filename, entry->link);
return ret;
}
return entry->link;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
149
|
phar_entry_info *phar_get_link_source(phar_entry_info *entry TSRMLS_DC) /* {{{ */
{
phar_entry_info *link_entry;
char *link;
if (!entry->link) {
return entry;
}
link = phar_get_link_location(entry TSRMLS_CC);
if (SUCCESS == zend_hash_find(&(entry->phar->manifest), entry->link, strlen(entry->link), (void **)&link_entry) ||
SUCCESS == zend_hash_find(&(entry->phar->manifest), link, strlen(link), (void **)&link_entry)) {
if (link != entry->link) {
efree(link);
}
return phar_get_link_source(link_entry TSRMLS_CC);
} else {
if (link != entry->link) {
efree(link);
}
return NULL;
}
}
/* }}} */
|
DoS
| 0
|
phar_entry_info *phar_get_link_source(phar_entry_info *entry TSRMLS_DC) /* {{{ */
{
phar_entry_info *link_entry;
char *link;
if (!entry->link) {
return entry;
}
link = phar_get_link_location(entry TSRMLS_CC);
if (SUCCESS == zend_hash_find(&(entry->phar->manifest), entry->link, strlen(entry->link), (void **)&link_entry) ||
SUCCESS == zend_hash_find(&(entry->phar->manifest), link, strlen(link), (void **)&link_entry)) {
if (link != entry->link) {
efree(link);
}
return phar_get_link_source(link_entry TSRMLS_CC);
} else {
if (link != entry->link) {
efree(link);
}
return NULL;
}
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
150
|
static int phar_hex_str(const char *digest, size_t digest_len, char **signature TSRMLS_DC) /* {{{ */
{
int pos = -1;
size_t len = 0;
*signature = (char*)safe_pemalloc(digest_len, 2, 1, PHAR_G(persist));
for (; len < digest_len; ++len) {
(*signature)[++pos] = hexChars[((const unsigned char *)digest)[len] >> 4];
(*signature)[++pos] = hexChars[((const unsigned char *)digest)[len] & 0x0F];
}
(*signature)[++pos] = '\0';
return pos;
}
/* }}} */
|
DoS
| 0
|
static int phar_hex_str(const char *digest, size_t digest_len, char **signature TSRMLS_DC) /* {{{ */
{
int pos = -1;
size_t len = 0;
*signature = (char*)safe_pemalloc(digest_len, 2, 1, PHAR_G(persist));
for (; len < digest_len; ++len) {
(*signature)[++pos] = hexChars[((const unsigned char *)digest)[len] >> 4];
(*signature)[++pos] = hexChars[((const unsigned char *)digest)[len] & 0x0F];
}
(*signature)[++pos] = '\0';
return pos;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
151
|
int phar_open_archive_fp(phar_archive_data *phar TSRMLS_DC) /* {{{ */
{
if (phar_get_pharfp(phar TSRMLS_CC)) {
return SUCCESS;
}
if (php_check_open_basedir(phar->fname TSRMLS_CC)) {
return FAILURE;
}
phar_set_pharfp(phar, php_stream_open_wrapper(phar->fname, "rb", IGNORE_URL|STREAM_MUST_SEEK|0, NULL) TSRMLS_CC);
if (!phar_get_pharfp(phar TSRMLS_CC)) {
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
DoS
| 0
|
int phar_open_archive_fp(phar_archive_data *phar TSRMLS_DC) /* {{{ */
{
if (phar_get_pharfp(phar TSRMLS_CC)) {
return SUCCESS;
}
if (php_check_open_basedir(phar->fname TSRMLS_CC)) {
return FAILURE;
}
phar_set_pharfp(phar, php_stream_open_wrapper(phar->fname, "rb", IGNORE_URL|STREAM_MUST_SEEK|0, NULL) TSRMLS_CC);
if (!phar_get_pharfp(phar TSRMLS_CC)) {
return FAILURE;
}
return SUCCESS;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
152
|
phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */
{
if (error) {
*error = NULL;
}
/* seek to start of internal file and read it */
if (FAILURE == phar_open_entry_fp(entry, error, 1 TSRMLS_CC)) {
return NULL;
}
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1 TSRMLS_CC)) {
spprintf(error, 4096, "phar error: cannot seek to start of file \"%s\" in phar \"%s\"", entry->filename, phar->fname);
return NULL;
}
return entry;
}
/* }}} */
|
DoS
| 0
|
phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */
{
if (error) {
*error = NULL;
}
/* seek to start of internal file and read it */
if (FAILURE == phar_open_entry_fp(entry, error, 1 TSRMLS_CC)) {
return NULL;
}
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 1 TSRMLS_CC)) {
spprintf(error, 4096, "phar error: cannot seek to start of file \"%s\" in phar \"%s\"", entry->filename, phar->fname);
return NULL;
}
return entry;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
153
|
int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t position, int follow_links TSRMLS_DC) /* {{{ */
{
php_stream *fp = phar_get_efp(entry, follow_links TSRMLS_CC);
off_t temp, eoffset;
if (!fp) {
return -1;
}
if (follow_links) {
phar_entry_info *t;
t = phar_get_link_source(entry TSRMLS_CC);
if (t) {
entry = t;
}
}
if (entry->is_dir) {
return 0;
}
eoffset = phar_get_fp_offset(entry TSRMLS_CC);
switch (whence) {
case SEEK_END:
temp = eoffset + entry->uncompressed_filesize + offset;
break;
case SEEK_CUR:
temp = eoffset + position + offset;
break;
case SEEK_SET:
temp = eoffset + offset;
break;
default:
temp = 0;
}
if (temp > eoffset + (off_t) entry->uncompressed_filesize) {
return -1;
}
if (temp < eoffset) {
return -1;
}
return php_stream_seek(fp, temp, SEEK_SET);
}
/* }}} */
|
DoS
| 0
|
int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t position, int follow_links TSRMLS_DC) /* {{{ */
{
php_stream *fp = phar_get_efp(entry, follow_links TSRMLS_CC);
off_t temp, eoffset;
if (!fp) {
return -1;
}
if (follow_links) {
phar_entry_info *t;
t = phar_get_link_source(entry TSRMLS_CC);
if (t) {
entry = t;
}
}
if (entry->is_dir) {
return 0;
}
eoffset = phar_get_fp_offset(entry TSRMLS_CC);
switch (whence) {
case SEEK_END:
temp = eoffset + entry->uncompressed_filesize + offset;
break;
case SEEK_CUR:
temp = eoffset + position + offset;
break;
case SEEK_SET:
temp = eoffset + offset;
break;
default:
temp = 0;
}
if (temp > eoffset + (off_t) entry->uncompressed_filesize) {
return -1;
}
if (temp < eoffset) {
return -1;
}
return php_stream_seek(fp, temp, SEEK_SET);
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
154
|
static int phar_update_cached_entry(void *data, void *argument) /* {{{ */
{
phar_entry_info *entry = (phar_entry_info *)data;
TSRMLS_FETCH();
entry->phar = (phar_archive_data *)argument;
if (entry->link) {
entry->link = estrdup(entry->link);
}
if (entry->tmp) {
entry->tmp = estrdup(entry->tmp);
}
entry->metadata_str.c = 0;
entry->filename = estrndup(entry->filename, entry->filename_len);
entry->is_persistent = 0;
if (entry->metadata) {
if (entry->metadata_len) {
char *buf = estrndup((char *) entry->metadata, entry->metadata_len);
/* assume success, we would have failed before */
phar_parse_metadata((char **) &buf, &entry->metadata, entry->metadata_len TSRMLS_CC);
efree(buf);
} else {
zval *t;
t = entry->metadata;
ALLOC_ZVAL(entry->metadata);
*entry->metadata = *t;
zval_copy_ctor(entry->metadata);
Z_SET_REFCOUNT_P(entry->metadata, 1);
entry->metadata_str.c = NULL;
entry->metadata_str.len = 0;
}
}
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
|
DoS
| 0
|
static int phar_update_cached_entry(void *data, void *argument) /* {{{ */
{
phar_entry_info *entry = (phar_entry_info *)data;
TSRMLS_FETCH();
entry->phar = (phar_archive_data *)argument;
if (entry->link) {
entry->link = estrdup(entry->link);
}
if (entry->tmp) {
entry->tmp = estrdup(entry->tmp);
}
entry->metadata_str.c = 0;
entry->filename = estrndup(entry->filename, entry->filename_len);
entry->is_persistent = 0;
if (entry->metadata) {
if (entry->metadata_len) {
char *buf = estrndup((char *) entry->metadata, entry->metadata_len);
/* assume success, we would have failed before */
phar_parse_metadata((char **) &buf, &entry->metadata, entry->metadata_len TSRMLS_CC);
efree(buf);
} else {
zval *t;
t = entry->metadata;
ALLOC_ZVAL(entry->metadata);
*entry->metadata = *t;
zval_copy_ctor(entry->metadata);
Z_SET_REFCOUNT_P(entry->metadata, 1);
entry->metadata_str.c = NULL;
entry->metadata_str.len = 0;
}
}
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
|
@@ -1977,7 +1977,7 @@ void phar_add_virtual_dirs(phar_archive_data *phar, char *filename, int filename
while ((s = zend_memrchr(filename, '/', filename_len))) {
filename_len = s - filename;
- if (FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
+ if (!filename_len || FAILURE == zend_hash_add_empty_element(&phar->virtual_dirs, filename, filename_len)) {
break;
}
}
|
CWE-189
| null | null |
155
|
delelement (struct fileinfo *f, struct fileinfo **start)
{
struct fileinfo *prev = f->prev;
struct fileinfo *next = f->next;
xfree (f->name);
xfree (f->linkto);
xfree (f);
if (next)
next->prev = prev;
if (prev)
prev->next = next;
else
*start = next;
return next;
}
|
+Info
| 0
|
delelement (struct fileinfo *f, struct fileinfo **start)
{
struct fileinfo *prev = f->prev;
struct fileinfo *next = f->next;
xfree (f->name);
xfree (f->linkto);
xfree (f);
if (next)
next->prev = prev;
if (prev)
prev->next = next;
else
*start = next;
return next;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
156
|
freefileinfo (struct fileinfo *f)
{
while (f)
{
struct fileinfo *next = f->next;
xfree (f->name);
if (f->linkto)
xfree (f->linkto);
xfree (f);
f = next;
}
}
|
+Info
| 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;
}
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
157
|
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;
}
|
+Info
| 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;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
158
|
ftp_do_pasv (int csock, ip_address *addr, int *port)
{
if (!opt.server_response)
logputs (LOG_VERBOSE, "==> PASV ... ");
return ftp_pasv (csock, addr, port);
}
|
+Info
| 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);
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
159
|
ftp_expected_bytes (const char *s)
{
wgint res;
while (1)
{
while (*s && *s != '(')
++s;
if (!*s)
return 0;
++s; /* skip the '(' */
res = str_to_wgint (s, (char **) &s, 10);
if (!*s)
return 0;
while (*s && c_isspace (*s))
++s;
if (!*s)
return 0;
if (c_tolower (*s) != 'b')
continue;
if (c_strncasecmp (s, "byte", 4))
continue;
else
break;
}
return res;
}
|
+Info
| 0
|
ftp_expected_bytes (const char *s)
{
wgint res;
while (1)
{
while (*s && *s != '(')
++s;
if (!*s)
return 0;
++s; /* skip the '(' */
res = str_to_wgint (s, (char **) &s, 10);
if (!*s)
return 0;
while (*s && c_isspace (*s))
++s;
if (!*s)
return 0;
if (c_tolower (*s) != 'b')
continue;
if (c_strncasecmp (s, "byte", 4))
continue;
else
break;
}
return res;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
160
|
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;
}
|
+Info
| 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;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
161
|
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;
}
|
+Info
| 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;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
162
|
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;
}
|
+Info
| 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;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
163
|
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;
}
|
+Info
| 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;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
164
|
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;
}
|
+Info
| 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;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
165
|
has_insecure_name_p (const char *s)
{
if (*s == '/')
return true;
if (strstr (s, "../") != 0)
return true;
return false;
}
|
+Info
| 0
|
has_insecure_name_p (const char *s)
{
if (*s == '/')
return true;
if (strstr (s, "../") != 0)
return true;
return false;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
166
|
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;
}
|
+Info
| 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;
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
167
|
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");
}
|
+Info
| 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");
}
|
@@ -252,7 +252,6 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
char *respline, *tms;
const char *user, *passwd, *tmrate;
int cmd = con->cmd;
- bool pasv_mode_open = false;
wgint expected_bytes = 0;
bool got_expected_bytes = false;
bool rest_failed = false;
@@ -883,13 +882,19 @@ Error in server response, closing control connection.\n"));
? CONERROR : CONIMPOSSIBLE);
}
- pasv_mode_open = true; /* Flag to avoid accept port */
if (!opt.server_response)
logputs (LOG_VERBOSE, _("done. "));
- } /* err==FTP_OK */
- }
+ }
+ else
+ return err;
- if (!pasv_mode_open) /* Try to use a port command if PASV failed */
+ /*
+ * We do not want to fall back from PASSIVE mode to ACTIVE mode !
+ * The reason is the PORT command exposes the client's real IP address
+ * to the server. Bad for someone who relies on privacy via a ftp proxy.
+ */
+ }
+ else
{
err = ftp_do_port (csock, &local_sock);
/* FTPRERR, WRITEFAILED, bindport (FTPSYSERR), HOSTERR,
@@ -1148,8 +1153,8 @@ Error in server response, closing control connection.\n"));
}
/* If no transmission was required, then everything is OK. */
- if (!pasv_mode_open) /* we are not using pasive mode so we need
- to accept */
+ if (!opt.ftp_pasv) /* we are not using passive mode so we need
+ to accept */
{
/* Wait for the server to connect to the address we're waiting
at. */
|
CWE-200
| null | null |
168
|
attr_count (void)
{
return attrhash->count;
}
|
DoS
| 0
|
attr_count (void)
{
return attrhash->count;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
169
|
attr_show_all (struct vty *vty)
{
hash_iterate (attrhash,
(void (*)(struct hash_backet *, void *))
attr_show_all_iterator,
vty);
}
|
DoS
| 0
|
attr_show_all (struct vty *vty)
{
hash_iterate (attrhash,
(void (*)(struct hash_backet *, void *))
attr_show_all_iterator,
vty);
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
170
|
attr_show_all_iterator (struct hash_backet *backet, struct vty *vty)
{
struct attr *attr = backet->data;
vty_out (vty, "attr[%ld] nexthop %s%s", attr->refcnt,
inet_ntoa (attr->nexthop), VTY_NEWLINE);
}
|
DoS
| 0
|
attr_show_all_iterator (struct hash_backet *backet, struct vty *vty)
{
struct attr *attr = backet->data;
vty_out (vty, "attr[%ld] nexthop %s%s", attr->refcnt,
inet_ntoa (attr->nexthop), VTY_NEWLINE);
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
171
|
attr_unknown_count (void)
{
return transit_hash->count;
}
|
DoS
| 0
|
attr_unknown_count (void)
{
return transit_hash->count;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
172
|
attrhash_finish (void)
{
hash_free (attrhash);
attrhash = NULL;
}
|
DoS
| 0
|
attrhash_finish (void)
{
hash_free (attrhash);
attrhash = NULL;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
173
|
attrhash_init (void)
{
attrhash = hash_create (attrhash_key_make, attrhash_cmp);
}
|
DoS
| 0
|
attrhash_init (void)
{
attrhash = hash_create (attrhash_key_make, attrhash_cmp);
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
174
|
attrhash_key_make (void *p)
{
const struct attr * attr = (struct attr *) p;
uint32_t key = 0;
#define MIX(val) key = jhash_1word(val, key)
MIX(attr->origin);
MIX(attr->nexthop.s_addr);
MIX(attr->med);
MIX(attr->local_pref);
key += attr->origin;
key += attr->nexthop.s_addr;
key += attr->med;
key += attr->local_pref;
if (attr->extra)
{
MIX(attr->extra->aggregator_as);
MIX(attr->extra->aggregator_addr.s_addr);
MIX(attr->extra->weight);
MIX(attr->extra->mp_nexthop_global_in.s_addr);
}
if (attr->aspath)
MIX(aspath_key_make (attr->aspath));
if (attr->community)
MIX(community_hash_make (attr->community));
if (attr->extra)
{
if (attr->extra->ecommunity)
MIX(ecommunity_hash_make (attr->extra->ecommunity));
if (attr->extra->cluster)
MIX(cluster_hash_key_make (attr->extra->cluster));
if (attr->extra->transit)
MIX(transit_hash_key_make (attr->extra->transit));
#ifdef HAVE_IPV6
MIX(attr->extra->mp_nexthop_len);
key = jhash(attr->extra->mp_nexthop_global.s6_addr, 16, key);
key = jhash(attr->extra->mp_nexthop_local.s6_addr, 16, key);
#endif /* HAVE_IPV6 */
}
return key;
}
|
DoS
| 0
|
attrhash_key_make (void *p)
{
const struct attr * attr = (struct attr *) p;
uint32_t key = 0;
#define MIX(val) key = jhash_1word(val, key)
MIX(attr->origin);
MIX(attr->nexthop.s_addr);
MIX(attr->med);
MIX(attr->local_pref);
key += attr->origin;
key += attr->nexthop.s_addr;
key += attr->med;
key += attr->local_pref;
if (attr->extra)
{
MIX(attr->extra->aggregator_as);
MIX(attr->extra->aggregator_addr.s_addr);
MIX(attr->extra->weight);
MIX(attr->extra->mp_nexthop_global_in.s_addr);
}
if (attr->aspath)
MIX(aspath_key_make (attr->aspath));
if (attr->community)
MIX(community_hash_make (attr->community));
if (attr->extra)
{
if (attr->extra->ecommunity)
MIX(ecommunity_hash_make (attr->extra->ecommunity));
if (attr->extra->cluster)
MIX(cluster_hash_key_make (attr->extra->cluster));
if (attr->extra->transit)
MIX(transit_hash_key_make (attr->extra->transit));
#ifdef HAVE_IPV6
MIX(attr->extra->mp_nexthop_len);
key = jhash(attr->extra->mp_nexthop_global.s6_addr, 16, key);
key = jhash(attr->extra->mp_nexthop_local.s6_addr, 16, key);
#endif /* HAVE_IPV6 */
}
return key;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
175
|
bgp_attr_aggregator (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
int wantedlen = 6;
struct attr_extra *attre = bgp_attr_extra_get (attr);
/* peer with AS4 will send 4 Byte AS, peer without will send 2 Byte */
if (CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV))
wantedlen = 8;
if (length != wantedlen)
{
zlog (peer->log, LOG_ERR, "AGGREGATOR attribute length isn't %u [%u]",
wantedlen, length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
if ( CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV ) )
attre->aggregator_as = stream_getl (peer->ibuf);
else
attre->aggregator_as = stream_getw (peer->ibuf);
attre->aggregator_addr.s_addr = stream_get_ipv4 (peer->ibuf);
/* Set atomic aggregate flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_aggregator (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
int wantedlen = 6;
struct attr_extra *attre = bgp_attr_extra_get (attr);
/* peer with AS4 will send 4 Byte AS, peer without will send 2 Byte */
if (CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV))
wantedlen = 8;
if (length != wantedlen)
{
zlog (peer->log, LOG_ERR, "AGGREGATOR attribute length isn't %u [%u]",
wantedlen, length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
if ( CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV ) )
attre->aggregator_as = stream_getl (peer->ibuf);
else
attre->aggregator_as = stream_getw (peer->ibuf);
attre->aggregator_addr.s_addr = stream_get_ipv4 (peer->ibuf);
/* Set atomic aggregate flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
176
|
bgp_attr_as4_aggregator (struct bgp_attr_parser_args *args,
as_t *as4_aggregator_as,
struct in_addr *as4_aggregator_addr)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
if (length != 8)
{
zlog (peer->log, LOG_ERR, "New Aggregator length is not 8 [%d]",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
0);
}
*as4_aggregator_as = stream_getl (peer->ibuf);
as4_aggregator_addr->s_addr = stream_get_ipv4 (peer->ibuf);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS4_AGGREGATOR);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_as4_aggregator (struct bgp_attr_parser_args *args,
as_t *as4_aggregator_as,
struct in_addr *as4_aggregator_addr)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
if (length != 8)
{
zlog (peer->log, LOG_ERR, "New Aggregator length is not 8 [%d]",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
0);
}
*as4_aggregator_as = stream_getl (peer->ibuf);
as4_aggregator_addr->s_addr = stream_get_ipv4 (peer->ibuf);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS4_AGGREGATOR);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
177
|
bgp_attr_as4_path (struct bgp_attr_parser_args *args, struct aspath **as4_path)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
*as4_path = aspath_parse (peer->ibuf, length, 1);
/* In case of IBGP, length will be zero. */
if (!*as4_path)
{
zlog (peer->log, LOG_ERR,
"Malformed AS4 path from %s, length is %d",
peer->host, length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_MAL_AS_PATH,
0);
}
/* Set aspath attribute flag. */
if (as4_path)
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS4_PATH);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_as4_path (struct bgp_attr_parser_args *args, struct aspath **as4_path)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
*as4_path = aspath_parse (peer->ibuf, length, 1);
/* In case of IBGP, length will be zero. */
if (!*as4_path)
{
zlog (peer->log, LOG_ERR,
"Malformed AS4 path from %s, length is %d",
peer->host, length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_MAL_AS_PATH,
0);
}
/* Set aspath attribute flag. */
if (as4_path)
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS4_PATH);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
178
|
bgp_attr_aspath (struct bgp_attr_parser_args *args)
{
struct attr *const attr = args->attr;
struct peer *const peer = args->peer;
const bgp_size_t length = args->length;
/*
* peer with AS4 => will get 4Byte ASnums
* otherwise, will get 16 Bit
*/
attr->aspath = aspath_parse (peer->ibuf, length,
CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV));
/* In case of IBGP, length will be zero. */
if (! attr->aspath)
{
zlog (peer->log, LOG_ERR,
"Malformed AS path from %s, length is %d",
peer->host, length);
return bgp_attr_malformed (args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, 0);
}
/* Set aspath attribute flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATH);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_aspath (struct bgp_attr_parser_args *args)
{
struct attr *const attr = args->attr;
struct peer *const peer = args->peer;
const bgp_size_t length = args->length;
/*
* peer with AS4 => will get 4Byte ASnums
* otherwise, will get 16 Bit
*/
attr->aspath = aspath_parse (peer->ibuf, length,
CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV));
/* In case of IBGP, length will be zero. */
if (! attr->aspath)
{
zlog (peer->log, LOG_ERR,
"Malformed AS path from %s, length is %d",
peer->host, length);
return bgp_attr_malformed (args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, 0);
}
/* Set aspath attribute flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATH);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
179
|
bgp_attr_aspath_check (struct peer *const peer, struct attr *const attr)
{
/* These checks were part of bgp_attr_aspath, but with
* as4 we should to check aspath things when
* aspath synthesizing with as4_path has already taken place.
* Otherwise we check ASPATH and use the synthesized thing, and that is
* not right.
* So do the checks later, i.e. here
*/
struct bgp *bgp = peer->bgp;
struct aspath *aspath;
bgp = peer->bgp;
/* Confederation sanity check. */
if ((peer_sort (peer) == BGP_PEER_CONFED && ! aspath_left_confed_check (attr->aspath)) ||
(peer_sort (peer) == BGP_PEER_EBGP && aspath_confed_check (attr->aspath)))
{
zlog (peer->log, LOG_ERR, "Malformed AS path from %s", peer->host);
bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
return BGP_ATTR_PARSE_ERROR;
}
/* First AS check for EBGP. */
if (bgp != NULL && bgp_flag_check (bgp, BGP_FLAG_ENFORCE_FIRST_AS))
{
if (peer_sort (peer) == BGP_PEER_EBGP
&& ! aspath_firstas_check (attr->aspath, peer->as))
{
zlog (peer->log, LOG_ERR,
"%s incorrect first AS (must be %u)", peer->host, peer->as);
bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
return BGP_ATTR_PARSE_ERROR;
}
}
/* local-as prepend */
if (peer->change_local_as &&
! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
{
aspath = aspath_dup (attr->aspath);
aspath = aspath_add_seq (aspath, peer->change_local_as);
aspath_unintern (&attr->aspath);
attr->aspath = aspath_intern (aspath);
}
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_aspath_check (struct peer *const peer, struct attr *const attr)
{
/* These checks were part of bgp_attr_aspath, but with
* as4 we should to check aspath things when
* aspath synthesizing with as4_path has already taken place.
* Otherwise we check ASPATH and use the synthesized thing, and that is
* not right.
* So do the checks later, i.e. here
*/
struct bgp *bgp = peer->bgp;
struct aspath *aspath;
bgp = peer->bgp;
/* Confederation sanity check. */
if ((peer_sort (peer) == BGP_PEER_CONFED && ! aspath_left_confed_check (attr->aspath)) ||
(peer_sort (peer) == BGP_PEER_EBGP && aspath_confed_check (attr->aspath)))
{
zlog (peer->log, LOG_ERR, "Malformed AS path from %s", peer->host);
bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
return BGP_ATTR_PARSE_ERROR;
}
/* First AS check for EBGP. */
if (bgp != NULL && bgp_flag_check (bgp, BGP_FLAG_ENFORCE_FIRST_AS))
{
if (peer_sort (peer) == BGP_PEER_EBGP
&& ! aspath_firstas_check (attr->aspath, peer->as))
{
zlog (peer->log, LOG_ERR,
"%s incorrect first AS (must be %u)", peer->host, peer->as);
bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
return BGP_ATTR_PARSE_ERROR;
}
}
/* local-as prepend */
if (peer->change_local_as &&
! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
{
aspath = aspath_dup (attr->aspath);
aspath = aspath_add_seq (aspath, peer->change_local_as);
aspath_unintern (&attr->aspath);
attr->aspath = aspath_intern (aspath);
}
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
180
|
bgp_attr_atomic (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Length check. */
if (length != 0)
{
zlog (peer->log, LOG_ERR, "ATOMIC_AGGREGATE attribute length isn't 0 [%u]",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
/* Set atomic aggregate flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_atomic (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Length check. */
if (length != 0)
{
zlog (peer->log, LOG_ERR, "ATOMIC_AGGREGATE attribute length isn't 0 [%u]",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
/* Set atomic aggregate flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
181
|
bgp_attr_check (struct peer *peer, struct attr *attr)
{
u_char type = 0;
if (! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
type = BGP_ATTR_ORIGIN;
if (! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
type = BGP_ATTR_AS_PATH;
if (! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
type = BGP_ATTR_NEXT_HOP;
if (peer_sort (peer) == BGP_PEER_IBGP
&& ! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
type = BGP_ATTR_LOCAL_PREF;
if (type)
{
zlog (peer->log, LOG_WARNING,
"%s Missing well-known attribute %d.",
peer->host, type);
bgp_notify_send_with_data (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MISS_ATTR,
&type, 1);
return BGP_ATTR_PARSE_ERROR;
}
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_check (struct peer *peer, struct attr *attr)
{
u_char type = 0;
if (! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
type = BGP_ATTR_ORIGIN;
if (! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
type = BGP_ATTR_AS_PATH;
if (! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
type = BGP_ATTR_NEXT_HOP;
if (peer_sort (peer) == BGP_PEER_IBGP
&& ! CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
type = BGP_ATTR_LOCAL_PREF;
if (type)
{
zlog (peer->log, LOG_WARNING,
"%s Missing well-known attribute %d.",
peer->host, type);
bgp_notify_send_with_data (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MISS_ATTR,
&type, 1);
return BGP_ATTR_PARSE_ERROR;
}
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
182
|
bgp_attr_cluster_list (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Check length. */
if (length % 4)
{
zlog (peer->log, LOG_ERR, "Bad cluster list length %d", length);
return bgp_attr_malformed (args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
(bgp_attr_extra_get (attr))->cluster
= cluster_parse ((struct in_addr *)stream_pnt (peer->ibuf), length);
/* XXX: Fix cluster_parse to use stream API and then remove this */
stream_forward_getp (peer->ibuf, length);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_cluster_list (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Check length. */
if (length % 4)
{
zlog (peer->log, LOG_ERR, "Bad cluster list length %d", length);
return bgp_attr_malformed (args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
(bgp_attr_extra_get (attr))->cluster
= cluster_parse ((struct in_addr *)stream_pnt (peer->ibuf), length);
/* XXX: Fix cluster_parse to use stream API and then remove this */
stream_forward_getp (peer->ibuf, length);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
183
|
bgp_attr_default_intern (u_char origin)
{
struct attr attr;
struct attr *new;
memset (&attr, 0, sizeof (struct attr));
bgp_attr_extra_get (&attr);
bgp_attr_default_set(&attr, origin);
new = bgp_attr_intern (&attr);
bgp_attr_extra_free (&attr);
aspath_unintern (&new->aspath);
return new;
}
|
DoS
| 0
|
bgp_attr_default_intern (u_char origin)
{
struct attr attr;
struct attr *new;
memset (&attr, 0, sizeof (struct attr));
bgp_attr_extra_get (&attr);
bgp_attr_default_set(&attr, origin);
new = bgp_attr_intern (&attr);
bgp_attr_extra_free (&attr);
aspath_unintern (&new->aspath);
return new;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
184
|
bgp_attr_dup (struct attr *new, struct attr *orig)
{
*new = *orig;
if (orig->extra)
{
new->extra = bgp_attr_extra_new();
*new->extra = *orig->extra;
}
}
|
DoS
| 0
|
bgp_attr_dup (struct attr *new, struct attr *orig)
{
*new = *orig;
if (orig->extra)
{
new->extra = bgp_attr_extra_new();
*new->extra = *orig->extra;
}
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
185
|
bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
if (length == 0)
{
if (attr->extra)
attr->extra->ecommunity = NULL;
/* Empty extcomm doesn't seem to be invalid per se */
return BGP_ATTR_PARSE_PROCEED;
}
(bgp_attr_extra_get (attr))->ecommunity =
ecommunity_parse ((u_int8_t *)stream_pnt (peer->ibuf), length);
/* XXX: fix ecommunity_parse to use stream API */
stream_forward_getp (peer->ibuf, length);
if (!attr->extra->ecommunity)
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
if (length == 0)
{
if (attr->extra)
attr->extra->ecommunity = NULL;
/* Empty extcomm doesn't seem to be invalid per se */
return BGP_ATTR_PARSE_PROCEED;
}
(bgp_attr_extra_get (attr))->ecommunity =
ecommunity_parse ((u_int8_t *)stream_pnt (peer->ibuf), length);
/* XXX: fix ecommunity_parse to use stream API */
stream_forward_getp (peer->ibuf, length);
if (!attr->extra->ecommunity)
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
186
|
bgp_attr_extra_free (struct attr *attr)
{
if (attr->extra)
{
XFREE (MTYPE_ATTR_EXTRA, attr->extra);
attr->extra = NULL;
}
}
|
DoS
| 0
|
bgp_attr_extra_free (struct attr *attr)
{
if (attr->extra)
{
XFREE (MTYPE_ATTR_EXTRA, attr->extra);
attr->extra = NULL;
}
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
187
|
bgp_attr_extra_get (struct attr *attr)
{
if (!attr->extra)
attr->extra = bgp_attr_extra_new();
return attr->extra;
}
|
DoS
| 0
|
bgp_attr_extra_get (struct attr *attr)
{
if (!attr->extra)
attr->extra = bgp_attr_extra_new();
return attr->extra;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
188
|
bgp_attr_extra_new (void)
{
return XCALLOC (MTYPE_ATTR_EXTRA, sizeof (struct attr_extra));
}
|
DoS
| 0
|
bgp_attr_extra_new (void)
{
return XCALLOC (MTYPE_ATTR_EXTRA, sizeof (struct attr_extra));
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
189
|
bgp_attr_finish (void)
{
aspath_finish ();
attrhash_finish ();
community_finish ();
ecommunity_finish ();
cluster_finish ();
transit_finish ();
}
|
DoS
| 0
|
bgp_attr_finish (void)
{
aspath_finish ();
attrhash_finish ();
community_finish ();
ecommunity_finish ();
cluster_finish ();
transit_finish ();
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
190
|
bgp_attr_flag_invalid (struct bgp_attr_parser_args *args)
{
u_int8_t mask = BGP_ATTR_FLAG_EXTLEN;
const u_int8_t flags = args->flags;
const u_int8_t attr_code = args->type;
struct peer *const peer = args->peer;
/* there may be attributes we don't know about */
if (attr_code > attr_flags_values_max)
return 0;
if (attr_flags_values[attr_code] == 0)
return 0;
/* RFC4271, "For well-known attributes, the Transitive bit MUST be set to
* 1."
*/
if (!CHECK_FLAG (BGP_ATTR_FLAG_OPTIONAL, flags)
&& !CHECK_FLAG (BGP_ATTR_FLAG_TRANS, flags))
{
zlog (peer->log, LOG_ERR,
"%s well-known attributes must have transitive flag set (%x)",
LOOKUP (attr_str, attr_code), flags);
return 1;
}
/* "For well-known attributes and for optional non-transitive attributes,
* the Partial bit MUST be set to 0."
*/
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_PARTIAL))
{
if (!CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL))
{
zlog (peer->log, LOG_ERR,
"%s well-known attribute "
"must NOT have the partial flag set (%x)",
LOOKUP (attr_str, attr_code), flags);
return 1;
}
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL)
&& !CHECK_FLAG (flags, BGP_ATTR_FLAG_TRANS))
{
zlog (peer->log, LOG_ERR,
"%s optional + transitive attribute "
"must NOT have the partial flag set (%x)",
LOOKUP (attr_str, attr_code), flags);
return 1;
}
}
/* Optional transitive attributes may go through speakers that don't
* reocgnise them and set the Partial bit.
*/
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL)
&& CHECK_FLAG (flags, BGP_ATTR_FLAG_TRANS))
SET_FLAG (mask, BGP_ATTR_FLAG_PARTIAL);
if ((flags & ~mask)
== attr_flags_values[attr_code])
return 0;
bgp_attr_flags_diagnose (args, attr_flags_values[attr_code]);
return 1;
}
|
DoS
| 0
|
bgp_attr_flag_invalid (struct bgp_attr_parser_args *args)
{
u_int8_t mask = BGP_ATTR_FLAG_EXTLEN;
const u_int8_t flags = args->flags;
const u_int8_t attr_code = args->type;
struct peer *const peer = args->peer;
/* there may be attributes we don't know about */
if (attr_code > attr_flags_values_max)
return 0;
if (attr_flags_values[attr_code] == 0)
return 0;
/* RFC4271, "For well-known attributes, the Transitive bit MUST be set to
* 1."
*/
if (!CHECK_FLAG (BGP_ATTR_FLAG_OPTIONAL, flags)
&& !CHECK_FLAG (BGP_ATTR_FLAG_TRANS, flags))
{
zlog (peer->log, LOG_ERR,
"%s well-known attributes must have transitive flag set (%x)",
LOOKUP (attr_str, attr_code), flags);
return 1;
}
/* "For well-known attributes and for optional non-transitive attributes,
* the Partial bit MUST be set to 0."
*/
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_PARTIAL))
{
if (!CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL))
{
zlog (peer->log, LOG_ERR,
"%s well-known attribute "
"must NOT have the partial flag set (%x)",
LOOKUP (attr_str, attr_code), flags);
return 1;
}
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL)
&& !CHECK_FLAG (flags, BGP_ATTR_FLAG_TRANS))
{
zlog (peer->log, LOG_ERR,
"%s optional + transitive attribute "
"must NOT have the partial flag set (%x)",
LOOKUP (attr_str, attr_code), flags);
return 1;
}
}
/* Optional transitive attributes may go through speakers that don't
* reocgnise them and set the Partial bit.
*/
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL)
&& CHECK_FLAG (flags, BGP_ATTR_FLAG_TRANS))
SET_FLAG (mask, BGP_ATTR_FLAG_PARTIAL);
if ((flags & ~mask)
== attr_flags_values[attr_code])
return 0;
bgp_attr_flags_diagnose (args, attr_flags_values[attr_code]);
return 1;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
191
|
bgp_attr_hash_alloc (void *p)
{
struct attr * val = (struct attr *) p;
struct attr *attr;
attr = XMALLOC (MTYPE_ATTR, sizeof (struct attr));
*attr = *val;
if (val->extra)
{
attr->extra = bgp_attr_extra_new ();
*attr->extra = *val->extra;
}
attr->refcnt = 0;
return attr;
}
|
DoS
| 0
|
bgp_attr_hash_alloc (void *p)
{
struct attr * val = (struct attr *) p;
struct attr *attr;
attr = XMALLOC (MTYPE_ATTR, sizeof (struct attr));
*attr = *val;
if (val->extra)
{
attr->extra = bgp_attr_extra_new ();
*attr->extra = *val->extra;
}
attr->refcnt = 0;
return attr;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
192
|
bgp_attr_init (void)
{
aspath_init ();
attrhash_init ();
community_init ();
ecommunity_init ();
cluster_init ();
transit_init ();
}
|
DoS
| 0
|
bgp_attr_init (void)
{
aspath_init ();
attrhash_init ();
community_init ();
ecommunity_init ();
cluster_init ();
transit_init ();
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
193
|
bgp_attr_intern (struct attr *attr)
{
struct attr *find;
/* Intern referenced strucutre. */
if (attr->aspath)
{
if (! attr->aspath->refcnt)
attr->aspath = aspath_intern (attr->aspath);
else
attr->aspath->refcnt++;
}
if (attr->community)
{
if (! attr->community->refcnt)
attr->community = community_intern (attr->community);
else
attr->community->refcnt++;
}
if (attr->extra)
{
struct attr_extra *attre = attr->extra;
if (attre->ecommunity)
{
if (! attre->ecommunity->refcnt)
attre->ecommunity = ecommunity_intern (attre->ecommunity);
else
attre->ecommunity->refcnt++;
}
if (attre->cluster)
{
if (! attre->cluster->refcnt)
attre->cluster = cluster_intern (attre->cluster);
else
attre->cluster->refcnt++;
}
if (attre->transit)
{
if (! attre->transit->refcnt)
attre->transit = transit_intern (attre->transit);
else
attre->transit->refcnt++;
}
}
find = (struct attr *) hash_get (attrhash, attr, bgp_attr_hash_alloc);
find->refcnt++;
return find;
}
|
DoS
| 0
|
bgp_attr_intern (struct attr *attr)
{
struct attr *find;
/* Intern referenced strucutre. */
if (attr->aspath)
{
if (! attr->aspath->refcnt)
attr->aspath = aspath_intern (attr->aspath);
else
attr->aspath->refcnt++;
}
if (attr->community)
{
if (! attr->community->refcnt)
attr->community = community_intern (attr->community);
else
attr->community->refcnt++;
}
if (attr->extra)
{
struct attr_extra *attre = attr->extra;
if (attre->ecommunity)
{
if (! attre->ecommunity->refcnt)
attre->ecommunity = ecommunity_intern (attre->ecommunity);
else
attre->ecommunity->refcnt++;
}
if (attre->cluster)
{
if (! attre->cluster->refcnt)
attre->cluster = cluster_intern (attre->cluster);
else
attre->cluster->refcnt++;
}
if (attre->transit)
{
if (! attre->transit->refcnt)
attre->transit = transit_intern (attre->transit);
else
attre->transit->refcnt++;
}
}
find = (struct attr *) hash_get (attrhash, attr, bgp_attr_hash_alloc);
find->refcnt++;
return find;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
194
|
bgp_attr_local_pref (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Length check. */
if (length != 4)
{
zlog (peer->log, LOG_ERR, "LOCAL_PREF attribute length isn't 4 [%u]",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
/* If it is contained in an UPDATE message that is received from an
external peer, then this attribute MUST be ignored by the
receiving speaker. */
if (peer_sort (peer) == BGP_PEER_EBGP)
{
stream_forward_getp (peer->ibuf, length);
return BGP_ATTR_PARSE_PROCEED;
}
attr->local_pref = stream_getl (peer->ibuf);
/* Set atomic aggregate flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_local_pref (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Length check. */
if (length != 4)
{
zlog (peer->log, LOG_ERR, "LOCAL_PREF attribute length isn't 4 [%u]",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
/* If it is contained in an UPDATE message that is received from an
external peer, then this attribute MUST be ignored by the
receiving speaker. */
if (peer_sort (peer) == BGP_PEER_EBGP)
{
stream_forward_getp (peer->ibuf, length);
return BGP_ATTR_PARSE_PROCEED;
}
attr->local_pref = stream_getl (peer->ibuf);
/* Set atomic aggregate flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
195
|
bgp_attr_malformed (struct bgp_attr_parser_args *args, u_char subcode,
bgp_size_t length)
{
struct peer *const peer = args->peer;
const u_int8_t flags = args->flags;
/* startp and length must be special-cased, as whether or not to
* send the attribute data with the NOTIFY depends on the error,
* the caller therefore signals this with the seperate length argument
*/
u_char *notify_datap = (length > 0 ? args->startp : NULL);
/* Only relax error handling for eBGP peers */
if (peer_sort (peer) != BGP_PEER_EBGP)
{
bgp_notify_send_with_data (peer, BGP_NOTIFY_UPDATE_ERR, subcode,
notify_datap, length);
return BGP_ATTR_PARSE_ERROR;
}
/* Adjust the stream getp to the end of the attribute, in case we can
* still proceed but the caller hasn't read all the attribute.
*/
stream_set_getp (BGP_INPUT (peer),
(args->startp - STREAM_DATA (BGP_INPUT (peer)))
+ args->total);
switch (args->type) {
/* where an attribute is relatively inconsequential, e.g. it does not
* affect route selection, and can be safely ignored, then any such
* attributes which are malformed should just be ignored and the route
* processed as normal.
*/
case BGP_ATTR_AS4_AGGREGATOR:
case BGP_ATTR_AGGREGATOR:
case BGP_ATTR_ATOMIC_AGGREGATE:
return BGP_ATTR_PARSE_PROCEED;
/* Core attributes, particularly ones which may influence route
* selection, should always cause session resets
*/
case BGP_ATTR_ORIGIN:
case BGP_ATTR_AS_PATH:
case BGP_ATTR_NEXT_HOP:
case BGP_ATTR_MULTI_EXIT_DISC:
case BGP_ATTR_LOCAL_PREF:
case BGP_ATTR_COMMUNITIES:
case BGP_ATTR_ORIGINATOR_ID:
case BGP_ATTR_CLUSTER_LIST:
case BGP_ATTR_MP_REACH_NLRI:
case BGP_ATTR_MP_UNREACH_NLRI:
case BGP_ATTR_EXT_COMMUNITIES:
bgp_notify_send_with_data (peer, BGP_NOTIFY_UPDATE_ERR, subcode,
notify_datap, length);
return BGP_ATTR_PARSE_ERROR;
}
/* Partial optional attributes that are malformed should not cause
* the whole session to be reset. Instead treat it as a withdrawal
* of the routes, if possible.
*/
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_TRANS)
&& CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL)
&& CHECK_FLAG (flags, BGP_ATTR_FLAG_PARTIAL))
return BGP_ATTR_PARSE_WITHDRAW;
/* default to reset */
return BGP_ATTR_PARSE_ERROR;
}
|
DoS
| 0
|
bgp_attr_malformed (struct bgp_attr_parser_args *args, u_char subcode,
bgp_size_t length)
{
struct peer *const peer = args->peer;
const u_int8_t flags = args->flags;
/* startp and length must be special-cased, as whether or not to
* send the attribute data with the NOTIFY depends on the error,
* the caller therefore signals this with the seperate length argument
*/
u_char *notify_datap = (length > 0 ? args->startp : NULL);
/* Only relax error handling for eBGP peers */
if (peer_sort (peer) != BGP_PEER_EBGP)
{
bgp_notify_send_with_data (peer, BGP_NOTIFY_UPDATE_ERR, subcode,
notify_datap, length);
return BGP_ATTR_PARSE_ERROR;
}
/* Adjust the stream getp to the end of the attribute, in case we can
* still proceed but the caller hasn't read all the attribute.
*/
stream_set_getp (BGP_INPUT (peer),
(args->startp - STREAM_DATA (BGP_INPUT (peer)))
+ args->total);
switch (args->type) {
/* where an attribute is relatively inconsequential, e.g. it does not
* affect route selection, and can be safely ignored, then any such
* attributes which are malformed should just be ignored and the route
* processed as normal.
*/
case BGP_ATTR_AS4_AGGREGATOR:
case BGP_ATTR_AGGREGATOR:
case BGP_ATTR_ATOMIC_AGGREGATE:
return BGP_ATTR_PARSE_PROCEED;
/* Core attributes, particularly ones which may influence route
* selection, should always cause session resets
*/
case BGP_ATTR_ORIGIN:
case BGP_ATTR_AS_PATH:
case BGP_ATTR_NEXT_HOP:
case BGP_ATTR_MULTI_EXIT_DISC:
case BGP_ATTR_LOCAL_PREF:
case BGP_ATTR_COMMUNITIES:
case BGP_ATTR_ORIGINATOR_ID:
case BGP_ATTR_CLUSTER_LIST:
case BGP_ATTR_MP_REACH_NLRI:
case BGP_ATTR_MP_UNREACH_NLRI:
case BGP_ATTR_EXT_COMMUNITIES:
bgp_notify_send_with_data (peer, BGP_NOTIFY_UPDATE_ERR, subcode,
notify_datap, length);
return BGP_ATTR_PARSE_ERROR;
}
/* Partial optional attributes that are malformed should not cause
* the whole session to be reset. Instead treat it as a withdrawal
* of the routes, if possible.
*/
if (CHECK_FLAG (flags, BGP_ATTR_FLAG_TRANS)
&& CHECK_FLAG (flags, BGP_ATTR_FLAG_OPTIONAL)
&& CHECK_FLAG (flags, BGP_ATTR_FLAG_PARTIAL))
return BGP_ATTR_PARSE_WITHDRAW;
/* default to reset */
return BGP_ATTR_PARSE_ERROR;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
196
|
bgp_attr_med (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Length check. */
if (length != 4)
{
zlog (peer->log, LOG_ERR,
"MED attribute length isn't four [%d]", length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
attr->med = stream_getl (peer->ibuf);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_med (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* Length check. */
if (length != 4)
{
zlog (peer->log, LOG_ERR,
"MED attribute length isn't four [%d]", length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
attr->med = stream_getl (peer->ibuf);
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
197
|
bgp_attr_munge_as4_attrs (struct peer *const peer,
struct attr *const attr,
struct aspath *as4_path, as_t as4_aggregator,
struct in_addr *as4_aggregator_addr)
{
int ignore_as4_path = 0;
struct aspath *newpath;
struct attr_extra *attre = attr->extra;
if (CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV))
{
/* peer can do AS4, so we ignore AS4_PATH and AS4_AGGREGATOR
* if given.
* It is worth a warning though, because the peer really
* should not send them
*/
if (BGP_DEBUG(as4, AS4))
{
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS4_PATH)))
zlog_debug ("[AS4] %s %s AS4_PATH",
peer->host, "AS4 capable peer, yet it sent");
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS4_AGGREGATOR)))
zlog_debug ("[AS4] %s %s AS4_AGGREGATOR",
peer->host, "AS4 capable peer, yet it sent");
}
return BGP_ATTR_PARSE_PROCEED;
}
/* We have a asn16 peer. First, look for AS4_AGGREGATOR
* because that may override AS4_PATH
*/
if (attr->flag & (ATTR_FLAG_BIT (BGP_ATTR_AS4_AGGREGATOR) ) )
{
if (attr->flag & (ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR) ) )
{
assert (attre);
/* received both.
* if the as_number in aggregator is not AS_TRANS,
* then AS4_AGGREGATOR and AS4_PATH shall be ignored
* and the Aggregator shall be taken as
* info on the aggregating node, and the AS_PATH
* shall be taken as the AS_PATH
* otherwise
* the Aggregator shall be ignored and the
* AS4_AGGREGATOR shall be taken as the
* Aggregating node and the AS_PATH is to be
* constructed "as in all other cases"
*/
if (attre->aggregator_as != BGP_AS_TRANS)
{
/* ignore */
if ( BGP_DEBUG(as4, AS4))
zlog_debug ("[AS4] %s BGP not AS4 capable peer"
" send AGGREGATOR != AS_TRANS and"
" AS4_AGGREGATOR, so ignore"
" AS4_AGGREGATOR and AS4_PATH", peer->host);
ignore_as4_path = 1;
}
else
{
/* "New_aggregator shall be taken as aggregator" */
attre->aggregator_as = as4_aggregator;
attre->aggregator_addr.s_addr = as4_aggregator_addr->s_addr;
}
}
else
{
/* We received a AS4_AGGREGATOR but no AGGREGATOR.
* That is bogus - but reading the conditions
* we have to handle AS4_AGGREGATOR as if it were
* AGGREGATOR in that case
*/
if ( BGP_DEBUG(as4, AS4))
zlog_debug ("[AS4] %s BGP not AS4 capable peer send"
" AS4_AGGREGATOR but no AGGREGATOR, will take"
" it as if AGGREGATOR with AS_TRANS had been there", peer->host);
(attre = bgp_attr_extra_get (attr))->aggregator_as = as4_aggregator;
/* sweep it under the carpet and simulate a "good" AGGREGATOR */
attr->flag |= (ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR));
}
}
/* need to reconcile NEW_AS_PATH and AS_PATH */
if (!ignore_as4_path && (attr->flag & (ATTR_FLAG_BIT( BGP_ATTR_AS4_PATH))))
{
newpath = aspath_reconcile_as4 (attr->aspath, as4_path);
aspath_unintern (&attr->aspath);
attr->aspath = aspath_intern (newpath);
}
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_munge_as4_attrs (struct peer *const peer,
struct attr *const attr,
struct aspath *as4_path, as_t as4_aggregator,
struct in_addr *as4_aggregator_addr)
{
int ignore_as4_path = 0;
struct aspath *newpath;
struct attr_extra *attre = attr->extra;
if (CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV))
{
/* peer can do AS4, so we ignore AS4_PATH and AS4_AGGREGATOR
* if given.
* It is worth a warning though, because the peer really
* should not send them
*/
if (BGP_DEBUG(as4, AS4))
{
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS4_PATH)))
zlog_debug ("[AS4] %s %s AS4_PATH",
peer->host, "AS4 capable peer, yet it sent");
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS4_AGGREGATOR)))
zlog_debug ("[AS4] %s %s AS4_AGGREGATOR",
peer->host, "AS4 capable peer, yet it sent");
}
return BGP_ATTR_PARSE_PROCEED;
}
/* We have a asn16 peer. First, look for AS4_AGGREGATOR
* because that may override AS4_PATH
*/
if (attr->flag & (ATTR_FLAG_BIT (BGP_ATTR_AS4_AGGREGATOR) ) )
{
if (attr->flag & (ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR) ) )
{
assert (attre);
/* received both.
* if the as_number in aggregator is not AS_TRANS,
* then AS4_AGGREGATOR and AS4_PATH shall be ignored
* and the Aggregator shall be taken as
* info on the aggregating node, and the AS_PATH
* shall be taken as the AS_PATH
* otherwise
* the Aggregator shall be ignored and the
* AS4_AGGREGATOR shall be taken as the
* Aggregating node and the AS_PATH is to be
* constructed "as in all other cases"
*/
if (attre->aggregator_as != BGP_AS_TRANS)
{
/* ignore */
if ( BGP_DEBUG(as4, AS4))
zlog_debug ("[AS4] %s BGP not AS4 capable peer"
" send AGGREGATOR != AS_TRANS and"
" AS4_AGGREGATOR, so ignore"
" AS4_AGGREGATOR and AS4_PATH", peer->host);
ignore_as4_path = 1;
}
else
{
/* "New_aggregator shall be taken as aggregator" */
attre->aggregator_as = as4_aggregator;
attre->aggregator_addr.s_addr = as4_aggregator_addr->s_addr;
}
}
else
{
/* We received a AS4_AGGREGATOR but no AGGREGATOR.
* That is bogus - but reading the conditions
* we have to handle AS4_AGGREGATOR as if it were
* AGGREGATOR in that case
*/
if ( BGP_DEBUG(as4, AS4))
zlog_debug ("[AS4] %s BGP not AS4 capable peer send"
" AS4_AGGREGATOR but no AGGREGATOR, will take"
" it as if AGGREGATOR with AS_TRANS had been there", peer->host);
(attre = bgp_attr_extra_get (attr))->aggregator_as = as4_aggregator;
/* sweep it under the carpet and simulate a "good" AGGREGATOR */
attr->flag |= (ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR));
}
}
/* need to reconcile NEW_AS_PATH and AS_PATH */
if (!ignore_as4_path && (attr->flag & (ATTR_FLAG_BIT( BGP_ATTR_AS4_PATH))))
{
newpath = aspath_reconcile_as4 (attr->aspath, as4_path);
aspath_unintern (&attr->aspath);
attr->aspath = aspath_intern (newpath);
}
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
198
|
bgp_attr_origin (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* If any recognized attribute has Attribute Length that conflicts
with the expected length (based on the attribute type code), then
the Error Subcode is set to Attribute Length Error. The Data
field contains the erroneous attribute (type, length and
value). */
if (length != 1)
{
zlog (peer->log, LOG_ERR, "Origin attribute length is not one %d",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
/* Fetch origin attribute. */
attr->origin = stream_getc (BGP_INPUT (peer));
/* If the ORIGIN attribute has an undefined value, then the Error
Subcode is set to Invalid Origin Attribute. The Data field
contains the unrecognized attribute (type, length and value). */
if ((attr->origin != BGP_ORIGIN_IGP)
&& (attr->origin != BGP_ORIGIN_EGP)
&& (attr->origin != BGP_ORIGIN_INCOMPLETE))
{
zlog (peer->log, LOG_ERR, "Origin attribute value is invalid %d",
attr->origin);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_INVAL_ORIGIN,
args->total);
}
/* Set oring attribute flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGIN);
return 0;
}
|
DoS
| 0
|
bgp_attr_origin (struct bgp_attr_parser_args *args)
{
struct peer *const peer = args->peer;
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
/* If any recognized attribute has Attribute Length that conflicts
with the expected length (based on the attribute type code), then
the Error Subcode is set to Attribute Length Error. The Data
field contains the erroneous attribute (type, length and
value). */
if (length != 1)
{
zlog (peer->log, LOG_ERR, "Origin attribute length is not one %d",
length);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
/* Fetch origin attribute. */
attr->origin = stream_getc (BGP_INPUT (peer));
/* If the ORIGIN attribute has an undefined value, then the Error
Subcode is set to Invalid Origin Attribute. The Data field
contains the unrecognized attribute (type, length and value). */
if ((attr->origin != BGP_ORIGIN_IGP)
&& (attr->origin != BGP_ORIGIN_EGP)
&& (attr->origin != BGP_ORIGIN_INCOMPLETE))
{
zlog (peer->log, LOG_ERR, "Origin attribute value is invalid %d",
attr->origin);
return bgp_attr_malformed (args,
BGP_NOTIFY_UPDATE_INVAL_ORIGIN,
args->total);
}
/* Set oring attribute flag. */
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGIN);
return 0;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
199
|
bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,
struct bgp_nlri *mp_update, struct bgp_nlri *mp_withdraw)
{
int ret;
u_char flag = 0;
u_char type = 0;
bgp_size_t length;
u_char *startp, *endp;
u_char *attr_endp;
u_char seen[BGP_ATTR_BITMAP_SIZE];
/* we need the as4_path only until we have synthesized the as_path with it */
/* same goes for as4_aggregator */
struct aspath *as4_path = NULL;
as_t as4_aggregator = 0;
struct in_addr as4_aggregator_addr = { 0 };
/* Initialize bitmap. */
memset (seen, 0, BGP_ATTR_BITMAP_SIZE);
/* End pointer of BGP attribute. */
endp = BGP_INPUT_PNT (peer) + size;
/* Get attributes to the end of attribute length. */
while (BGP_INPUT_PNT (peer) < endp)
{
/* Check remaining length check.*/
if (endp - BGP_INPUT_PNT (peer) < BGP_ATTR_MIN_LEN)
{
/* XXX warning: long int format, int arg (arg 5) */
zlog (peer->log, LOG_WARNING,
"%s: error BGP attribute length %lu is smaller than min len",
peer->host,
(unsigned long) (endp - STREAM_PNT (BGP_INPUT (peer))));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
return BGP_ATTR_PARSE_ERROR;
}
/* Fetch attribute flag and type. */
startp = BGP_INPUT_PNT (peer);
/* "The lower-order four bits of the Attribute Flags octet are
unused. They MUST be zero when sent and MUST be ignored when
received." */
flag = 0xF0 & stream_getc (BGP_INPUT (peer));
type = stream_getc (BGP_INPUT (peer));
/* Check whether Extended-Length applies and is in bounds */
if (CHECK_FLAG (flag, BGP_ATTR_FLAG_EXTLEN)
&& ((endp - startp) < (BGP_ATTR_MIN_LEN + 1)))
{
zlog (peer->log, LOG_WARNING,
"%s: Extended length set, but just %lu bytes of attr header",
peer->host,
(unsigned long) (endp - STREAM_PNT (BGP_INPUT (peer))));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
return BGP_ATTR_PARSE_ERROR;
}
/* Check extended attribue length bit. */
if (CHECK_FLAG (flag, BGP_ATTR_FLAG_EXTLEN))
length = stream_getw (BGP_INPUT (peer));
else
length = stream_getc (BGP_INPUT (peer));
/* If any attribute appears more than once in the UPDATE
message, then the Error Subcode is set to Malformed Attribute
List. */
if (CHECK_BITMAP (seen, type))
{
zlog (peer->log, LOG_WARNING,
"%s: error BGP attribute type %d appears twice in a message",
peer->host, type);
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_ATTR);
return BGP_ATTR_PARSE_ERROR;
}
/* Set type to bitmap to check duplicate attribute. `type' is
unsigned char so it never overflow bitmap range. */
SET_BITMAP (seen, type);
/* Overflow check. */
attr_endp = BGP_INPUT_PNT (peer) + length;
if (attr_endp > endp)
{
zlog (peer->log, LOG_WARNING,
"%s: BGP type %d length %d is too large, attribute total length is %d. attr_endp is %p. endp is %p", peer->host, type, length, size, attr_endp, endp);
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
return BGP_ATTR_PARSE_ERROR;
}
struct bgp_attr_parser_args attr_args = {
.peer = peer,
.length = length,
.attr = attr,
.type = type,
.flags = flag,
.startp = startp,
.total = attr_endp - startp,
};
/* If any recognized attribute has Attribute Flags that conflict
with the Attribute Type Code, then the Error Subcode is set to
Attribute Flags Error. The Data field contains the erroneous
attribute (type, length and value). */
if (bgp_attr_flag_invalid (&attr_args))
{
bgp_attr_parse_ret_t ret;
ret = bgp_attr_malformed (&attr_args,
BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR,
attr_args.total);
if (ret == BGP_ATTR_PARSE_PROCEED)
continue;
return ret;
}
/* OK check attribute and store it's value. */
switch (type)
{
case BGP_ATTR_ORIGIN:
ret = bgp_attr_origin (&attr_args);
break;
case BGP_ATTR_AS_PATH:
ret = bgp_attr_aspath (&attr_args);
break;
case BGP_ATTR_AS4_PATH:
ret = bgp_attr_as4_path (&attr_args, &as4_path);
break;
case BGP_ATTR_NEXT_HOP:
ret = bgp_attr_nexthop (&attr_args);
break;
case BGP_ATTR_MULTI_EXIT_DISC:
ret = bgp_attr_med (&attr_args);
break;
case BGP_ATTR_LOCAL_PREF:
ret = bgp_attr_local_pref (&attr_args);
break;
case BGP_ATTR_ATOMIC_AGGREGATE:
ret = bgp_attr_atomic (&attr_args);
break;
case BGP_ATTR_AGGREGATOR:
ret = bgp_attr_aggregator (&attr_args);
break;
case BGP_ATTR_AS4_AGGREGATOR:
ret = bgp_attr_as4_aggregator (&attr_args,
&as4_aggregator,
&as4_aggregator_addr);
break;
case BGP_ATTR_COMMUNITIES:
ret = bgp_attr_community (&attr_args);
break;
case BGP_ATTR_ORIGINATOR_ID:
ret = bgp_attr_originator_id (&attr_args);
break;
case BGP_ATTR_CLUSTER_LIST:
ret = bgp_attr_cluster_list (&attr_args);
break;
case BGP_ATTR_MP_REACH_NLRI:
ret = bgp_mp_reach_parse (&attr_args, mp_update);
break;
case BGP_ATTR_MP_UNREACH_NLRI:
ret = bgp_mp_unreach_parse (&attr_args, mp_withdraw);
break;
case BGP_ATTR_EXT_COMMUNITIES:
ret = bgp_attr_ext_communities (&attr_args);
break;
default:
ret = bgp_attr_unknown (&attr_args);
break;
}
/* If hard error occured immediately return to the caller. */
if (ret == BGP_ATTR_PARSE_ERROR)
{
zlog (peer->log, LOG_WARNING,
"%s: Attribute %s, parse error",
peer->host,
LOOKUP (attr_str, type));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_ATTR);
if (as4_path)
aspath_unintern (&as4_path);
return ret;
}
if (ret == BGP_ATTR_PARSE_WITHDRAW)
{
zlog (peer->log, LOG_WARNING,
"%s: Attribute %s, parse error - treating as withdrawal",
peer->host,
LOOKUP (attr_str, type));
if (as4_path)
aspath_unintern (&as4_path);
return ret;
}
/* Check the fetched length. */
if (BGP_INPUT_PNT (peer) != attr_endp)
{
zlog (peer->log, LOG_WARNING,
"%s: BGP attribute %s, fetch error",
peer->host, LOOKUP (attr_str, type));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
if (as4_path)
aspath_unintern (&as4_path);
return BGP_ATTR_PARSE_ERROR;
}
}
/* Check final read pointer is same as end pointer. */
if (BGP_INPUT_PNT (peer) != endp)
{
zlog (peer->log, LOG_WARNING,
"%s: BGP attribute %s, length mismatch",
peer->host, LOOKUP (attr_str, type));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
if (as4_path)
aspath_unintern (&as4_path);
return BGP_ATTR_PARSE_ERROR;
}
/*
* At this place we can see whether we got AS4_PATH and/or
* AS4_AGGREGATOR from a 16Bit peer and act accordingly.
* We can not do this before we've read all attributes because
* the as4 handling does not say whether AS4_PATH has to be sent
* after AS_PATH or not - and when AS4_AGGREGATOR will be send
* in relationship to AGGREGATOR.
* So, to be defensive, we are not relying on any order and read
* all attributes first, including these 32bit ones, and now,
* afterwards, we look what and if something is to be done for as4.
*/
if (bgp_attr_munge_as4_attrs (peer, attr, as4_path,
as4_aggregator, &as4_aggregator_addr))
{
if (as4_path)
aspath_unintern (&as4_path);
return BGP_ATTR_PARSE_ERROR;
}
/* At this stage, we have done all fiddling with as4, and the
* resulting info is in attr->aggregator resp. attr->aspath
* so we can chuck as4_aggregator and as4_path alltogether in
* order to save memory
*/
if (as4_path)
{
aspath_unintern (&as4_path); /* unintern - it is in the hash */
/* The flag that we got this is still there, but that does not
* do any trouble
*/
}
/*
* The "rest" of the code does nothing with as4_aggregator.
* there is no memory attached specifically which is not part
* of the attr.
* so ignoring just means do nothing.
*/
/*
* Finally do the checks on the aspath we did not do yet
* because we waited for a potentially synthesized aspath.
*/
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
{
ret = bgp_attr_aspath_check (peer, attr);
if (ret != BGP_ATTR_PARSE_PROCEED)
return ret;
}
/* Finally intern unknown attribute. */
if (attr->extra && attr->extra->transit)
attr->extra->transit = transit_intern (attr->extra->transit);
return BGP_ATTR_PARSE_PROCEED;
}
|
DoS
| 0
|
bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size,
struct bgp_nlri *mp_update, struct bgp_nlri *mp_withdraw)
{
int ret;
u_char flag = 0;
u_char type = 0;
bgp_size_t length;
u_char *startp, *endp;
u_char *attr_endp;
u_char seen[BGP_ATTR_BITMAP_SIZE];
/* we need the as4_path only until we have synthesized the as_path with it */
/* same goes for as4_aggregator */
struct aspath *as4_path = NULL;
as_t as4_aggregator = 0;
struct in_addr as4_aggregator_addr = { 0 };
/* Initialize bitmap. */
memset (seen, 0, BGP_ATTR_BITMAP_SIZE);
/* End pointer of BGP attribute. */
endp = BGP_INPUT_PNT (peer) + size;
/* Get attributes to the end of attribute length. */
while (BGP_INPUT_PNT (peer) < endp)
{
/* Check remaining length check.*/
if (endp - BGP_INPUT_PNT (peer) < BGP_ATTR_MIN_LEN)
{
/* XXX warning: long int format, int arg (arg 5) */
zlog (peer->log, LOG_WARNING,
"%s: error BGP attribute length %lu is smaller than min len",
peer->host,
(unsigned long) (endp - STREAM_PNT (BGP_INPUT (peer))));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
return BGP_ATTR_PARSE_ERROR;
}
/* Fetch attribute flag and type. */
startp = BGP_INPUT_PNT (peer);
/* "The lower-order four bits of the Attribute Flags octet are
unused. They MUST be zero when sent and MUST be ignored when
received." */
flag = 0xF0 & stream_getc (BGP_INPUT (peer));
type = stream_getc (BGP_INPUT (peer));
/* Check whether Extended-Length applies and is in bounds */
if (CHECK_FLAG (flag, BGP_ATTR_FLAG_EXTLEN)
&& ((endp - startp) < (BGP_ATTR_MIN_LEN + 1)))
{
zlog (peer->log, LOG_WARNING,
"%s: Extended length set, but just %lu bytes of attr header",
peer->host,
(unsigned long) (endp - STREAM_PNT (BGP_INPUT (peer))));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
return BGP_ATTR_PARSE_ERROR;
}
/* Check extended attribue length bit. */
if (CHECK_FLAG (flag, BGP_ATTR_FLAG_EXTLEN))
length = stream_getw (BGP_INPUT (peer));
else
length = stream_getc (BGP_INPUT (peer));
/* If any attribute appears more than once in the UPDATE
message, then the Error Subcode is set to Malformed Attribute
List. */
if (CHECK_BITMAP (seen, type))
{
zlog (peer->log, LOG_WARNING,
"%s: error BGP attribute type %d appears twice in a message",
peer->host, type);
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_ATTR);
return BGP_ATTR_PARSE_ERROR;
}
/* Set type to bitmap to check duplicate attribute. `type' is
unsigned char so it never overflow bitmap range. */
SET_BITMAP (seen, type);
/* Overflow check. */
attr_endp = BGP_INPUT_PNT (peer) + length;
if (attr_endp > endp)
{
zlog (peer->log, LOG_WARNING,
"%s: BGP type %d length %d is too large, attribute total length is %d. attr_endp is %p. endp is %p", peer->host, type, length, size, attr_endp, endp);
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
return BGP_ATTR_PARSE_ERROR;
}
struct bgp_attr_parser_args attr_args = {
.peer = peer,
.length = length,
.attr = attr,
.type = type,
.flags = flag,
.startp = startp,
.total = attr_endp - startp,
};
/* If any recognized attribute has Attribute Flags that conflict
with the Attribute Type Code, then the Error Subcode is set to
Attribute Flags Error. The Data field contains the erroneous
attribute (type, length and value). */
if (bgp_attr_flag_invalid (&attr_args))
{
bgp_attr_parse_ret_t ret;
ret = bgp_attr_malformed (&attr_args,
BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR,
attr_args.total);
if (ret == BGP_ATTR_PARSE_PROCEED)
continue;
return ret;
}
/* OK check attribute and store it's value. */
switch (type)
{
case BGP_ATTR_ORIGIN:
ret = bgp_attr_origin (&attr_args);
break;
case BGP_ATTR_AS_PATH:
ret = bgp_attr_aspath (&attr_args);
break;
case BGP_ATTR_AS4_PATH:
ret = bgp_attr_as4_path (&attr_args, &as4_path);
break;
case BGP_ATTR_NEXT_HOP:
ret = bgp_attr_nexthop (&attr_args);
break;
case BGP_ATTR_MULTI_EXIT_DISC:
ret = bgp_attr_med (&attr_args);
break;
case BGP_ATTR_LOCAL_PREF:
ret = bgp_attr_local_pref (&attr_args);
break;
case BGP_ATTR_ATOMIC_AGGREGATE:
ret = bgp_attr_atomic (&attr_args);
break;
case BGP_ATTR_AGGREGATOR:
ret = bgp_attr_aggregator (&attr_args);
break;
case BGP_ATTR_AS4_AGGREGATOR:
ret = bgp_attr_as4_aggregator (&attr_args,
&as4_aggregator,
&as4_aggregator_addr);
break;
case BGP_ATTR_COMMUNITIES:
ret = bgp_attr_community (&attr_args);
break;
case BGP_ATTR_ORIGINATOR_ID:
ret = bgp_attr_originator_id (&attr_args);
break;
case BGP_ATTR_CLUSTER_LIST:
ret = bgp_attr_cluster_list (&attr_args);
break;
case BGP_ATTR_MP_REACH_NLRI:
ret = bgp_mp_reach_parse (&attr_args, mp_update);
break;
case BGP_ATTR_MP_UNREACH_NLRI:
ret = bgp_mp_unreach_parse (&attr_args, mp_withdraw);
break;
case BGP_ATTR_EXT_COMMUNITIES:
ret = bgp_attr_ext_communities (&attr_args);
break;
default:
ret = bgp_attr_unknown (&attr_args);
break;
}
/* If hard error occured immediately return to the caller. */
if (ret == BGP_ATTR_PARSE_ERROR)
{
zlog (peer->log, LOG_WARNING,
"%s: Attribute %s, parse error",
peer->host,
LOOKUP (attr_str, type));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_ATTR);
if (as4_path)
aspath_unintern (&as4_path);
return ret;
}
if (ret == BGP_ATTR_PARSE_WITHDRAW)
{
zlog (peer->log, LOG_WARNING,
"%s: Attribute %s, parse error - treating as withdrawal",
peer->host,
LOOKUP (attr_str, type));
if (as4_path)
aspath_unintern (&as4_path);
return ret;
}
/* Check the fetched length. */
if (BGP_INPUT_PNT (peer) != attr_endp)
{
zlog (peer->log, LOG_WARNING,
"%s: BGP attribute %s, fetch error",
peer->host, LOOKUP (attr_str, type));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
if (as4_path)
aspath_unintern (&as4_path);
return BGP_ATTR_PARSE_ERROR;
}
}
/* Check final read pointer is same as end pointer. */
if (BGP_INPUT_PNT (peer) != endp)
{
zlog (peer->log, LOG_WARNING,
"%s: BGP attribute %s, length mismatch",
peer->host, LOOKUP (attr_str, type));
bgp_notify_send (peer,
BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
if (as4_path)
aspath_unintern (&as4_path);
return BGP_ATTR_PARSE_ERROR;
}
/*
* At this place we can see whether we got AS4_PATH and/or
* AS4_AGGREGATOR from a 16Bit peer and act accordingly.
* We can not do this before we've read all attributes because
* the as4 handling does not say whether AS4_PATH has to be sent
* after AS_PATH or not - and when AS4_AGGREGATOR will be send
* in relationship to AGGREGATOR.
* So, to be defensive, we are not relying on any order and read
* all attributes first, including these 32bit ones, and now,
* afterwards, we look what and if something is to be done for as4.
*/
if (bgp_attr_munge_as4_attrs (peer, attr, as4_path,
as4_aggregator, &as4_aggregator_addr))
{
if (as4_path)
aspath_unintern (&as4_path);
return BGP_ATTR_PARSE_ERROR;
}
/* At this stage, we have done all fiddling with as4, and the
* resulting info is in attr->aggregator resp. attr->aspath
* so we can chuck as4_aggregator and as4_path alltogether in
* order to save memory
*/
if (as4_path)
{
aspath_unintern (&as4_path); /* unintern - it is in the hash */
/* The flag that we got this is still there, but that does not
* do any trouble
*/
}
/*
* The "rest" of the code does nothing with as4_aggregator.
* there is no memory attached specifically which is not part
* of the attr.
* so ignoring just means do nothing.
*/
/*
* Finally do the checks on the aspath we did not do yet
* because we waited for a potentially synthesized aspath.
*/
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
{
ret = bgp_attr_aspath_check (peer, attr);
if (ret != BGP_ATTR_PARSE_PROCEED)
return ret;
}
/* Finally intern unknown attribute. */
if (attr->extra && attr->extra->transit)
attr->extra->transit = transit_intern (attr->extra->transit);
return BGP_ATTR_PARSE_PROCEED;
}
|
@@ -1646,7 +1646,7 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
static bgp_attr_parse_ret_t
bgp_attr_unknown (struct bgp_attr_parser_args *args)
{
- bgp_size_t total;
+ bgp_size_t total = args->total;
struct transit *transit;
struct attr_extra *attre;
struct peer *const peer = args->peer;
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.