idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
17,500 | void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
{
drm_mode_object_put(dev, &mode->base);
kfree(mode);
}
| DoS Overflow +Priv Mem. Corr. | 0 | void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
{
drm_mode_object_put(dev, &mode->base);
kfree(mode);
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,501 | int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_destroy_dumb *args = data;
if (!dev->driver->dumb_destroy)
return -ENOSYS;
return dev->driver->dumb_destroy(file_priv, dev, args->handle);
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_destroy_dumb *args = data;
if (!dev->driver->dumb_destroy)
return -ENOSYS;
return dev->driver->dumb_destroy(file_priv, dev, args->handle);
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,502 | static int drm_mode_detachmode(struct drm_device *dev,
struct drm_connector *connector,
struct drm_display_mode *mode)
{
int found = 0;
int ret = 0;
struct drm_display_mode *match_mode, *t;
list_for_each_entry_safe(match_mode, t, &connector->user_modes, head) {
if (drm_mode_equal(match_mode, mode)) {
list_del(&match_mode->head);
drm_mode_destroy(dev, match_mode);
found = 1;
break;
}
}
if (!found)
ret = -EINVAL;
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | static int drm_mode_detachmode(struct drm_device *dev,
struct drm_connector *connector,
struct drm_display_mode *mode)
{
int found = 0;
int ret = 0;
struct drm_display_mode *match_mode, *t;
list_for_each_entry_safe(match_mode, t, &connector->user_modes, head) {
if (drm_mode_equal(match_mode, mode)) {
list_del(&match_mode->head);
drm_mode_destroy(dev, match_mode);
found = 1;
break;
}
}
if (!found)
ret = -EINVAL;
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,503 | int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode)
{
struct drm_connector *connector;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
drm_mode_detachmode(dev, connector, mode);
}
return 0;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode)
{
struct drm_connector *connector;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
drm_mode_detachmode(dev, connector, mode);
}
return 0;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,504 | int drm_mode_detachmode_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_object *obj;
struct drm_mode_mode_cmd *mode_cmd = data;
struct drm_connector *connector;
struct drm_display_mode mode;
struct drm_mode_modeinfo *umode = &mode_cmd->mode;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
if (!obj) {
ret = -EINVAL;
goto out;
}
connector = obj_to_connector(obj);
drm_crtc_convert_umode(&mode, umode);
ret = drm_mode_detachmode(dev, connector, &mode);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_detachmode_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_object *obj;
struct drm_mode_mode_cmd *mode_cmd = data;
struct drm_connector *connector;
struct drm_display_mode mode;
struct drm_mode_modeinfo *umode = &mode_cmd->mode;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
if (!obj) {
ret = -EINVAL;
goto out;
}
connector = obj_to_connector(obj);
drm_crtc_convert_umode(&mode, umode);
ret = drm_mode_detachmode(dev, connector, &mode);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,505 | int drm_mode_gamma_get_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc_lut *crtc_lut = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc;
void *r_base, *g_base, *b_base;
int size;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
if (!obj) {
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
/* memcpy into gamma store */
if (crtc_lut->gamma_size != crtc->gamma_size) {
ret = -EINVAL;
goto out;
}
size = crtc_lut->gamma_size * (sizeof(uint16_t));
r_base = crtc->gamma_store;
if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
ret = -EFAULT;
goto out;
}
g_base = r_base + size;
if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
ret = -EFAULT;
goto out;
}
b_base = g_base + size;
if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
ret = -EFAULT;
goto out;
}
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_gamma_get_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc_lut *crtc_lut = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc;
void *r_base, *g_base, *b_base;
int size;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
if (!obj) {
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
/* memcpy into gamma store */
if (crtc_lut->gamma_size != crtc->gamma_size) {
ret = -EINVAL;
goto out;
}
size = crtc_lut->gamma_size * (sizeof(uint16_t));
r_base = crtc->gamma_store;
if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
ret = -EFAULT;
goto out;
}
g_base = r_base + size;
if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
ret = -EFAULT;
goto out;
}
b_base = g_base + size;
if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
ret = -EFAULT;
goto out;
}
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,506 | int drm_mode_gamma_set_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc_lut *crtc_lut = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc;
void *r_base, *g_base, *b_base;
int size;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
if (!obj) {
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
/* memcpy into gamma store */
if (crtc_lut->gamma_size != crtc->gamma_size) {
ret = -EINVAL;
goto out;
}
size = crtc_lut->gamma_size * (sizeof(uint16_t));
r_base = crtc->gamma_store;
if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
ret = -EFAULT;
goto out;
}
g_base = r_base + size;
if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
ret = -EFAULT;
goto out;
}
b_base = g_base + size;
if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
ret = -EFAULT;
goto out;
}
crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_gamma_set_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc_lut *crtc_lut = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc;
void *r_base, *g_base, *b_base;
int size;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
if (!obj) {
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
/* memcpy into gamma store */
if (crtc_lut->gamma_size != crtc->gamma_size) {
ret = -EINVAL;
goto out;
}
size = crtc_lut->gamma_size * (sizeof(uint16_t));
r_base = crtc->gamma_store;
if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
ret = -EFAULT;
goto out;
}
g_base = r_base + size;
if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
ret = -EFAULT;
goto out;
}
b_base = g_base + size;
if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
ret = -EFAULT;
goto out;
}
crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,507 | int drm_mode_getblob_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_object *obj;
struct drm_mode_get_blob *out_resp = data;
struct drm_property_blob *blob;
int ret = 0;
void *blob_ptr;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
if (!obj) {
ret = -EINVAL;
goto done;
}
blob = obj_to_blob(obj);
if (out_resp->length == blob->length) {
blob_ptr = (void *)(unsigned long)out_resp->data;
if (copy_to_user(blob_ptr, blob->data, blob->length)){
ret = -EFAULT;
goto done;
}
}
out_resp->length = blob->length;
done:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_getblob_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_object *obj;
struct drm_mode_get_blob *out_resp = data;
struct drm_property_blob *blob;
int ret = 0;
void *blob_ptr;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
if (!obj) {
ret = -EINVAL;
goto done;
}
blob = obj_to_blob(obj);
if (out_resp->length == blob->length) {
blob_ptr = (void *)(unsigned long)out_resp->data;
if (copy_to_user(blob_ptr, blob->data, blob->length)){
ret = -EFAULT;
goto done;
}
}
out_resp->length = blob->length;
done:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,508 | int drm_mode_getconnector(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_get_connector *out_resp = data;
struct drm_mode_object *obj;
struct drm_connector *connector;
struct drm_display_mode *mode;
int mode_count = 0;
int props_count = 0;
int encoders_count = 0;
int ret = 0;
int copied = 0;
int i;
struct drm_mode_modeinfo u_mode;
struct drm_mode_modeinfo __user *mode_ptr;
uint32_t __user *prop_ptr;
uint64_t __user *prop_values;
uint32_t __user *encoder_ptr;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, out_resp->connector_id,
DRM_MODE_OBJECT_CONNECTOR);
if (!obj) {
ret = -EINVAL;
goto out;
}
connector = obj_to_connector(obj);
for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
if (connector->property_ids[i] != 0) {
props_count++;
}
}
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
if (connector->encoder_ids[i] != 0) {
encoders_count++;
}
}
if (out_resp->count_modes == 0) {
connector->funcs->fill_modes(connector,
dev->mode_config.max_width,
dev->mode_config.max_height);
}
/* delayed so we get modes regardless of pre-fill_modes state */
list_for_each_entry(mode, &connector->modes, head)
mode_count++;
out_resp->connector_id = connector->base.id;
out_resp->connector_type = connector->connector_type;
out_resp->connector_type_id = connector->connector_type_id;
out_resp->mm_width = connector->display_info.width_mm;
out_resp->mm_height = connector->display_info.height_mm;
out_resp->subpixel = connector->display_info.subpixel_order;
out_resp->connection = connector->status;
if (connector->encoder)
out_resp->encoder_id = connector->encoder->base.id;
else
out_resp->encoder_id = 0;
/*
* This ioctl is called twice, once to determine how much space is
* needed, and the 2nd time to fill it.
*/
if ((out_resp->count_modes >= mode_count) && mode_count) {
copied = 0;
mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
list_for_each_entry(mode, &connector->modes, head) {
drm_crtc_convert_to_umode(&u_mode, mode);
if (copy_to_user(mode_ptr + copied,
&u_mode, sizeof(u_mode))) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
out_resp->count_modes = mode_count;
if ((out_resp->count_props >= props_count) && props_count) {
copied = 0;
prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
if (connector->property_ids[i] != 0) {
if (put_user(connector->property_ids[i],
prop_ptr + copied)) {
ret = -EFAULT;
goto out;
}
if (put_user(connector->property_values[i],
prop_values + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
out_resp->count_props = props_count;
if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
copied = 0;
encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
if (connector->encoder_ids[i] != 0) {
if (put_user(connector->encoder_ids[i],
encoder_ptr + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
out_resp->count_encoders = encoders_count;
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_getconnector(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_get_connector *out_resp = data;
struct drm_mode_object *obj;
struct drm_connector *connector;
struct drm_display_mode *mode;
int mode_count = 0;
int props_count = 0;
int encoders_count = 0;
int ret = 0;
int copied = 0;
int i;
struct drm_mode_modeinfo u_mode;
struct drm_mode_modeinfo __user *mode_ptr;
uint32_t __user *prop_ptr;
uint64_t __user *prop_values;
uint32_t __user *encoder_ptr;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, out_resp->connector_id,
DRM_MODE_OBJECT_CONNECTOR);
if (!obj) {
ret = -EINVAL;
goto out;
}
connector = obj_to_connector(obj);
for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
if (connector->property_ids[i] != 0) {
props_count++;
}
}
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
if (connector->encoder_ids[i] != 0) {
encoders_count++;
}
}
if (out_resp->count_modes == 0) {
connector->funcs->fill_modes(connector,
dev->mode_config.max_width,
dev->mode_config.max_height);
}
/* delayed so we get modes regardless of pre-fill_modes state */
list_for_each_entry(mode, &connector->modes, head)
mode_count++;
out_resp->connector_id = connector->base.id;
out_resp->connector_type = connector->connector_type;
out_resp->connector_type_id = connector->connector_type_id;
out_resp->mm_width = connector->display_info.width_mm;
out_resp->mm_height = connector->display_info.height_mm;
out_resp->subpixel = connector->display_info.subpixel_order;
out_resp->connection = connector->status;
if (connector->encoder)
out_resp->encoder_id = connector->encoder->base.id;
else
out_resp->encoder_id = 0;
/*
* This ioctl is called twice, once to determine how much space is
* needed, and the 2nd time to fill it.
*/
if ((out_resp->count_modes >= mode_count) && mode_count) {
copied = 0;
mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
list_for_each_entry(mode, &connector->modes, head) {
drm_crtc_convert_to_umode(&u_mode, mode);
if (copy_to_user(mode_ptr + copied,
&u_mode, sizeof(u_mode))) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
out_resp->count_modes = mode_count;
if ((out_resp->count_props >= props_count) && props_count) {
copied = 0;
prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
if (connector->property_ids[i] != 0) {
if (put_user(connector->property_ids[i],
prop_ptr + copied)) {
ret = -EFAULT;
goto out;
}
if (put_user(connector->property_values[i],
prop_values + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
out_resp->count_props = props_count;
if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
copied = 0;
encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
if (connector->encoder_ids[i] != 0) {
if (put_user(connector->encoder_ids[i],
encoder_ptr + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
out_resp->count_encoders = encoders_count;
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,509 | int drm_mode_getcrtc(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc *crtc_resp = data;
struct drm_crtc *crtc;
struct drm_mode_object *obj;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
DRM_MODE_OBJECT_CRTC);
if (!obj) {
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
crtc_resp->x = crtc->x;
crtc_resp->y = crtc->y;
crtc_resp->gamma_size = crtc->gamma_size;
if (crtc->fb)
crtc_resp->fb_id = crtc->fb->base.id;
else
crtc_resp->fb_id = 0;
if (crtc->enabled) {
drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode);
crtc_resp->mode_valid = 1;
} else {
crtc_resp->mode_valid = 0;
}
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_getcrtc(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc *crtc_resp = data;
struct drm_crtc *crtc;
struct drm_mode_object *obj;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
DRM_MODE_OBJECT_CRTC);
if (!obj) {
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
crtc_resp->x = crtc->x;
crtc_resp->y = crtc->y;
crtc_resp->gamma_size = crtc->gamma_size;
if (crtc->fb)
crtc_resp->fb_id = crtc->fb->base.id;
else
crtc_resp->fb_id = 0;
if (crtc->enabled) {
drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode);
crtc_resp->mode_valid = 1;
} else {
crtc_resp->mode_valid = 0;
}
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,510 | int drm_mode_getencoder(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_get_encoder *enc_resp = data;
struct drm_mode_object *obj;
struct drm_encoder *encoder;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, enc_resp->encoder_id,
DRM_MODE_OBJECT_ENCODER);
if (!obj) {
ret = -EINVAL;
goto out;
}
encoder = obj_to_encoder(obj);
if (encoder->crtc)
enc_resp->crtc_id = encoder->crtc->base.id;
else
enc_resp->crtc_id = 0;
enc_resp->encoder_type = encoder->encoder_type;
enc_resp->encoder_id = encoder->base.id;
enc_resp->possible_crtcs = encoder->possible_crtcs;
enc_resp->possible_clones = encoder->possible_clones;
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_getencoder(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_get_encoder *enc_resp = data;
struct drm_mode_object *obj;
struct drm_encoder *encoder;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, enc_resp->encoder_id,
DRM_MODE_OBJECT_ENCODER);
if (!obj) {
ret = -EINVAL;
goto out;
}
encoder = obj_to_encoder(obj);
if (encoder->crtc)
enc_resp->crtc_id = encoder->crtc->base.id;
else
enc_resp->crtc_id = 0;
enc_resp->encoder_type = encoder->encoder_type;
enc_resp->encoder_id = encoder->base.id;
enc_resp->possible_crtcs = encoder->possible_crtcs;
enc_resp->possible_clones = encoder->possible_clones;
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,511 | int drm_mode_getfb(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_fb_cmd *r = data;
struct drm_mode_object *obj;
struct drm_framebuffer *fb;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
if (!obj) {
DRM_ERROR("invalid framebuffer id\n");
ret = -EINVAL;
goto out;
}
fb = obj_to_fb(obj);
r->height = fb->height;
r->width = fb->width;
r->depth = fb->depth;
r->bpp = fb->bits_per_pixel;
r->pitch = fb->pitch;
fb->funcs->create_handle(fb, file_priv, &r->handle);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_getfb(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_fb_cmd *r = data;
struct drm_mode_object *obj;
struct drm_framebuffer *fb;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
if (!obj) {
DRM_ERROR("invalid framebuffer id\n");
ret = -EINVAL;
goto out;
}
fb = obj_to_fb(obj);
r->height = fb->height;
r->width = fb->width;
r->depth = fb->depth;
r->bpp = fb->bits_per_pixel;
r->pitch = fb->pitch;
fb->funcs->create_handle(fb, file_priv, &r->handle);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,512 | int drm_mode_getresources(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_card_res *card_res = data;
struct list_head *lh;
struct drm_framebuffer *fb;
struct drm_connector *connector;
struct drm_crtc *crtc;
struct drm_encoder *encoder;
int ret = 0;
int connector_count = 0;
int crtc_count = 0;
int fb_count = 0;
int encoder_count = 0;
int copied = 0, i;
uint32_t __user *fb_id;
uint32_t __user *crtc_id;
uint32_t __user *connector_id;
uint32_t __user *encoder_id;
struct drm_mode_group *mode_group;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
/*
* For the non-control nodes we need to limit the list of resources
* by IDs in the group list for this node
*/
list_for_each(lh, &file_priv->fbs)
fb_count++;
mode_group = &file_priv->master->minor->mode_group;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each(lh, &dev->mode_config.crtc_list)
crtc_count++;
list_for_each(lh, &dev->mode_config.connector_list)
connector_count++;
list_for_each(lh, &dev->mode_config.encoder_list)
encoder_count++;
} else {
crtc_count = mode_group->num_crtcs;
connector_count = mode_group->num_connectors;
encoder_count = mode_group->num_encoders;
}
card_res->max_height = dev->mode_config.max_height;
card_res->min_height = dev->mode_config.min_height;
card_res->max_width = dev->mode_config.max_width;
card_res->min_width = dev->mode_config.min_width;
/* handle this in 4 parts */
/* FBs */
if (card_res->count_fbs >= fb_count) {
copied = 0;
fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
list_for_each_entry(fb, &file_priv->fbs, filp_head) {
if (put_user(fb->base.id, fb_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
card_res->count_fbs = fb_count;
/* CRTCs */
if (card_res->count_crtcs >= crtc_count) {
copied = 0;
crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each_entry(crtc, &dev->mode_config.crtc_list,
head) {
DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
if (put_user(crtc->base.id, crtc_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
} else {
for (i = 0; i < mode_group->num_crtcs; i++) {
if (put_user(mode_group->id_list[i],
crtc_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
card_res->count_crtcs = crtc_count;
/* Encoders */
if (card_res->count_encoders >= encoder_count) {
copied = 0;
encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each_entry(encoder,
&dev->mode_config.encoder_list,
head) {
DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
drm_get_encoder_name(encoder));
if (put_user(encoder->base.id, encoder_id +
copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
} else {
for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) {
if (put_user(mode_group->id_list[i],
encoder_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
card_res->count_encoders = encoder_count;
/* Connectors */
if (card_res->count_connectors >= connector_count) {
copied = 0;
connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each_entry(connector,
&dev->mode_config.connector_list,
head) {
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
connector->base.id,
drm_get_connector_name(connector));
if (put_user(connector->base.id,
connector_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
} else {
int start = mode_group->num_crtcs +
mode_group->num_encoders;
for (i = start; i < start + mode_group->num_connectors; i++) {
if (put_user(mode_group->id_list[i],
connector_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
card_res->count_connectors = connector_count;
DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs,
card_res->count_connectors, card_res->count_encoders);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_getresources(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_card_res *card_res = data;
struct list_head *lh;
struct drm_framebuffer *fb;
struct drm_connector *connector;
struct drm_crtc *crtc;
struct drm_encoder *encoder;
int ret = 0;
int connector_count = 0;
int crtc_count = 0;
int fb_count = 0;
int encoder_count = 0;
int copied = 0, i;
uint32_t __user *fb_id;
uint32_t __user *crtc_id;
uint32_t __user *connector_id;
uint32_t __user *encoder_id;
struct drm_mode_group *mode_group;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
/*
* For the non-control nodes we need to limit the list of resources
* by IDs in the group list for this node
*/
list_for_each(lh, &file_priv->fbs)
fb_count++;
mode_group = &file_priv->master->minor->mode_group;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each(lh, &dev->mode_config.crtc_list)
crtc_count++;
list_for_each(lh, &dev->mode_config.connector_list)
connector_count++;
list_for_each(lh, &dev->mode_config.encoder_list)
encoder_count++;
} else {
crtc_count = mode_group->num_crtcs;
connector_count = mode_group->num_connectors;
encoder_count = mode_group->num_encoders;
}
card_res->max_height = dev->mode_config.max_height;
card_res->min_height = dev->mode_config.min_height;
card_res->max_width = dev->mode_config.max_width;
card_res->min_width = dev->mode_config.min_width;
/* handle this in 4 parts */
/* FBs */
if (card_res->count_fbs >= fb_count) {
copied = 0;
fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
list_for_each_entry(fb, &file_priv->fbs, filp_head) {
if (put_user(fb->base.id, fb_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
card_res->count_fbs = fb_count;
/* CRTCs */
if (card_res->count_crtcs >= crtc_count) {
copied = 0;
crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each_entry(crtc, &dev->mode_config.crtc_list,
head) {
DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
if (put_user(crtc->base.id, crtc_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
} else {
for (i = 0; i < mode_group->num_crtcs; i++) {
if (put_user(mode_group->id_list[i],
crtc_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
card_res->count_crtcs = crtc_count;
/* Encoders */
if (card_res->count_encoders >= encoder_count) {
copied = 0;
encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each_entry(encoder,
&dev->mode_config.encoder_list,
head) {
DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
drm_get_encoder_name(encoder));
if (put_user(encoder->base.id, encoder_id +
copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
} else {
for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) {
if (put_user(mode_group->id_list[i],
encoder_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
card_res->count_encoders = encoder_count;
/* Connectors */
if (card_res->count_connectors >= connector_count) {
copied = 0;
connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
list_for_each_entry(connector,
&dev->mode_config.connector_list,
head) {
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
connector->base.id,
drm_get_connector_name(connector));
if (put_user(connector->base.id,
connector_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
} else {
int start = mode_group->num_crtcs +
mode_group->num_encoders;
for (i = start; i < start + mode_group->num_connectors; i++) {
if (put_user(mode_group->id_list[i],
connector_id + copied)) {
ret = -EFAULT;
goto out;
}
copied++;
}
}
}
card_res->count_connectors = connector_count;
DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs,
card_res->count_connectors, card_res->count_encoders);
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,513 | int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group)
{
uint32_t total_objects = 0;
total_objects += dev->mode_config.num_crtc;
total_objects += dev->mode_config.num_connector;
total_objects += dev->mode_config.num_encoder;
group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL);
if (!group->id_list)
return -ENOMEM;
group->num_crtcs = 0;
group->num_connectors = 0;
group->num_encoders = 0;
return 0;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group)
{
uint32_t total_objects = 0;
total_objects += dev->mode_config.num_crtc;
total_objects += dev->mode_config.num_connector;
total_objects += dev->mode_config.num_encoder;
group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL);
if (!group->id_list)
return -ENOMEM;
group->num_crtcs = 0;
group->num_connectors = 0;
group->num_encoders = 0;
return 0;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,514 | int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_map_dumb *args = data;
/* call driver ioctl to get mmap offset */
if (!dev->driver->dumb_map_offset)
return -ENOSYS;
return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_map_dumb *args = data;
/* call driver ioctl to get mmap offset */
if (!dev->driver->dumb_map_offset)
return -ENOSYS;
return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,515 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
uint32_t id, uint32_t type)
{
struct drm_mode_object *obj = NULL;
mutex_lock(&dev->mode_config.idr_mutex);
obj = idr_find(&dev->mode_config.crtc_idr, id);
if (!obj || (obj->type != type) || (obj->id != id))
obj = NULL;
mutex_unlock(&dev->mode_config.idr_mutex);
return obj;
}
| DoS Overflow +Priv Mem. Corr. | 0 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
uint32_t id, uint32_t type)
{
struct drm_mode_object *obj = NULL;
mutex_lock(&dev->mode_config.idr_mutex);
obj = idr_find(&dev->mode_config.crtc_idr, id);
if (!obj || (obj->type != type) || (obj->id != id))
obj = NULL;
mutex_unlock(&dev->mode_config.idr_mutex);
return obj;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,516 | static int drm_mode_object_get(struct drm_device *dev,
struct drm_mode_object *obj, uint32_t obj_type)
{
int new_id = 0;
int ret;
again:
if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
DRM_ERROR("Ran out memory getting a mode number\n");
return -EINVAL;
}
mutex_lock(&dev->mode_config.idr_mutex);
ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id);
mutex_unlock(&dev->mode_config.idr_mutex);
if (ret == -EAGAIN)
goto again;
obj->id = new_id;
obj->type = obj_type;
return 0;
}
| DoS Overflow +Priv Mem. Corr. | 0 | static int drm_mode_object_get(struct drm_device *dev,
struct drm_mode_object *obj, uint32_t obj_type)
{
int new_id = 0;
int ret;
again:
if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) {
DRM_ERROR("Ran out memory getting a mode number\n");
return -EINVAL;
}
mutex_lock(&dev->mode_config.idr_mutex);
ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id);
mutex_unlock(&dev->mode_config.idr_mutex);
if (ret == -EAGAIN)
goto again;
obj->id = new_id;
obj->type = obj_type;
return 0;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,517 | static void drm_mode_object_put(struct drm_device *dev,
struct drm_mode_object *object)
{
mutex_lock(&dev->mode_config.idr_mutex);
idr_remove(&dev->mode_config.crtc_idr, object->id);
mutex_unlock(&dev->mode_config.idr_mutex);
}
| DoS Overflow +Priv Mem. Corr. | 0 | static void drm_mode_object_put(struct drm_device *dev,
struct drm_mode_object *object)
{
mutex_lock(&dev->mode_config.idr_mutex);
idr_remove(&dev->mode_config.crtc_idr, object->id);
mutex_unlock(&dev->mode_config.idr_mutex);
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,518 | int drm_mode_page_flip_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc_page_flip *page_flip = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc;
struct drm_framebuffer *fb;
struct drm_pending_vblank_event *e = NULL;
unsigned long flags;
int ret = -EINVAL;
if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
page_flip->reserved != 0)
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC);
if (!obj)
goto out;
crtc = obj_to_crtc(obj);
if (crtc->fb == NULL) {
/* The framebuffer is currently unbound, presumably
* due to a hotplug event, that userspace has not
* yet discovered.
*/
ret = -EBUSY;
goto out;
}
if (crtc->funcs->page_flip == NULL)
goto out;
obj = drm_mode_object_find(dev, page_flip->fb_id, DRM_MODE_OBJECT_FB);
if (!obj)
goto out;
fb = obj_to_fb(obj);
if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
ret = -ENOMEM;
spin_lock_irqsave(&dev->event_lock, flags);
if (file_priv->event_space < sizeof e->event) {
spin_unlock_irqrestore(&dev->event_lock, flags);
goto out;
}
file_priv->event_space -= sizeof e->event;
spin_unlock_irqrestore(&dev->event_lock, flags);
e = kzalloc(sizeof *e, GFP_KERNEL);
if (e == NULL) {
spin_lock_irqsave(&dev->event_lock, flags);
file_priv->event_space += sizeof e->event;
spin_unlock_irqrestore(&dev->event_lock, flags);
goto out;
}
e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
e->event.base.length = sizeof e->event;
e->event.user_data = page_flip->user_data;
e->base.event = &e->event.base;
e->base.file_priv = file_priv;
e->base.destroy =
(void (*) (struct drm_pending_event *)) kfree;
}
ret = crtc->funcs->page_flip(crtc, fb, e);
if (ret) {
spin_lock_irqsave(&dev->event_lock, flags);
file_priv->event_space += sizeof e->event;
spin_unlock_irqrestore(&dev->event_lock, flags);
kfree(e);
}
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_page_flip_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv)
{
struct drm_mode_crtc_page_flip *page_flip = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc;
struct drm_framebuffer *fb;
struct drm_pending_vblank_event *e = NULL;
unsigned long flags;
int ret = -EINVAL;
if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
page_flip->reserved != 0)
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC);
if (!obj)
goto out;
crtc = obj_to_crtc(obj);
if (crtc->fb == NULL) {
/* The framebuffer is currently unbound, presumably
* due to a hotplug event, that userspace has not
* yet discovered.
*/
ret = -EBUSY;
goto out;
}
if (crtc->funcs->page_flip == NULL)
goto out;
obj = drm_mode_object_find(dev, page_flip->fb_id, DRM_MODE_OBJECT_FB);
if (!obj)
goto out;
fb = obj_to_fb(obj);
if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
ret = -ENOMEM;
spin_lock_irqsave(&dev->event_lock, flags);
if (file_priv->event_space < sizeof e->event) {
spin_unlock_irqrestore(&dev->event_lock, flags);
goto out;
}
file_priv->event_space -= sizeof e->event;
spin_unlock_irqrestore(&dev->event_lock, flags);
e = kzalloc(sizeof *e, GFP_KERNEL);
if (e == NULL) {
spin_lock_irqsave(&dev->event_lock, flags);
file_priv->event_space += sizeof e->event;
spin_unlock_irqrestore(&dev->event_lock, flags);
goto out;
}
e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
e->event.base.length = sizeof e->event;
e->event.user_data = page_flip->user_data;
e->base.event = &e->event.base;
e->base.file_priv = file_priv;
e->base.destroy =
(void (*) (struct drm_pending_event *)) kfree;
}
ret = crtc->funcs->page_flip(crtc, fb, e);
if (ret) {
spin_lock_irqsave(&dev->event_lock, flags);
file_priv->event_space += sizeof e->event;
spin_unlock_irqrestore(&dev->event_lock, flags);
kfree(e);
}
out:
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,519 | void drm_mode_probed_add(struct drm_connector *connector,
struct drm_display_mode *mode)
{
list_add(&mode->head, &connector->probed_modes);
}
| DoS Overflow +Priv Mem. Corr. | 0 | void drm_mode_probed_add(struct drm_connector *connector,
struct drm_display_mode *mode)
{
list_add(&mode->head, &connector->probed_modes);
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,520 | void drm_mode_remove(struct drm_connector *connector,
struct drm_display_mode *mode)
{
list_del(&mode->head);
kfree(mode);
}
| DoS Overflow +Priv Mem. Corr. | 0 | void drm_mode_remove(struct drm_connector *connector,
struct drm_display_mode *mode)
{
list_del(&mode->head);
kfree(mode);
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,521 | int drm_mode_setcrtc(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_config *config = &dev->mode_config;
struct drm_mode_crtc *crtc_req = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc, *crtcfb;
struct drm_connector **connector_set = NULL, *connector;
struct drm_framebuffer *fb = NULL;
struct drm_display_mode *mode = NULL;
struct drm_mode_set set;
uint32_t __user *set_connectors_ptr;
int ret = 0;
int i;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_req->crtc_id,
DRM_MODE_OBJECT_CRTC);
if (!obj) {
DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
if (crtc_req->mode_valid) {
/* If we have a mode we need a framebuffer. */
/* If we pass -1, set the mode with the currently bound fb */
if (crtc_req->fb_id == -1) {
list_for_each_entry(crtcfb,
&dev->mode_config.crtc_list, head) {
if (crtcfb == crtc) {
DRM_DEBUG_KMS("Using current fb for "
"setmode\n");
fb = crtc->fb;
}
}
} else {
obj = drm_mode_object_find(dev, crtc_req->fb_id,
DRM_MODE_OBJECT_FB);
if (!obj) {
DRM_DEBUG_KMS("Unknown FB ID%d\n",
crtc_req->fb_id);
ret = -EINVAL;
goto out;
}
fb = obj_to_fb(obj);
}
mode = drm_mode_create(dev);
drm_crtc_convert_umode(mode, &crtc_req->mode);
drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
}
if (crtc_req->count_connectors == 0 && mode) {
DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
ret = -EINVAL;
goto out;
}
if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
crtc_req->count_connectors);
ret = -EINVAL;
goto out;
}
if (crtc_req->count_connectors > 0) {
u32 out_id;
/* Avoid unbounded kernel memory allocation */
if (crtc_req->count_connectors > config->num_connector) {
ret = -EINVAL;
goto out;
}
connector_set = kmalloc(crtc_req->count_connectors *
sizeof(struct drm_connector *),
GFP_KERNEL);
if (!connector_set) {
ret = -ENOMEM;
goto out;
}
for (i = 0; i < crtc_req->count_connectors; i++) {
set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
if (get_user(out_id, &set_connectors_ptr[i])) {
ret = -EFAULT;
goto out;
}
obj = drm_mode_object_find(dev, out_id,
DRM_MODE_OBJECT_CONNECTOR);
if (!obj) {
DRM_DEBUG_KMS("Connector id %d unknown\n",
out_id);
ret = -EINVAL;
goto out;
}
connector = obj_to_connector(obj);
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
connector->base.id,
drm_get_connector_name(connector));
connector_set[i] = connector;
}
}
set.crtc = crtc;
set.x = crtc_req->x;
set.y = crtc_req->y;
set.mode = mode;
set.connectors = connector_set;
set.num_connectors = crtc_req->count_connectors;
set.fb = fb;
ret = crtc->funcs->set_config(&set);
out:
kfree(connector_set);
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_mode_setcrtc(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_mode_config *config = &dev->mode_config;
struct drm_mode_crtc *crtc_req = data;
struct drm_mode_object *obj;
struct drm_crtc *crtc, *crtcfb;
struct drm_connector **connector_set = NULL, *connector;
struct drm_framebuffer *fb = NULL;
struct drm_display_mode *mode = NULL;
struct drm_mode_set set;
uint32_t __user *set_connectors_ptr;
int ret = 0;
int i;
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL;
mutex_lock(&dev->mode_config.mutex);
obj = drm_mode_object_find(dev, crtc_req->crtc_id,
DRM_MODE_OBJECT_CRTC);
if (!obj) {
DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
ret = -EINVAL;
goto out;
}
crtc = obj_to_crtc(obj);
DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
if (crtc_req->mode_valid) {
/* If we have a mode we need a framebuffer. */
/* If we pass -1, set the mode with the currently bound fb */
if (crtc_req->fb_id == -1) {
list_for_each_entry(crtcfb,
&dev->mode_config.crtc_list, head) {
if (crtcfb == crtc) {
DRM_DEBUG_KMS("Using current fb for "
"setmode\n");
fb = crtc->fb;
}
}
} else {
obj = drm_mode_object_find(dev, crtc_req->fb_id,
DRM_MODE_OBJECT_FB);
if (!obj) {
DRM_DEBUG_KMS("Unknown FB ID%d\n",
crtc_req->fb_id);
ret = -EINVAL;
goto out;
}
fb = obj_to_fb(obj);
}
mode = drm_mode_create(dev);
drm_crtc_convert_umode(mode, &crtc_req->mode);
drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
}
if (crtc_req->count_connectors == 0 && mode) {
DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
ret = -EINVAL;
goto out;
}
if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
crtc_req->count_connectors);
ret = -EINVAL;
goto out;
}
if (crtc_req->count_connectors > 0) {
u32 out_id;
/* Avoid unbounded kernel memory allocation */
if (crtc_req->count_connectors > config->num_connector) {
ret = -EINVAL;
goto out;
}
connector_set = kmalloc(crtc_req->count_connectors *
sizeof(struct drm_connector *),
GFP_KERNEL);
if (!connector_set) {
ret = -ENOMEM;
goto out;
}
for (i = 0; i < crtc_req->count_connectors; i++) {
set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
if (get_user(out_id, &set_connectors_ptr[i])) {
ret = -EFAULT;
goto out;
}
obj = drm_mode_object_find(dev, out_id,
DRM_MODE_OBJECT_CONNECTOR);
if (!obj) {
DRM_DEBUG_KMS("Connector id %d unknown\n",
out_id);
ret = -EINVAL;
goto out;
}
connector = obj_to_connector(obj);
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
connector->base.id,
drm_get_connector_name(connector));
connector_set[i] = connector;
}
}
set.crtc = crtc;
set.x = crtc_req->x;
set.y = crtc_req->y;
set.mode = mode;
set.connectors = connector_set;
set.num_connectors = crtc_req->count_connectors;
set.fb = fb;
ret = crtc->funcs->set_config(&set);
out:
kfree(connector_set);
mutex_unlock(&dev->mode_config.mutex);
return ret;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,522 | int drm_property_add_enum(struct drm_property *property, int index,
uint64_t value, const char *name)
{
struct drm_property_enum *prop_enum;
if (!(property->flags & DRM_MODE_PROP_ENUM))
return -EINVAL;
if (!list_empty(&property->enum_blob_list)) {
list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
if (prop_enum->value == value) {
strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
return 0;
}
}
}
prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
if (!prop_enum)
return -ENOMEM;
strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
prop_enum->value = value;
property->values[index] = value;
list_add_tail(&prop_enum->head, &property->enum_blob_list);
return 0;
}
| DoS Overflow +Priv Mem. Corr. | 0 | int drm_property_add_enum(struct drm_property *property, int index,
uint64_t value, const char *name)
{
struct drm_property_enum *prop_enum;
if (!(property->flags & DRM_MODE_PROP_ENUM))
return -EINVAL;
if (!list_empty(&property->enum_blob_list)) {
list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
if (prop_enum->value == value) {
strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
return 0;
}
}
}
prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
if (!prop_enum)
return -ENOMEM;
strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
prop_enum->value = value;
property->values[index] = value;
list_add_tail(&prop_enum->head, &property->enum_blob_list);
return 0;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,523 | struct drm_property *drm_property_create(struct drm_device *dev, int flags,
const char *name, int num_values)
{
struct drm_property *property = NULL;
property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
if (!property)
return NULL;
if (num_values) {
property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL);
if (!property->values)
goto fail;
}
drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
property->flags = flags;
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_blob_list);
if (name) {
strncpy(property->name, name, DRM_PROP_NAME_LEN);
property->name[DRM_PROP_NAME_LEN-1] = '\0';
}
list_add_tail(&property->head, &dev->mode_config.property_list);
return property;
fail:
kfree(property);
return NULL;
}
| DoS Overflow +Priv Mem. Corr. | 0 | struct drm_property *drm_property_create(struct drm_device *dev, int flags,
const char *name, int num_values)
{
struct drm_property *property = NULL;
property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
if (!property)
return NULL;
if (num_values) {
property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL);
if (!property->values)
goto fail;
}
drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
property->flags = flags;
property->num_values = num_values;
INIT_LIST_HEAD(&property->enum_blob_list);
if (name) {
strncpy(property->name, name, DRM_PROP_NAME_LEN);
property->name[DRM_PROP_NAME_LEN-1] = '\0';
}
list_add_tail(&property->head, &dev->mode_config.property_list);
return property;
fail:
kfree(property);
return NULL;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,524 | static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length,
void *data)
{
struct drm_property_blob *blob;
if (!length || !data)
return NULL;
blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
if (!blob)
return NULL;
blob->data = (void *)((char *)blob + sizeof(struct drm_property_blob));
blob->length = length;
memcpy(blob->data, data, length);
drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB);
list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
return blob;
}
| DoS Overflow +Priv Mem. Corr. | 0 | static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length,
void *data)
{
struct drm_property_blob *blob;
if (!length || !data)
return NULL;
blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
if (!blob)
return NULL;
blob->data = (void *)((char *)blob + sizeof(struct drm_property_blob));
blob->length = length;
memcpy(blob->data, data, length);
drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB);
list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
return blob;
}
| @@ -1873,6 +1873,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
}
if (num_clips && clips_ptr) {
+ if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+ ret = -EINVAL;
+ goto out_err1;
+ }
clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
if (!clips) {
ret = -ENOMEM; | CWE-189 | null | null |
17,525 | posix_acl_access_exists(struct inode *inode)
{
return xfs_acl_exists(inode, SGI_ACL_FILE);
}
| DoS Overflow | 0 | posix_acl_access_exists(struct inode *inode)
{
return xfs_acl_exists(inode, SGI_ACL_FILE);
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,526 | posix_acl_default_exists(struct inode *inode)
{
if (!S_ISDIR(inode->i_mode))
return 0;
return xfs_acl_exists(inode, SGI_ACL_DEFAULT);
}
| DoS Overflow | 0 | posix_acl_default_exists(struct inode *inode)
{
if (!S_ISDIR(inode->i_mode))
return 0;
return xfs_acl_exists(inode, SGI_ACL_DEFAULT);
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,527 | xfs_acl_chmod(struct inode *inode)
{
struct posix_acl *acl;
int error;
if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
acl = xfs_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
return error;
}
| DoS Overflow | 0 | xfs_acl_chmod(struct inode *inode)
{
struct posix_acl *acl;
int error;
if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
acl = xfs_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
return error;
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,528 | xfs_acl_exists(struct inode *inode, unsigned char *name)
{
int len = sizeof(struct xfs_acl);
return (xfs_attr_get(XFS_I(inode), name, NULL, &len,
ATTR_ROOT|ATTR_KERNOVAL) == 0);
}
| DoS Overflow | 0 | xfs_acl_exists(struct inode *inode, unsigned char *name)
{
int len = sizeof(struct xfs_acl);
return (xfs_attr_get(XFS_I(inode), name, NULL, &len,
ATTR_ROOT|ATTR_KERNOVAL) == 0);
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,529 | xfs_acl_to_disk(struct xfs_acl *aclp, const struct posix_acl *acl)
{
const struct posix_acl_entry *acl_e;
struct xfs_acl_entry *ace;
int i;
aclp->acl_cnt = cpu_to_be32(acl->a_count);
for (i = 0; i < acl->a_count; i++) {
ace = &aclp->acl_entry[i];
acl_e = &acl->a_entries[i];
ace->ae_tag = cpu_to_be32(acl_e->e_tag);
ace->ae_id = cpu_to_be32(acl_e->e_id);
ace->ae_perm = cpu_to_be16(acl_e->e_perm);
}
}
| DoS Overflow | 0 | xfs_acl_to_disk(struct xfs_acl *aclp, const struct posix_acl *acl)
{
const struct posix_acl_entry *acl_e;
struct xfs_acl_entry *ace;
int i;
aclp->acl_cnt = cpu_to_be32(acl->a_count);
for (i = 0; i < acl->a_count; i++) {
ace = &aclp->acl_entry[i];
acl_e = &acl->a_entries[i];
ace->ae_tag = cpu_to_be32(acl_e->e_tag);
ace->ae_id = cpu_to_be32(acl_e->e_id);
ace->ae_perm = cpu_to_be16(acl_e->e_perm);
}
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,530 | xfs_get_acl(struct inode *inode, int type)
{
struct xfs_inode *ip = XFS_I(inode);
struct posix_acl *acl;
struct xfs_acl *xfs_acl;
int len = sizeof(struct xfs_acl);
unsigned char *ea_name;
int error;
acl = get_cached_acl(inode, type);
if (acl != ACL_NOT_CACHED)
return acl;
trace_xfs_get_acl(ip);
switch (type) {
case ACL_TYPE_ACCESS:
ea_name = SGI_ACL_FILE;
break;
case ACL_TYPE_DEFAULT:
ea_name = SGI_ACL_DEFAULT;
break;
default:
BUG();
}
/*
* If we have a cached ACLs value just return it, not need to
* go out to the disk.
*/
xfs_acl = kzalloc(sizeof(struct xfs_acl), GFP_KERNEL);
if (!xfs_acl)
return ERR_PTR(-ENOMEM);
error = -xfs_attr_get(ip, ea_name, (unsigned char *)xfs_acl,
&len, ATTR_ROOT);
if (error) {
/*
* If the attribute doesn't exist make sure we have a negative
* cache entry, for any other error assume it is transient and
* leave the cache entry as ACL_NOT_CACHED.
*/
if (error == -ENOATTR) {
acl = NULL;
goto out_update_cache;
}
goto out;
}
acl = xfs_acl_from_disk(xfs_acl);
if (IS_ERR(acl))
goto out;
out_update_cache:
set_cached_acl(inode, type, acl);
out:
kfree(xfs_acl);
return acl;
}
| DoS Overflow | 0 | xfs_get_acl(struct inode *inode, int type)
{
struct xfs_inode *ip = XFS_I(inode);
struct posix_acl *acl;
struct xfs_acl *xfs_acl;
int len = sizeof(struct xfs_acl);
unsigned char *ea_name;
int error;
acl = get_cached_acl(inode, type);
if (acl != ACL_NOT_CACHED)
return acl;
trace_xfs_get_acl(ip);
switch (type) {
case ACL_TYPE_ACCESS:
ea_name = SGI_ACL_FILE;
break;
case ACL_TYPE_DEFAULT:
ea_name = SGI_ACL_DEFAULT;
break;
default:
BUG();
}
/*
* If we have a cached ACLs value just return it, not need to
* go out to the disk.
*/
xfs_acl = kzalloc(sizeof(struct xfs_acl), GFP_KERNEL);
if (!xfs_acl)
return ERR_PTR(-ENOMEM);
error = -xfs_attr_get(ip, ea_name, (unsigned char *)xfs_acl,
&len, ATTR_ROOT);
if (error) {
/*
* If the attribute doesn't exist make sure we have a negative
* cache entry, for any other error assume it is transient and
* leave the cache entry as ACL_NOT_CACHED.
*/
if (error == -ENOATTR) {
acl = NULL;
goto out_update_cache;
}
goto out;
}
acl = xfs_acl_from_disk(xfs_acl);
if (IS_ERR(acl))
goto out;
out_update_cache:
set_cached_acl(inode, type, acl);
out:
kfree(xfs_acl);
return acl;
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,531 | xfs_inherit_acl(struct inode *inode, struct posix_acl *acl)
{
umode_t mode = inode->i_mode;
int error = 0, inherit = 0;
if (S_ISDIR(inode->i_mode)) {
error = xfs_set_acl(inode, ACL_TYPE_DEFAULT, acl);
if (error)
goto out;
}
error = posix_acl_create(&acl, GFP_KERNEL, &mode);
if (error < 0)
return error;
/*
* If posix_acl_create returns a positive value we need to
* inherit a permission that can't be represented using the Unix
* mode bits and we actually need to set an ACL.
*/
if (error > 0)
inherit = 1;
error = xfs_set_mode(inode, mode);
if (error)
goto out;
if (inherit)
error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
out:
posix_acl_release(acl);
return error;
}
| DoS Overflow | 0 | xfs_inherit_acl(struct inode *inode, struct posix_acl *acl)
{
umode_t mode = inode->i_mode;
int error = 0, inherit = 0;
if (S_ISDIR(inode->i_mode)) {
error = xfs_set_acl(inode, ACL_TYPE_DEFAULT, acl);
if (error)
goto out;
}
error = posix_acl_create(&acl, GFP_KERNEL, &mode);
if (error < 0)
return error;
/*
* If posix_acl_create returns a positive value we need to
* inherit a permission that can't be represented using the Unix
* mode bits and we actually need to set an ACL.
*/
if (error > 0)
inherit = 1;
error = xfs_set_mode(inode, mode);
if (error)
goto out;
if (inherit)
error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
out:
posix_acl_release(acl);
return error;
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,532 | xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
{
struct xfs_inode *ip = XFS_I(inode);
unsigned char *ea_name;
int error;
if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
switch (type) {
case ACL_TYPE_ACCESS:
ea_name = SGI_ACL_FILE;
break;
case ACL_TYPE_DEFAULT:
if (!S_ISDIR(inode->i_mode))
return acl ? -EACCES : 0;
ea_name = SGI_ACL_DEFAULT;
break;
default:
return -EINVAL;
}
if (acl) {
struct xfs_acl *xfs_acl;
int len;
xfs_acl = kzalloc(sizeof(struct xfs_acl), GFP_KERNEL);
if (!xfs_acl)
return -ENOMEM;
xfs_acl_to_disk(xfs_acl, acl);
len = sizeof(struct xfs_acl) -
(sizeof(struct xfs_acl_entry) *
(XFS_ACL_MAX_ENTRIES - acl->a_count));
error = -xfs_attr_set(ip, ea_name, (unsigned char *)xfs_acl,
len, ATTR_ROOT);
kfree(xfs_acl);
} else {
/*
* A NULL ACL argument means we want to remove the ACL.
*/
error = -xfs_attr_remove(ip, ea_name, ATTR_ROOT);
/*
* If the attribute didn't exist to start with that's fine.
*/
if (error == -ENOATTR)
error = 0;
}
if (!error)
set_cached_acl(inode, type, acl);
return error;
}
| DoS Overflow | 0 | xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
{
struct xfs_inode *ip = XFS_I(inode);
unsigned char *ea_name;
int error;
if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
switch (type) {
case ACL_TYPE_ACCESS:
ea_name = SGI_ACL_FILE;
break;
case ACL_TYPE_DEFAULT:
if (!S_ISDIR(inode->i_mode))
return acl ? -EACCES : 0;
ea_name = SGI_ACL_DEFAULT;
break;
default:
return -EINVAL;
}
if (acl) {
struct xfs_acl *xfs_acl;
int len;
xfs_acl = kzalloc(sizeof(struct xfs_acl), GFP_KERNEL);
if (!xfs_acl)
return -ENOMEM;
xfs_acl_to_disk(xfs_acl, acl);
len = sizeof(struct xfs_acl) -
(sizeof(struct xfs_acl_entry) *
(XFS_ACL_MAX_ENTRIES - acl->a_count));
error = -xfs_attr_set(ip, ea_name, (unsigned char *)xfs_acl,
len, ATTR_ROOT);
kfree(xfs_acl);
} else {
/*
* A NULL ACL argument means we want to remove the ACL.
*/
error = -xfs_attr_remove(ip, ea_name, ATTR_ROOT);
/*
* If the attribute didn't exist to start with that's fine.
*/
if (error == -ENOATTR)
error = 0;
}
if (!error)
set_cached_acl(inode, type, acl);
return error;
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,533 | xfs_set_mode(struct inode *inode, umode_t mode)
{
int error = 0;
if (mode != inode->i_mode) {
struct iattr iattr;
iattr.ia_valid = ATTR_MODE | ATTR_CTIME;
iattr.ia_mode = mode;
iattr.ia_ctime = current_fs_time(inode->i_sb);
error = -xfs_setattr_nonsize(XFS_I(inode), &iattr, XFS_ATTR_NOACL);
}
return error;
}
| DoS Overflow | 0 | xfs_set_mode(struct inode *inode, umode_t mode)
{
int error = 0;
if (mode != inode->i_mode) {
struct iattr iattr;
iattr.ia_valid = ATTR_MODE | ATTR_CTIME;
iattr.ia_mode = mode;
iattr.ia_ctime = current_fs_time(inode->i_sb);
error = -xfs_setattr_nonsize(XFS_I(inode), &iattr, XFS_ATTR_NOACL);
}
return error;
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,534 | xfs_xattr_acl_get(struct dentry *dentry, const char *name,
void *value, size_t size, int type)
{
struct posix_acl *acl;
int error;
acl = xfs_get_acl(dentry->d_inode, type);
if (IS_ERR(acl))
return PTR_ERR(acl);
if (acl == NULL)
return -ENODATA;
error = posix_acl_to_xattr(acl, value, size);
posix_acl_release(acl);
return error;
}
| DoS Overflow | 0 | xfs_xattr_acl_get(struct dentry *dentry, const char *name,
void *value, size_t size, int type)
{
struct posix_acl *acl;
int error;
acl = xfs_get_acl(dentry->d_inode, type);
if (IS_ERR(acl))
return PTR_ERR(acl);
if (acl == NULL)
return -ENODATA;
error = posix_acl_to_xattr(acl, value, size);
posix_acl_release(acl);
return error;
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,535 | xfs_xattr_acl_set(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags, int type)
{
struct inode *inode = dentry->d_inode;
struct posix_acl *acl = NULL;
int error = 0;
if (flags & XATTR_CREATE)
return -EINVAL;
if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
return value ? -EACCES : 0;
if ((current_fsuid() != inode->i_uid) && !capable(CAP_FOWNER))
return -EPERM;
if (!value)
goto set_acl;
acl = posix_acl_from_xattr(value, size);
if (!acl) {
/*
* acl_set_file(3) may request that we set default ACLs with
* zero length -- defend (gracefully) against that here.
*/
goto out;
}
if (IS_ERR(acl)) {
error = PTR_ERR(acl);
goto out;
}
error = posix_acl_valid(acl);
if (error)
goto out_release;
error = -EINVAL;
if (acl->a_count > XFS_ACL_MAX_ENTRIES)
goto out_release;
if (type == ACL_TYPE_ACCESS) {
umode_t mode = inode->i_mode;
error = posix_acl_equiv_mode(acl, &mode);
if (error <= 0) {
posix_acl_release(acl);
acl = NULL;
if (error < 0)
return error;
}
error = xfs_set_mode(inode, mode);
if (error)
goto out_release;
}
set_acl:
error = xfs_set_acl(inode, type, acl);
out_release:
posix_acl_release(acl);
out:
return error;
}
| DoS Overflow | 0 | xfs_xattr_acl_set(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags, int type)
{
struct inode *inode = dentry->d_inode;
struct posix_acl *acl = NULL;
int error = 0;
if (flags & XATTR_CREATE)
return -EINVAL;
if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
return value ? -EACCES : 0;
if ((current_fsuid() != inode->i_uid) && !capable(CAP_FOWNER))
return -EPERM;
if (!value)
goto set_acl;
acl = posix_acl_from_xattr(value, size);
if (!acl) {
/*
* acl_set_file(3) may request that we set default ACLs with
* zero length -- defend (gracefully) against that here.
*/
goto out;
}
if (IS_ERR(acl)) {
error = PTR_ERR(acl);
goto out;
}
error = posix_acl_valid(acl);
if (error)
goto out_release;
error = -EINVAL;
if (acl->a_count > XFS_ACL_MAX_ENTRIES)
goto out_release;
if (type == ACL_TYPE_ACCESS) {
umode_t mode = inode->i_mode;
error = posix_acl_equiv_mode(acl, &mode);
if (error <= 0) {
posix_acl_release(acl);
acl = NULL;
if (error < 0)
return error;
}
error = xfs_set_mode(inode, mode);
if (error)
goto out_release;
}
set_acl:
error = xfs_set_acl(inode, type, acl);
out_release:
posix_acl_release(acl);
out:
return error;
}
| @@ -42,6 +42,8 @@ xfs_acl_from_disk(struct xfs_acl *aclp)
int count, i;
count = be32_to_cpu(aclp->acl_cnt);
+ if (count > XFS_ACL_MAX_ENTRIES)
+ return ERR_PTR(-EFSCORRUPTED);
acl = posix_acl_alloc(count, GFP_KERNEL);
if (!acl) | CWE-189 | null | null |
17,536 | end_element(void *user_data, const char *name)
{
rdfalist* context_stack = (rdfalist*)user_data;
rdfacontext* context = (rdfacontext*)rdfa_pop_item(context_stack);
rdfacontext* parent_context = (rdfacontext*)
context_stack->items[context_stack->num_items - 1]->data;
char* buffer = (char*)malloc(strlen(name) + 4);
if(DEBUG)
{
printf("DEBUG: </%s>\n", name);
}
sprintf(buffer, "</%s>", name);
if(context->xml_literal == NULL)
{
context->xml_literal =
rdfa_replace_string(context->xml_literal, buffer);
context->xml_literal_size = strlen(buffer);
}
else
{
context->xml_literal = rdfa_n_append_string(
context->xml_literal, &context->xml_literal_size,
buffer, strlen(buffer));
}
free(buffer);
if(context->property != NULL)
{
char* saved_xml_literal = context->xml_literal;
char* content_start = NULL;
char* content_end = NULL;
buffer = NULL;
if(context->xml_literal != NULL)
{
content_start = strchr(context->xml_literal, '>');
content_end = strrchr(context->xml_literal, '<');
if((content_start != NULL) && (content_end != NULL))
{
context->xml_literal = ++content_start;
*content_end = '\0';
}
}
if(strlen(context->xml_literal) == 0)
{
context->plain_literal =
rdfa_replace_string(context->plain_literal, "");
}
rdfa_complete_object_literal_triples(context);
if(content_end != NULL)
{
*content_end = '<';
}
if(saved_xml_literal != NULL)
{
context->xml_literal = saved_xml_literal;
}
}
if(context->xml_literal != NULL)
{
if(parent_context->xml_literal == NULL)
{
parent_context->xml_literal =
rdfa_replace_string(
parent_context->xml_literal, context->xml_literal);
parent_context->xml_literal_size = context->xml_literal_size;
}
else
{
parent_context->xml_literal =
rdfa_n_append_string(
parent_context->xml_literal, &parent_context->xml_literal_size,
context->xml_literal, context->xml_literal_size);
}
if(context->plain_literal != NULL)
{
if(parent_context->plain_literal == NULL)
{
parent_context->plain_literal =
rdfa_replace_string(
parent_context->plain_literal, context->plain_literal);
parent_context->plain_literal_size = context->plain_literal_size;
}
else
{
parent_context->plain_literal =
rdfa_n_append_string(
parent_context->plain_literal,
&parent_context->plain_literal_size,
context->plain_literal,
context->plain_literal_size);
}
}
}
parent_context->bnode_count = context->bnode_count;
parent_context->underscore_colon_bnode_name = \
rdfa_replace_string(parent_context->underscore_colon_bnode_name,
context->underscore_colon_bnode_name);
if((context->skip_element == 0) && (context->new_subject != NULL))
{
rdfa_complete_incomplete_triples(context);
}
rdfa_free_context(context);
}
| +Info | 0 | end_element(void *user_data, const char *name)
{
rdfalist* context_stack = (rdfalist*)user_data;
rdfacontext* context = (rdfacontext*)rdfa_pop_item(context_stack);
rdfacontext* parent_context = (rdfacontext*)
context_stack->items[context_stack->num_items - 1]->data;
char* buffer = (char*)malloc(strlen(name) + 4);
if(DEBUG)
{
printf("DEBUG: </%s>\n", name);
}
sprintf(buffer, "</%s>", name);
if(context->xml_literal == NULL)
{
context->xml_literal =
rdfa_replace_string(context->xml_literal, buffer);
context->xml_literal_size = strlen(buffer);
}
else
{
context->xml_literal = rdfa_n_append_string(
context->xml_literal, &context->xml_literal_size,
buffer, strlen(buffer));
}
free(buffer);
if(context->property != NULL)
{
char* saved_xml_literal = context->xml_literal;
char* content_start = NULL;
char* content_end = NULL;
buffer = NULL;
if(context->xml_literal != NULL)
{
content_start = strchr(context->xml_literal, '>');
content_end = strrchr(context->xml_literal, '<');
if((content_start != NULL) && (content_end != NULL))
{
context->xml_literal = ++content_start;
*content_end = '\0';
}
}
if(strlen(context->xml_literal) == 0)
{
context->plain_literal =
rdfa_replace_string(context->plain_literal, "");
}
rdfa_complete_object_literal_triples(context);
if(content_end != NULL)
{
*content_end = '<';
}
if(saved_xml_literal != NULL)
{
context->xml_literal = saved_xml_literal;
}
}
if(context->xml_literal != NULL)
{
if(parent_context->xml_literal == NULL)
{
parent_context->xml_literal =
rdfa_replace_string(
parent_context->xml_literal, context->xml_literal);
parent_context->xml_literal_size = context->xml_literal_size;
}
else
{
parent_context->xml_literal =
rdfa_n_append_string(
parent_context->xml_literal, &parent_context->xml_literal_size,
context->xml_literal, context->xml_literal_size);
}
if(context->plain_literal != NULL)
{
if(parent_context->plain_literal == NULL)
{
parent_context->plain_literal =
rdfa_replace_string(
parent_context->plain_literal, context->plain_literal);
parent_context->plain_literal_size = context->plain_literal_size;
}
else
{
parent_context->plain_literal =
rdfa_n_append_string(
parent_context->plain_literal,
&parent_context->plain_literal_size,
context->plain_literal,
context->plain_literal_size);
}
}
}
parent_context->bnode_count = context->bnode_count;
parent_context->underscore_colon_bnode_name = \
rdfa_replace_string(parent_context->underscore_colon_bnode_name,
context->underscore_colon_bnode_name);
if((context->skip_element == 0) && (context->new_subject != NULL))
{
rdfa_complete_incomplete_triples(context);
}
rdfa_free_context(context);
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,537 | raptor_nspace_compare(const void *a, const void *b)
{
raptor_namespace* ns_a=*(raptor_namespace**)a;
raptor_namespace* ns_b=*(raptor_namespace**)b;
if(!ns_a->prefix)
return 1;
else if(!ns_b->prefix)
return -1;
else
return strcmp((const char*)ns_b->prefix, (const char*)ns_a->prefix);
}
| +Info | 0 | raptor_nspace_compare(const void *a, const void *b)
{
raptor_namespace* ns_a=*(raptor_namespace**)a;
raptor_namespace* ns_b=*(raptor_namespace**)b;
if(!ns_a->prefix)
return 1;
else if(!ns_b->prefix)
return -1;
else
return strcmp((const char*)ns_b->prefix, (const char*)ns_a->prefix);
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,538 | static void raptor_rdfa_end_element(void *user_data,
raptor_xml_element* xml_element)
{
raptor_qname* qname=raptor_xml_element_get_name(xml_element);
unsigned char* qname_string=raptor_qname_to_counted_name(qname, NULL);
end_element(user_data, (const char*)qname_string);
raptor_free_memory(qname_string);
}
| +Info | 0 | static void raptor_rdfa_end_element(void *user_data,
raptor_xml_element* xml_element)
{
raptor_qname* qname=raptor_xml_element_get_name(xml_element);
unsigned char* qname_string=raptor_qname_to_counted_name(qname, NULL);
end_element(user_data, (const char*)qname_string);
raptor_free_memory(qname_string);
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,539 | static void raptor_rdfa_namespace_handler(void *user_data,
raptor_namespace* nspace)
{
rdfalist* context_stack = (rdfalist*)user_data;
rdfacontext* context = (rdfacontext*)
context_stack->items[context_stack->num_items - 1]->data;
if(context->namespace_handler)
(*context->namespace_handler)(context->namespace_handler_user_data,
nspace);
}
| +Info | 0 | static void raptor_rdfa_namespace_handler(void *user_data,
raptor_namespace* nspace)
{
rdfalist* context_stack = (rdfalist*)user_data;
rdfacontext* context = (rdfacontext*)
context_stack->items[context_stack->num_items - 1]->data;
if(context->namespace_handler)
(*context->namespace_handler)(context->namespace_handler_user_data,
nspace);
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,540 | static void raptor_rdfa_start_element(void *user_data,
raptor_xml_element *xml_element)
{
raptor_qname* qname=raptor_xml_element_get_name(xml_element);
int attr_count=raptor_xml_element_get_attributes_count(xml_element);
raptor_qname** attrs=raptor_xml_element_get_attributes(xml_element);
unsigned char* qname_string=raptor_qname_to_counted_name(qname, NULL);
char** attr=NULL;
int i;
if(attr_count > 0) {
attr=(char**)malloc(sizeof(char*) * (1+(attr_count*2)));
for(i=0; i<attr_count; i++) {
attr[2*i]=(char*)raptor_qname_to_counted_name(attrs[i], NULL);
attr[1+(2*i)]=(char*)raptor_qname_get_value(attrs[i]);
}
attr[2*i]=NULL;
}
start_element(user_data, (char*)qname_string, (const char**)attr);
raptor_free_memory(qname_string);
if(attr) {
for(i=0; i<attr_count; i++)
raptor_free_memory(attr[2*i]);
free(attr);
}
}
| +Info | 0 | static void raptor_rdfa_start_element(void *user_data,
raptor_xml_element *xml_element)
{
raptor_qname* qname=raptor_xml_element_get_name(xml_element);
int attr_count=raptor_xml_element_get_attributes_count(xml_element);
raptor_qname** attrs=raptor_xml_element_get_attributes(xml_element);
unsigned char* qname_string=raptor_qname_to_counted_name(qname, NULL);
char** attr=NULL;
int i;
if(attr_count > 0) {
attr=(char**)malloc(sizeof(char*) * (1+(attr_count*2)));
for(i=0; i<attr_count; i++) {
attr[2*i]=(char*)raptor_qname_to_counted_name(attrs[i], NULL);
attr[1+(2*i)]=(char*)raptor_qname_get_value(attrs[i]);
}
attr[2*i]=NULL;
}
start_element(user_data, (char*)qname_string, (const char**)attr);
raptor_free_memory(qname_string);
if(attr) {
for(i=0; i<attr_count; i++)
raptor_free_memory(attr[2*i]);
free(attr);
}
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,541 | rdfacontext* rdfa_create_context(const char* base)
{
rdfacontext* rval = NULL;
size_t base_length = strlen(base);
if(base_length > 0)
{
char* cleaned_base;
rval = (rdfacontext*)malloc(sizeof(rdfacontext));
rval->base = NULL;
cleaned_base = rdfa_iri_get_base(base);
rval->base = rdfa_replace_string(rval->base, cleaned_base);
free(cleaned_base);
rval->default_graph_triple_callback = NULL;
rval->buffer_filler_callback = NULL;
rval->processor_graph_triple_callback = NULL;
rval->callback_data = NULL;
/* parse state */
rval->wb_allocated = 0;
rval->working_buffer = NULL;
rval->wb_position = 0;
#ifdef LIBRDFA_IN_RAPTOR
rval->base_uri = NULL;
rval->sax2 = NULL;
rval->namespace_handler = NULL;
rval->namespace_handler_user_data = NULL;
#else
rval->uri_mappings = NULL;
rval->parser = NULL;
#endif
rval->done = 0;
rval->context_stack = NULL;
rval->wb_preread = 0;
rval->preread = 0;
}
else
{
printf("librdfa error: Failed to create a parsing context, "
"base IRI was not specified!\n");
}
return rval;
}
| +Info | 0 | rdfacontext* rdfa_create_context(const char* base)
{
rdfacontext* rval = NULL;
size_t base_length = strlen(base);
if(base_length > 0)
{
char* cleaned_base;
rval = (rdfacontext*)malloc(sizeof(rdfacontext));
rval->base = NULL;
cleaned_base = rdfa_iri_get_base(base);
rval->base = rdfa_replace_string(rval->base, cleaned_base);
free(cleaned_base);
rval->default_graph_triple_callback = NULL;
rval->buffer_filler_callback = NULL;
rval->processor_graph_triple_callback = NULL;
rval->callback_data = NULL;
/* parse state */
rval->wb_allocated = 0;
rval->working_buffer = NULL;
rval->wb_position = 0;
#ifdef LIBRDFA_IN_RAPTOR
rval->base_uri = NULL;
rval->sax2 = NULL;
rval->namespace_handler = NULL;
rval->namespace_handler_user_data = NULL;
#else
rval->uri_mappings = NULL;
rval->parser = NULL;
#endif
rval->done = 0;
rval->context_stack = NULL;
rval->wb_preread = 0;
rval->preread = 0;
}
else
{
printf("librdfa error: Failed to create a parsing context, "
"base IRI was not specified!\n");
}
return rval;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,542 | static rdfacontext* rdfa_create_new_element_context(rdfalist* context_stack)
{
rdfacontext* parent_context = (rdfacontext*)
context_stack->items[context_stack->num_items - 1]->data;
rdfacontext* rval = rdfa_create_context(parent_context->base);
rval->base = rdfa_replace_string(rval->base, parent_context->base);
rdfa_init_context(rval);
#ifndef LIBRDFA_IN_RAPTOR
rdfa_free_mapping(rval->uri_mappings);
rval->uri_mappings = rdfa_copy_mapping(parent_context->uri_mappings);
#endif
if(parent_context->language != NULL)
{
rval->language =
rdfa_replace_string(rval->language, parent_context->language);
}
rval->default_graph_triple_callback =
parent_context->default_graph_triple_callback;
rval->processor_graph_triple_callback =
parent_context->processor_graph_triple_callback;
rval->buffer_filler_callback = parent_context->buffer_filler_callback;
rval->bnode_count = parent_context->bnode_count;
rval->underscore_colon_bnode_name =
rdfa_replace_string(rval->underscore_colon_bnode_name,
parent_context->underscore_colon_bnode_name);
rval->recurse = parent_context->recurse;
rval->skip_element = 0;
rval->callback_data = parent_context->callback_data;
rval->xml_literal_namespaces_defined =
parent_context->xml_literal_namespaces_defined;
rval->xml_literal_xml_lang_defined =
parent_context->xml_literal_xml_lang_defined;
if(parent_context->skip_element == 0)
{
if(parent_context->new_subject != NULL)
{
rval->parent_subject = rdfa_replace_string(
rval->parent_subject, parent_context->new_subject);
}
else
{
rval->parent_subject = rdfa_replace_string(
rval->parent_subject, parent_context->parent_subject);
}
if(parent_context->current_object_resource != NULL)
{
rval->parent_object =
rdfa_replace_string(
rval->parent_object, parent_context->current_object_resource);
}
else if(parent_context->new_subject != NULL)
{
rval->parent_object =
rdfa_replace_string(
rval->parent_object, parent_context->new_subject);
}
else
{
rval->parent_object =
rdfa_replace_string(
rval->parent_object, parent_context->parent_subject);
}
if(rval->incomplete_triples != NULL)
{
rdfa_free_list(rval->incomplete_triples);
}
rval->incomplete_triples =
rdfa_copy_list(parent_context->local_incomplete_triples);
}
else
{
rval->parent_subject = rdfa_replace_string(
rval->parent_subject, parent_context->parent_subject);
rval->parent_object = rdfa_replace_string(
rval->parent_object, parent_context->parent_object);
rdfa_free_list(rval->incomplete_triples);
rval->incomplete_triples =
rdfa_copy_list(parent_context->incomplete_triples);
rdfa_free_list(rval->local_incomplete_triples);
rval->local_incomplete_triples =
rdfa_copy_list(parent_context->local_incomplete_triples);
}
#ifdef LIBRDFA_IN_RAPTOR
rval->base_uri = parent_context->base_uri;
rval->sax2 = parent_context->sax2;
rval->namespace_handler = parent_context->namespace_handler;
rval->namespace_handler_user_data = parent_context->namespace_handler_user_data;
#endif
return rval;
}
| +Info | 0 | static rdfacontext* rdfa_create_new_element_context(rdfalist* context_stack)
{
rdfacontext* parent_context = (rdfacontext*)
context_stack->items[context_stack->num_items - 1]->data;
rdfacontext* rval = rdfa_create_context(parent_context->base);
rval->base = rdfa_replace_string(rval->base, parent_context->base);
rdfa_init_context(rval);
#ifndef LIBRDFA_IN_RAPTOR
rdfa_free_mapping(rval->uri_mappings);
rval->uri_mappings = rdfa_copy_mapping(parent_context->uri_mappings);
#endif
if(parent_context->language != NULL)
{
rval->language =
rdfa_replace_string(rval->language, parent_context->language);
}
rval->default_graph_triple_callback =
parent_context->default_graph_triple_callback;
rval->processor_graph_triple_callback =
parent_context->processor_graph_triple_callback;
rval->buffer_filler_callback = parent_context->buffer_filler_callback;
rval->bnode_count = parent_context->bnode_count;
rval->underscore_colon_bnode_name =
rdfa_replace_string(rval->underscore_colon_bnode_name,
parent_context->underscore_colon_bnode_name);
rval->recurse = parent_context->recurse;
rval->skip_element = 0;
rval->callback_data = parent_context->callback_data;
rval->xml_literal_namespaces_defined =
parent_context->xml_literal_namespaces_defined;
rval->xml_literal_xml_lang_defined =
parent_context->xml_literal_xml_lang_defined;
if(parent_context->skip_element == 0)
{
if(parent_context->new_subject != NULL)
{
rval->parent_subject = rdfa_replace_string(
rval->parent_subject, parent_context->new_subject);
}
else
{
rval->parent_subject = rdfa_replace_string(
rval->parent_subject, parent_context->parent_subject);
}
if(parent_context->current_object_resource != NULL)
{
rval->parent_object =
rdfa_replace_string(
rval->parent_object, parent_context->current_object_resource);
}
else if(parent_context->new_subject != NULL)
{
rval->parent_object =
rdfa_replace_string(
rval->parent_object, parent_context->new_subject);
}
else
{
rval->parent_object =
rdfa_replace_string(
rval->parent_object, parent_context->parent_subject);
}
if(rval->incomplete_triples != NULL)
{
rdfa_free_list(rval->incomplete_triples);
}
rval->incomplete_triples =
rdfa_copy_list(parent_context->local_incomplete_triples);
}
else
{
rval->parent_subject = rdfa_replace_string(
rval->parent_subject, parent_context->parent_subject);
rval->parent_object = rdfa_replace_string(
rval->parent_object, parent_context->parent_object);
rdfa_free_list(rval->incomplete_triples);
rval->incomplete_triples =
rdfa_copy_list(parent_context->incomplete_triples);
rdfa_free_list(rval->local_incomplete_triples);
rval->local_incomplete_triples =
rdfa_copy_list(parent_context->local_incomplete_triples);
}
#ifdef LIBRDFA_IN_RAPTOR
rval->base_uri = parent_context->base_uri;
rval->sax2 = parent_context->sax2;
rval->namespace_handler = parent_context->namespace_handler;
rval->namespace_handler_user_data = parent_context->namespace_handler_user_data;
#endif
return rval;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,543 | void rdfa_free_context(rdfacontext* context)
{
free(context->base);
free(context->parent_subject);
free(context->parent_object);
#ifndef LIBRDFA_IN_RAPTOR
rdfa_free_mapping(context->uri_mappings);
#endif
rdfa_free_list(context->incomplete_triples);
free(context->language);
free(context->underscore_colon_bnode_name);
free(context->new_subject);
free(context->current_object_resource);
free(context->content);
free(context->datatype);
rdfa_free_list(context->property);
free(context->plain_literal);
free(context->xml_literal);
rdfa_free_list(context->local_incomplete_triples);
rdfa_free_context_stack(context);
free(context->working_buffer);
free(context);
}
| +Info | 0 | void rdfa_free_context(rdfacontext* context)
{
free(context->base);
free(context->parent_subject);
free(context->parent_object);
#ifndef LIBRDFA_IN_RAPTOR
rdfa_free_mapping(context->uri_mappings);
#endif
rdfa_free_list(context->incomplete_triples);
free(context->language);
free(context->underscore_colon_bnode_name);
free(context->new_subject);
free(context->current_object_resource);
free(context->content);
free(context->datatype);
rdfa_free_list(context->property);
free(context->plain_literal);
free(context->xml_literal);
rdfa_free_list(context->local_incomplete_triples);
rdfa_free_context_stack(context);
free(context->working_buffer);
free(context);
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,544 | static void rdfa_free_context_stack(rdfacontext* context)
{
if(context->context_stack != NULL)
{
void* rval;
do
{
rval = rdfa_pop_item(context->context_stack);
if(rval && rval != context)
{
rdfa_free_context((rdfacontext*)rval);
}
}
while(rval);
free(context->context_stack->items);
free(context->context_stack);
context->context_stack = NULL;
}
}
| +Info | 0 | static void rdfa_free_context_stack(rdfacontext* context)
{
if(context->context_stack != NULL)
{
void* rval;
do
{
rval = rdfa_pop_item(context->context_stack);
if(rval && rval != context)
{
rdfa_free_context((rdfacontext*)rval);
}
}
while(rval);
free(context->context_stack->items);
free(context->context_stack);
context->context_stack = NULL;
}
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,545 | char* rdfa_get_buffer(rdfacontext* context, size_t* blen)
{
*blen = context->wb_allocated;
return context->working_buffer;
}
| +Info | 0 | char* rdfa_get_buffer(rdfacontext* context, size_t* blen)
{
*blen = context->wb_allocated;
return context->working_buffer;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,546 | static size_t rdfa_init_base(
rdfacontext* context, char** working_buffer, size_t* working_buffer_size,
char* temp_buffer, size_t bytes_read)
{
char* head_end = NULL;
size_t offset = context->wb_position;
size_t needed_size = (offset + bytes_read) - *working_buffer_size;
if(needed_size > 0)
{
size_t temp_buffer_size = sizeof(char) * READ_BUFFER_SIZE;
if((size_t)needed_size > temp_buffer_size)
temp_buffer_size += needed_size;
*working_buffer_size += temp_buffer_size;
*working_buffer = (char*)realloc(*working_buffer, *working_buffer_size + 1);
}
memmove(*working_buffer + offset, temp_buffer, bytes_read);
*(*working_buffer + offset + bytes_read) = '\0';
head_end = strstr(*working_buffer, "</head>");
if(head_end == NULL)
head_end = strstr(*working_buffer, "</HEAD>");
context->wb_position += bytes_read;
if(head_end == NULL)
return bytes_read;
if(head_end != NULL)
{
char* base_start = strstr(*working_buffer, "<base ");
if(base_start == NULL)
base_start = strstr(*working_buffer, "<BASE ");
if(base_start != NULL)
{
char* href_start = strstr(base_start, "href=");
char sep = href_start[5];
char* uri_start = href_start + 6;
char* uri_end = strchr(uri_start, sep);
if((uri_start != NULL) && (uri_end != NULL))
{
if(*uri_start != sep)
{
size_t uri_size = uri_end - uri_start;
char* temp_uri = (char*)malloc(sizeof(char) * uri_size + 1);
char* cleaned_base;
strncpy(temp_uri, uri_start, uri_size);
temp_uri[uri_size] = '\0';
cleaned_base = rdfa_iri_get_base(temp_uri);
context->current_object_resource =
rdfa_replace_string(
context->current_object_resource, cleaned_base);
context->base =
rdfa_replace_string(context->base, cleaned_base);
free(cleaned_base);
free(temp_uri);
}
}
}
}
return bytes_read;
}
| +Info | 0 | static size_t rdfa_init_base(
rdfacontext* context, char** working_buffer, size_t* working_buffer_size,
char* temp_buffer, size_t bytes_read)
{
char* head_end = NULL;
size_t offset = context->wb_position;
size_t needed_size = (offset + bytes_read) - *working_buffer_size;
if(needed_size > 0)
{
size_t temp_buffer_size = sizeof(char) * READ_BUFFER_SIZE;
if((size_t)needed_size > temp_buffer_size)
temp_buffer_size += needed_size;
*working_buffer_size += temp_buffer_size;
*working_buffer = (char*)realloc(*working_buffer, *working_buffer_size + 1);
}
memmove(*working_buffer + offset, temp_buffer, bytes_read);
*(*working_buffer + offset + bytes_read) = '\0';
head_end = strstr(*working_buffer, "</head>");
if(head_end == NULL)
head_end = strstr(*working_buffer, "</HEAD>");
context->wb_position += bytes_read;
if(head_end == NULL)
return bytes_read;
if(head_end != NULL)
{
char* base_start = strstr(*working_buffer, "<base ");
if(base_start == NULL)
base_start = strstr(*working_buffer, "<BASE ");
if(base_start != NULL)
{
char* href_start = strstr(base_start, "href=");
char sep = href_start[5];
char* uri_start = href_start + 6;
char* uri_end = strchr(uri_start, sep);
if((uri_start != NULL) && (uri_end != NULL))
{
if(*uri_start != sep)
{
size_t uri_size = uri_end - uri_start;
char* temp_uri = (char*)malloc(sizeof(char) * uri_size + 1);
char* cleaned_base;
strncpy(temp_uri, uri_start, uri_size);
temp_uri[uri_size] = '\0';
cleaned_base = rdfa_iri_get_base(temp_uri);
context->current_object_resource =
rdfa_replace_string(
context->current_object_resource, cleaned_base);
context->base =
rdfa_replace_string(context->base, cleaned_base);
free(cleaned_base);
free(temp_uri);
}
}
}
}
return bytes_read;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,547 | int rdfa_parse(rdfacontext* context)
{
int rval;
rval = rdfa_parse_start(context);
if(rval != RDFA_PARSE_SUCCESS)
{
context->done = 1;
return rval;
}
do
{
size_t wblen;
int done;
wblen = context->buffer_filler_callback(
context->working_buffer, context->wb_allocated,
context->callback_data);
done = (wblen == 0);
rval = rdfa_parse_chunk(context, context->working_buffer, wblen, done);
context->done=done;
}
while(!context->done && rval == RDFA_PARSE_SUCCESS);
rdfa_parse_end(context);
return rval;
}
| +Info | 0 | int rdfa_parse(rdfacontext* context)
{
int rval;
rval = rdfa_parse_start(context);
if(rval != RDFA_PARSE_SUCCESS)
{
context->done = 1;
return rval;
}
do
{
size_t wblen;
int done;
wblen = context->buffer_filler_callback(
context->working_buffer, context->wb_allocated,
context->callback_data);
done = (wblen == 0);
rval = rdfa_parse_chunk(context, context->working_buffer, wblen, done);
context->done=done;
}
while(!context->done && rval == RDFA_PARSE_SUCCESS);
rdfa_parse_end(context);
return rval;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,548 | int rdfa_parse_chunk(rdfacontext* context, char* data, size_t wblen, int done)
{
if(context->done)
{
return RDFA_PARSE_FAILED;
}
if(!context->preread)
{
context->wb_preread = rdfa_init_base(context,
&context->working_buffer, &context->wb_allocated, data, wblen);
if(!context->base && context->wb_preread < (1<<17))
return RDFA_PARSE_SUCCESS;
rdfa_process_doctype(context, &wblen);
#ifdef LIBRDFA_IN_RAPTOR
if(raptor_sax2_parse_chunk(context->sax2,
(const unsigned char*)context->working_buffer,
context->wb_position, done))
{
return RDFA_PARSE_FAILED;
}
#else
if(XML_Parse(context->parser, context->working_buffer,
context->wb_position, 0) == XML_STATUS_ERROR)
{
rdfa_report_error(context, data, wblen);
return RDFA_PARSE_FAILED;
}
#endif
context->preread = 1;
return RDFA_PARSE_SUCCESS;
}
#ifdef LIBRDFA_IN_RAPTOR
if(raptor_sax2_parse_chunk(context->sax2, (const unsigned char*)data, wblen, done))
{
return RDFA_PARSE_FAILED;
}
#else
if(XML_Parse(context->parser, data, wblen, done) == XML_STATUS_ERROR)
{
rdfa_report_error(context, data, wblen);
return RDFA_PARSE_FAILED;
}
#endif
return RDFA_PARSE_SUCCESS;
}
| +Info | 0 | int rdfa_parse_chunk(rdfacontext* context, char* data, size_t wblen, int done)
{
if(context->done)
{
return RDFA_PARSE_FAILED;
}
if(!context->preread)
{
context->wb_preread = rdfa_init_base(context,
&context->working_buffer, &context->wb_allocated, data, wblen);
if(!context->base && context->wb_preread < (1<<17))
return RDFA_PARSE_SUCCESS;
rdfa_process_doctype(context, &wblen);
#ifdef LIBRDFA_IN_RAPTOR
if(raptor_sax2_parse_chunk(context->sax2,
(const unsigned char*)context->working_buffer,
context->wb_position, done))
{
return RDFA_PARSE_FAILED;
}
#else
if(XML_Parse(context->parser, context->working_buffer,
context->wb_position, 0) == XML_STATUS_ERROR)
{
rdfa_report_error(context, data, wblen);
return RDFA_PARSE_FAILED;
}
#endif
context->preread = 1;
return RDFA_PARSE_SUCCESS;
}
#ifdef LIBRDFA_IN_RAPTOR
if(raptor_sax2_parse_chunk(context->sax2, (const unsigned char*)data, wblen, done))
{
return RDFA_PARSE_FAILED;
}
#else
if(XML_Parse(context->parser, data, wblen, done) == XML_STATUS_ERROR)
{
rdfa_report_error(context, data, wblen);
return RDFA_PARSE_FAILED;
}
#endif
return RDFA_PARSE_SUCCESS;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,549 | void rdfa_parse_end(rdfacontext* context)
{
rdfa_free_context_stack(context);
#ifdef LIBRDFA_IN_RAPTOR
if(context->base_uri)
raptor_free_uri(context->base_uri);
raptor_free_sax2(context->sax2);
context->sax2=NULL;
#else
XML_ParserFree(context->parser);
#endif
}
| +Info | 0 | void rdfa_parse_end(rdfacontext* context)
{
rdfa_free_context_stack(context);
#ifdef LIBRDFA_IN_RAPTOR
if(context->base_uri)
raptor_free_uri(context->base_uri);
raptor_free_sax2(context->sax2);
context->sax2=NULL;
#else
XML_ParserFree(context->parser);
#endif
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,550 | static void rdfa_report_error(rdfacontext* context, char* data, size_t length)
{
char* buffer = malloc(2<<12);
snprintf(buffer, 2<<12, "XML parsing error: %s at line %d, column %d.",
XML_ErrorString(XML_GetErrorCode(context->parser)),
(int)XML_GetCurrentLineNumber(context->parser),
(int)XML_GetCurrentColumnNumber(context->parser));
if(context->processor_graph_triple_callback != NULL)
{
char* error_subject = rdfa_create_bnode(context);
char* pointer_subject = rdfa_create_bnode(context);
rdftriple* triple = rdfa_create_triple(
error_subject, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://www.w3.org/ns/rdfa_processing_graph#Error",
RDF_TYPE_IRI, NULL, NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
triple = rdfa_create_triple(
error_subject, "http://purl.org/dc/terms/description", buffer,
RDF_TYPE_PLAIN_LITERAL, NULL, "en");
context->processor_graph_triple_callback(triple, context->callback_data);
triple = rdfa_create_triple(
error_subject, "http://www.w3.org/ns/rdfa_processing_graph#context",
pointer_subject, RDF_TYPE_IRI, NULL, NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
triple = rdfa_create_triple(
pointer_subject, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://www.w3.org/2009/pointers#LineCharPointer",
RDF_TYPE_IRI, NULL, NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
snprintf(buffer, 2<<12, "%d",
(int)XML_GetCurrentLineNumber(context->parser));
triple = rdfa_create_triple(
pointer_subject, "http://www.w3.org/2009/pointers#lineNumber",
buffer, RDF_TYPE_TYPED_LITERAL,
"http://www.w3.org/2001/XMLSchema#positiveInteger", NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
snprintf(buffer, 2<<12, "%d",
(int)XML_GetCurrentColumnNumber(context->parser));
triple = rdfa_create_triple(
pointer_subject, "http://www.w3.org/2009/pointers#charNumber",
buffer, RDF_TYPE_TYPED_LITERAL,
"http://www.w3.org/2001/XMLSchema#positiveInteger", NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
free(error_subject);
free(pointer_subject);
}
else
{
printf("librdfa processor error: %s\n", buffer);
}
free(buffer);
}
| +Info | 0 | static void rdfa_report_error(rdfacontext* context, char* data, size_t length)
{
char* buffer = malloc(2<<12);
snprintf(buffer, 2<<12, "XML parsing error: %s at line %d, column %d.",
XML_ErrorString(XML_GetErrorCode(context->parser)),
(int)XML_GetCurrentLineNumber(context->parser),
(int)XML_GetCurrentColumnNumber(context->parser));
if(context->processor_graph_triple_callback != NULL)
{
char* error_subject = rdfa_create_bnode(context);
char* pointer_subject = rdfa_create_bnode(context);
rdftriple* triple = rdfa_create_triple(
error_subject, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://www.w3.org/ns/rdfa_processing_graph#Error",
RDF_TYPE_IRI, NULL, NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
triple = rdfa_create_triple(
error_subject, "http://purl.org/dc/terms/description", buffer,
RDF_TYPE_PLAIN_LITERAL, NULL, "en");
context->processor_graph_triple_callback(triple, context->callback_data);
triple = rdfa_create_triple(
error_subject, "http://www.w3.org/ns/rdfa_processing_graph#context",
pointer_subject, RDF_TYPE_IRI, NULL, NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
triple = rdfa_create_triple(
pointer_subject, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://www.w3.org/2009/pointers#LineCharPointer",
RDF_TYPE_IRI, NULL, NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
snprintf(buffer, 2<<12, "%d",
(int)XML_GetCurrentLineNumber(context->parser));
triple = rdfa_create_triple(
pointer_subject, "http://www.w3.org/2009/pointers#lineNumber",
buffer, RDF_TYPE_TYPED_LITERAL,
"http://www.w3.org/2001/XMLSchema#positiveInteger", NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
snprintf(buffer, 2<<12, "%d",
(int)XML_GetCurrentColumnNumber(context->parser));
triple = rdfa_create_triple(
pointer_subject, "http://www.w3.org/2009/pointers#charNumber",
buffer, RDF_TYPE_TYPED_LITERAL,
"http://www.w3.org/2001/XMLSchema#positiveInteger", NULL);
context->processor_graph_triple_callback(triple, context->callback_data);
free(error_subject);
free(pointer_subject);
}
else
{
printf("librdfa processor error: %s\n", buffer);
}
free(buffer);
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,551 | void rdfa_set_buffer_filler(rdfacontext* context, buffer_filler_fp bf)
{
context->buffer_filler_callback = bf;
}
| +Info | 0 | void rdfa_set_buffer_filler(rdfacontext* context, buffer_filler_fp bf)
{
context->buffer_filler_callback = bf;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,552 | void rdfa_set_default_graph_triple_handler(
rdfacontext* context, triple_handler_fp th)
{
context->default_graph_triple_callback = th;
}
| +Info | 0 | void rdfa_set_default_graph_triple_handler(
rdfacontext* context, triple_handler_fp th)
{
context->default_graph_triple_callback = th;
}
| @@ -1230,6 +1230,9 @@ int rdfa_parse_start(rdfacontext* context)
raptor_sax2_set_option(context->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(context->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(context->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,553 | raptor_libxml_endDocument(void* user_data) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
xmlParserCtxtPtr xc = sax2->xc;
libxml2_endDocument(sax2->xc);
if(xc->myDoc) {
xmlFreeDoc(xc->myDoc);
xc->myDoc = NULL;
}
}
| +Info | 0 | raptor_libxml_endDocument(void* user_data) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
xmlParserCtxtPtr xc = sax2->xc;
libxml2_endDocument(sax2->xc);
if(xc->myDoc) {
xmlFreeDoc(xc->myDoc);
xc->myDoc = NULL;
}
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,554 | raptor_libxml_entityDecl(void* user_data, const xmlChar *name, int type,
const xmlChar *publicId, const xmlChar *systemId,
xmlChar *content) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_entityDecl(sax2->xc, name, type, publicId, systemId, content);
}
| +Info | 0 | raptor_libxml_entityDecl(void* user_data, const xmlChar *name, int type,
const xmlChar *publicId, const xmlChar *systemId,
xmlChar *content) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_entityDecl(sax2->xc, name, type, publicId, systemId, content);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,555 | raptor_libxml_error(void* user_data, const char *msg, ...)
{
va_list args;
va_start(args, msg);
raptor_libxml_error_common(user_data, msg, args, xml_error_prefix, 0);
va_end(args);
}
| +Info | 0 | raptor_libxml_error(void* user_data, const char *msg, ...)
{
va_list args;
va_start(args, msg);
raptor_libxml_error_common(user_data, msg, args, xml_error_prefix, 0);
va_end(args);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,556 | raptor_libxml_error_common(void* user_data, const char *msg, va_list args,
const char *prefix, int is_fatal)
{
raptor_sax2* sax2 = NULL;
int prefix_length = RAPTOR_BAD_CAST(int, strlen(prefix));
int length;
char *nmsg;
int msg_len;
raptor_world* world = NULL;
raptor_locator* locator = NULL;
if(user_data) {
/* Work around libxml2 bug - sometimes the sax2->error
* returns a user_data, sometimes the userdata
*/
if(((raptor_sax2*)user_data)->magic == RAPTOR_LIBXML_MAGIC)
sax2 = (raptor_sax2*)user_data;
else
/* user_data is not userData */
sax2 = (raptor_sax2*)((xmlParserCtxtPtr)user_data)->userData;
}
if(sax2) {
world = sax2->world;
locator = sax2->locator;
if(locator)
raptor_libxml_update_document_locator(sax2, sax2->locator);
}
msg_len = RAPTOR_BAD_CAST(int, strlen(msg));
length = prefix_length + msg_len + 1;
nmsg = RAPTOR_MALLOC(char*, length);
if(nmsg) {
memcpy(nmsg, prefix, prefix_length); /* Do not copy NUL */
memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */
if(nmsg[length-1] == '\n')
nmsg[length-1]='\0';
}
if(is_fatal)
raptor_log_error_varargs(world,
RAPTOR_LOG_LEVEL_FATAL,
locator,
nmsg ? nmsg : msg,
args);
else
raptor_log_error_varargs(world,
RAPTOR_LOG_LEVEL_ERROR,
locator,
nmsg ? nmsg : msg,
args);
if(nmsg)
RAPTOR_FREE(char*, nmsg);
}
| +Info | 0 | raptor_libxml_error_common(void* user_data, const char *msg, va_list args,
const char *prefix, int is_fatal)
{
raptor_sax2* sax2 = NULL;
int prefix_length = RAPTOR_BAD_CAST(int, strlen(prefix));
int length;
char *nmsg;
int msg_len;
raptor_world* world = NULL;
raptor_locator* locator = NULL;
if(user_data) {
/* Work around libxml2 bug - sometimes the sax2->error
* returns a user_data, sometimes the userdata
*/
if(((raptor_sax2*)user_data)->magic == RAPTOR_LIBXML_MAGIC)
sax2 = (raptor_sax2*)user_data;
else
/* user_data is not userData */
sax2 = (raptor_sax2*)((xmlParserCtxtPtr)user_data)->userData;
}
if(sax2) {
world = sax2->world;
locator = sax2->locator;
if(locator)
raptor_libxml_update_document_locator(sax2, sax2->locator);
}
msg_len = RAPTOR_BAD_CAST(int, strlen(msg));
length = prefix_length + msg_len + 1;
nmsg = RAPTOR_MALLOC(char*, length);
if(nmsg) {
memcpy(nmsg, prefix, prefix_length); /* Do not copy NUL */
memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */
if(nmsg[length-1] == '\n')
nmsg[length-1]='\0';
}
if(is_fatal)
raptor_log_error_varargs(world,
RAPTOR_LOG_LEVEL_FATAL,
locator,
nmsg ? nmsg : msg,
args);
else
raptor_log_error_varargs(world,
RAPTOR_LOG_LEVEL_ERROR,
locator,
nmsg ? nmsg : msg,
args);
if(nmsg)
RAPTOR_FREE(char*, nmsg);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,557 | raptor_libxml_externalSubset(void* user_data, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_externalSubset(sax2->xc, name, ExternalID, SystemID);
}
| +Info | 0 | raptor_libxml_externalSubset(void* user_data, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_externalSubset(sax2->xc, name, ExternalID, SystemID);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,558 | raptor_libxml_fatal_error(void* user_data, const char *msg, ...)
{
va_list args;
va_start(args, msg);
raptor_libxml_error_common(user_data, msg, args, xml_fatal_error_prefix, 1);
va_end(args);
}
| +Info | 0 | raptor_libxml_fatal_error(void* user_data, const char *msg, ...)
{
va_list args;
va_start(args, msg);
raptor_libxml_error_common(user_data, msg, args, xml_fatal_error_prefix, 1);
va_end(args);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,559 | raptor_libxml_finish(raptor_world* world)
{
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_STRUCTURED_ERROR_SAVE)
xmlSetStructuredErrorFunc(world->libxml_saved_structured_error_context,
world->libxml_saved_structured_error_handler);
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_GENERIC_ERROR_SAVE)
xmlSetGenericErrorFunc(world->libxml_saved_generic_error_context,
world->libxml_saved_generic_error_handler);
xmlCleanupParser();
}
| +Info | 0 | raptor_libxml_finish(raptor_world* world)
{
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_STRUCTURED_ERROR_SAVE)
xmlSetStructuredErrorFunc(world->libxml_saved_structured_error_context,
world->libxml_saved_structured_error_handler);
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_GENERIC_ERROR_SAVE)
xmlSetGenericErrorFunc(world->libxml_saved_generic_error_context,
world->libxml_saved_generic_error_handler);
xmlCleanupParser();
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,560 | raptor_libxml_free(xmlParserCtxtPtr xc) {
libxml2_endDocument(xc);
if(xc->myDoc) {
xmlFreeDoc(xc->myDoc);
xc->myDoc = NULL;
}
xmlFreeParserCtxt(xc);
}
| +Info | 0 | raptor_libxml_free(xmlParserCtxtPtr xc) {
libxml2_endDocument(xc);
if(xc->myDoc) {
xmlFreeDoc(xc->myDoc);
xc->myDoc = NULL;
}
xmlFreeParserCtxt(xc);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,561 | raptor_libxml_generic_error(void* user_data, const char *msg, ...)
{
raptor_world* world = (raptor_world*)user_data;
va_list args;
const char* prefix = xml_generic_error_prefix;
int prefix_length = RAPTOR_BAD_CAST(int, strlen(prefix));
int length;
char *nmsg;
int msg_len;
va_start(args, msg);
msg_len = RAPTOR_BAD_CAST(int, strlen(msg));
length = prefix_length + msg_len + 1;
nmsg = RAPTOR_MALLOC(char*, length);
if(nmsg) {
memcpy(nmsg, prefix, prefix_length); /* Do not copy NUL */
memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */
if(nmsg[length-1] == '\n')
nmsg[length-1]='\0';
}
raptor_log_error_varargs(world, RAPTOR_LOG_LEVEL_ERROR,
/* locator */ NULL,
nmsg ? nmsg : msg,
args);
if(nmsg)
RAPTOR_FREE(char*, nmsg);
va_end(args);
}
| +Info | 0 | raptor_libxml_generic_error(void* user_data, const char *msg, ...)
{
raptor_world* world = (raptor_world*)user_data;
va_list args;
const char* prefix = xml_generic_error_prefix;
int prefix_length = RAPTOR_BAD_CAST(int, strlen(prefix));
int length;
char *nmsg;
int msg_len;
va_start(args, msg);
msg_len = RAPTOR_BAD_CAST(int, strlen(msg));
length = prefix_length + msg_len + 1;
nmsg = RAPTOR_MALLOC(char*, length);
if(nmsg) {
memcpy(nmsg, prefix, prefix_length); /* Do not copy NUL */
memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */
if(nmsg[length-1] == '\n')
nmsg[length-1]='\0';
}
raptor_log_error_varargs(world, RAPTOR_LOG_LEVEL_ERROR,
/* locator */ NULL,
nmsg ? nmsg : msg,
args);
if(nmsg)
RAPTOR_FREE(char*, nmsg);
va_end(args);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,562 | raptor_libxml_hasExternalSubset (void* user_data)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
return libxml2_hasExternalSubset(sax2->xc);
}
| +Info | 0 | raptor_libxml_hasExternalSubset (void* user_data)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
return libxml2_hasExternalSubset(sax2->xc);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,563 | raptor_libxml_init(raptor_world* world)
{
xmlInitParser();
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_STRUCTURED_ERROR_SAVE) {
world->libxml_saved_structured_error_context = xmlGenericErrorContext;
world->libxml_saved_structured_error_handler = xmlStructuredError;
/* sets xmlGenericErrorContext and xmlStructuredError */
xmlSetStructuredErrorFunc(world,
(xmlStructuredErrorFunc)raptor_libxml_xmlStructuredError_handler_global);
}
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_GENERIC_ERROR_SAVE) {
world->libxml_saved_generic_error_context = xmlGenericErrorContext;
world->libxml_saved_generic_error_handler = xmlGenericError;
/* sets xmlGenericErrorContext and xmlGenericError */
xmlSetGenericErrorFunc(world,
(xmlGenericErrorFunc)raptor_libxml_generic_error);
}
return 0;
}
| +Info | 0 | raptor_libxml_init(raptor_world* world)
{
xmlInitParser();
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_STRUCTURED_ERROR_SAVE) {
world->libxml_saved_structured_error_context = xmlGenericErrorContext;
world->libxml_saved_structured_error_handler = xmlStructuredError;
/* sets xmlGenericErrorContext and xmlStructuredError */
xmlSetStructuredErrorFunc(world,
(xmlStructuredErrorFunc)raptor_libxml_xmlStructuredError_handler_global);
}
if(world->libxml_flags & RAPTOR_WORLD_FLAG_LIBXML_GENERIC_ERROR_SAVE) {
world->libxml_saved_generic_error_context = xmlGenericErrorContext;
world->libxml_saved_generic_error_handler = xmlGenericError;
/* sets xmlGenericErrorContext and xmlGenericError */
xmlSetGenericErrorFunc(world,
(xmlGenericErrorFunc)raptor_libxml_generic_error);
}
return 0;
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,564 | raptor_libxml_internalSubset(void* user_data, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_internalSubset(sax2->xc, name, ExternalID, SystemID);
}
| +Info | 0 | raptor_libxml_internalSubset(void* user_data, const xmlChar *name,
const xmlChar *ExternalID, const xmlChar *SystemID) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_internalSubset(sax2->xc, name, ExternalID, SystemID);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,565 | raptor_libxml_isStandalone (void* user_data)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
return libxml2_isStandalone(sax2->xc);
}
| +Info | 0 | raptor_libxml_isStandalone (void* user_data)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
return libxml2_isStandalone(sax2->xc);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,566 | raptor_libxml_sax_init(raptor_sax2* sax2)
{
xmlSAXHandler *sax = &sax2->sax;
sax->internalSubset = raptor_libxml_internalSubset;
sax->isStandalone = raptor_libxml_isStandalone;
sax->hasInternalSubset = raptor_libxml_hasInternalSubset;
sax->hasExternalSubset = raptor_libxml_hasExternalSubset;
sax->resolveEntity = raptor_libxml_resolveEntity;
sax->getEntity = raptor_libxml_getEntity;
sax->getParameterEntity = raptor_libxml_getParameterEntity;
sax->entityDecl = raptor_libxml_entityDecl;
sax->attributeDecl = NULL; /* attributeDecl */
sax->elementDecl = NULL; /* elementDecl */
sax->notationDecl = NULL; /* notationDecl */
sax->unparsedEntityDecl = raptor_libxml_unparsedEntityDecl;
sax->setDocumentLocator = raptor_libxml_set_document_locator;
sax->startDocument = raptor_libxml_startDocument;
sax->endDocument = raptor_libxml_endDocument;
sax->startElement= raptor_sax2_start_element;
sax->endElement= raptor_sax2_end_element;
sax->reference = NULL; /* reference */
sax->characters= raptor_sax2_characters;
sax->cdataBlock= raptor_sax2_cdata; /* like <![CDATA[...]> */
sax->ignorableWhitespace= raptor_sax2_cdata;
sax->processingInstruction = NULL; /* processingInstruction */
sax->comment = raptor_sax2_comment; /* comment */
sax->warning = (warningSAXFunc)raptor_libxml_warning;
sax->error = (errorSAXFunc)raptor_libxml_error;
sax->fatalError = (fatalErrorSAXFunc)raptor_libxml_fatal_error;
sax->serror = (xmlStructuredErrorFunc)raptor_libxml_xmlStructuredError_handler_parsing;
#ifdef RAPTOR_LIBXML_XMLSAXHANDLER_EXTERNALSUBSET
sax->externalSubset = raptor_libxml_externalSubset;
#endif
#ifdef RAPTOR_LIBXML_XMLSAXHANDLER_INITIALIZED
sax->initialized = 1;
#endif
}
| +Info | 0 | raptor_libxml_sax_init(raptor_sax2* sax2)
{
xmlSAXHandler *sax = &sax2->sax;
sax->internalSubset = raptor_libxml_internalSubset;
sax->isStandalone = raptor_libxml_isStandalone;
sax->hasInternalSubset = raptor_libxml_hasInternalSubset;
sax->hasExternalSubset = raptor_libxml_hasExternalSubset;
sax->resolveEntity = raptor_libxml_resolveEntity;
sax->getEntity = raptor_libxml_getEntity;
sax->getParameterEntity = raptor_libxml_getParameterEntity;
sax->entityDecl = raptor_libxml_entityDecl;
sax->attributeDecl = NULL; /* attributeDecl */
sax->elementDecl = NULL; /* elementDecl */
sax->notationDecl = NULL; /* notationDecl */
sax->unparsedEntityDecl = raptor_libxml_unparsedEntityDecl;
sax->setDocumentLocator = raptor_libxml_set_document_locator;
sax->startDocument = raptor_libxml_startDocument;
sax->endDocument = raptor_libxml_endDocument;
sax->startElement= raptor_sax2_start_element;
sax->endElement= raptor_sax2_end_element;
sax->reference = NULL; /* reference */
sax->characters= raptor_sax2_characters;
sax->cdataBlock= raptor_sax2_cdata; /* like <![CDATA[...]> */
sax->ignorableWhitespace= raptor_sax2_cdata;
sax->processingInstruction = NULL; /* processingInstruction */
sax->comment = raptor_sax2_comment; /* comment */
sax->warning = (warningSAXFunc)raptor_libxml_warning;
sax->error = (errorSAXFunc)raptor_libxml_error;
sax->fatalError = (fatalErrorSAXFunc)raptor_libxml_fatal_error;
sax->serror = (xmlStructuredErrorFunc)raptor_libxml_xmlStructuredError_handler_parsing;
#ifdef RAPTOR_LIBXML_XMLSAXHANDLER_EXTERNALSUBSET
sax->externalSubset = raptor_libxml_externalSubset;
#endif
#ifdef RAPTOR_LIBXML_XMLSAXHANDLER_INITIALIZED
sax->initialized = 1;
#endif
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,567 | raptor_libxml_set_document_locator(void* user_data, xmlSAXLocatorPtr loc)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
sax2->loc = loc;
}
| +Info | 0 | raptor_libxml_set_document_locator(void* user_data, xmlSAXLocatorPtr loc)
{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
sax2->loc = loc;
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,568 | raptor_libxml_startDocument(void* user_data) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_startDocument(sax2->xc);
}
| +Info | 0 | raptor_libxml_startDocument(void* user_data) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_startDocument(sax2->xc);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,569 | raptor_libxml_unparsedEntityDecl(void* user_data, const xmlChar *name,
const xmlChar *publicId, const xmlChar *systemId,
const xmlChar *notationName) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_unparsedEntityDecl(sax2->xc, name, publicId, systemId, notationName);
}
| +Info | 0 | raptor_libxml_unparsedEntityDecl(void* user_data, const xmlChar *name,
const xmlChar *publicId, const xmlChar *systemId,
const xmlChar *notationName) {
raptor_sax2* sax2 = (raptor_sax2*)user_data;
libxml2_unparsedEntityDecl(sax2->xc, name, publicId, systemId, notationName);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,570 | raptor_libxml_update_document_locator(raptor_sax2* sax2,
raptor_locator* locator)
{
/* for storing error info */
xmlSAXLocatorPtr loc = sax2 ? sax2->loc : NULL;
xmlParserCtxtPtr xc= sax2 ? sax2->xc : NULL;
if(xc && xc->inSubset)
return;
if(!locator)
return;
locator->line= -1;
locator->column= -1;
if(!xc)
return;
if(loc) {
locator->line = loc->getLineNumber(xc);
/* Seems to be broken */
/* locator->column = loc->getColumnNumber(xc); */
}
}
| +Info | 0 | raptor_libxml_update_document_locator(raptor_sax2* sax2,
raptor_locator* locator)
{
/* for storing error info */
xmlSAXLocatorPtr loc = sax2 ? sax2->loc : NULL;
xmlParserCtxtPtr xc= sax2 ? sax2->xc : NULL;
if(xc && xc->inSubset)
return;
if(!locator)
return;
locator->line= -1;
locator->column= -1;
if(!xc)
return;
if(loc) {
locator->line = loc->getLineNumber(xc);
/* Seems to be broken */
/* locator->column = loc->getColumnNumber(xc); */
}
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,571 | raptor_libxml_validation_error(void* user_data, const char *msg, ...)
{
va_list args;
va_start(args, msg);
raptor_libxml_error_common(user_data, msg, args,
xml_validation_error_prefix, 1);
va_end(args);
}
| +Info | 0 | raptor_libxml_validation_error(void* user_data, const char *msg, ...)
{
va_list args;
va_start(args, msg);
raptor_libxml_error_common(user_data, msg, args,
xml_validation_error_prefix, 1);
va_end(args);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,572 | raptor_libxml_validation_warning(void* user_data, const char *msg, ...)
{
va_list args;
raptor_sax2* sax2 = (raptor_sax2*)user_data;
int prefix_length = RAPTOR_GOOD_CAST(int, strlen(xml_validation_warning_prefix));
int length;
char *nmsg;
int msg_len;
va_start(args, msg);
raptor_libxml_update_document_locator(sax2, sax2->locator);
msg_len = RAPTOR_BAD_CAST(int, strlen(msg));
length = prefix_length + msg_len + 1;
nmsg = RAPTOR_MALLOC(char*, length);
if(nmsg) {
memcpy(nmsg, xml_validation_warning_prefix, prefix_length); /* Do not copy NUL */
memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */
if(nmsg[length-2] == '\n')
nmsg[length-2]='\0';
}
raptor_log_error_varargs(sax2->world,
RAPTOR_LOG_LEVEL_WARN,
sax2->locator,
nmsg ? nmsg : msg,
args);
if(nmsg)
RAPTOR_FREE(char*, nmsg);
va_end(args);
}
| +Info | 0 | raptor_libxml_validation_warning(void* user_data, const char *msg, ...)
{
va_list args;
raptor_sax2* sax2 = (raptor_sax2*)user_data;
int prefix_length = RAPTOR_GOOD_CAST(int, strlen(xml_validation_warning_prefix));
int length;
char *nmsg;
int msg_len;
va_start(args, msg);
raptor_libxml_update_document_locator(sax2, sax2->locator);
msg_len = RAPTOR_BAD_CAST(int, strlen(msg));
length = prefix_length + msg_len + 1;
nmsg = RAPTOR_MALLOC(char*, length);
if(nmsg) {
memcpy(nmsg, xml_validation_warning_prefix, prefix_length); /* Do not copy NUL */
memcpy(nmsg + prefix_length, msg, msg_len + 1); /* Copy NUL */
if(nmsg[length-2] == '\n')
nmsg[length-2]='\0';
}
raptor_log_error_varargs(sax2->world,
RAPTOR_LOG_LEVEL_WARN,
sax2->locator,
nmsg ? nmsg : msg,
args);
if(nmsg)
RAPTOR_FREE(char*, nmsg);
va_end(args);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,573 | raptor_libxml_xmlStructuredError_handler_common(raptor_world *world,
raptor_locator *locator,
xmlErrorPtr err)
{
raptor_stringbuffer* sb;
char *nmsg;
raptor_log_level level = RAPTOR_LOG_LEVEL_ERROR;
if(err == NULL || err->code == XML_ERR_OK || err->level == XML_ERR_NONE)
return;
/* Do not warn about things with no location */
if(err->level == XML_ERR_WARNING && !err->file)
return;
/* XML fatal errors never cause an abort */
if(err->level == XML_ERR_FATAL)
err->level = XML_ERR_ERROR;
sb = raptor_new_stringbuffer();
if(err->domain != XML_FROM_HTML)
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)"XML ",
4, 1);
if(err->domain != XML_FROM_NONE && err->domain < XML_LAST_DL) {
const unsigned char* label;
label = (const unsigned char*)raptor_libxml_domain_labels[(int)err->domain];
raptor_stringbuffer_append_string(sb, label, 1);
raptor_stringbuffer_append_counted_string(sb,
(const unsigned char*)" ", 1, 1);
}
if(err->level == XML_ERR_WARNING)
raptor_stringbuffer_append_counted_string(sb,
(const unsigned char*)"warning: ",
9, 1);
else /* XML_ERR_ERROR or XML_ERR_FATAL */
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)"error: ",
7, 1);
if(err->message) {
unsigned char* msg;
size_t len;
msg = (unsigned char*)err->message;
len= strlen((const char*)msg);
if(len && msg[len-1] == '\n')
msg[--len]='\0';
raptor_stringbuffer_append_counted_string(sb, msg, len, 1);
}
#if LIBXML_VERSION >= 20618
/* 2005-02-13 - v2.6.18 */
/* str1 has the detailed HTTP error */
if(err->domain == XML_FROM_HTTP && err->str1) {
unsigned char* msg;
size_t len;
msg = (unsigned char*)err->str1;
len= strlen((const char*)msg);
if(len && msg[len-1] == '\n')
msg[--len]='\0';
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)" - ",
3, 1);
raptor_stringbuffer_append_counted_string(sb, msg, len, 1);
}
#endif
/* When err->domain == XML_FROM_XPATH then err->int1 is
* the offset into err->str1, the line with the error
*/
if(err->domain == XML_FROM_XPATH && err->str1) {
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)" in ",
4, 1);
raptor_stringbuffer_append_string(sb, (const unsigned char*)err->str1, 1);
}
nmsg = (char*)raptor_stringbuffer_as_string(sb);
if(err->level == XML_ERR_FATAL)
level = RAPTOR_LOG_LEVEL_FATAL;
else if(err->level == XML_ERR_ERROR)
level = RAPTOR_LOG_LEVEL_ERROR;
else
level = RAPTOR_LOG_LEVEL_WARN;
raptor_log_error(world, level, locator, nmsg);
raptor_free_stringbuffer(sb);
}
| +Info | 0 | raptor_libxml_xmlStructuredError_handler_common(raptor_world *world,
raptor_locator *locator,
xmlErrorPtr err)
{
raptor_stringbuffer* sb;
char *nmsg;
raptor_log_level level = RAPTOR_LOG_LEVEL_ERROR;
if(err == NULL || err->code == XML_ERR_OK || err->level == XML_ERR_NONE)
return;
/* Do not warn about things with no location */
if(err->level == XML_ERR_WARNING && !err->file)
return;
/* XML fatal errors never cause an abort */
if(err->level == XML_ERR_FATAL)
err->level = XML_ERR_ERROR;
sb = raptor_new_stringbuffer();
if(err->domain != XML_FROM_HTML)
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)"XML ",
4, 1);
if(err->domain != XML_FROM_NONE && err->domain < XML_LAST_DL) {
const unsigned char* label;
label = (const unsigned char*)raptor_libxml_domain_labels[(int)err->domain];
raptor_stringbuffer_append_string(sb, label, 1);
raptor_stringbuffer_append_counted_string(sb,
(const unsigned char*)" ", 1, 1);
}
if(err->level == XML_ERR_WARNING)
raptor_stringbuffer_append_counted_string(sb,
(const unsigned char*)"warning: ",
9, 1);
else /* XML_ERR_ERROR or XML_ERR_FATAL */
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)"error: ",
7, 1);
if(err->message) {
unsigned char* msg;
size_t len;
msg = (unsigned char*)err->message;
len= strlen((const char*)msg);
if(len && msg[len-1] == '\n')
msg[--len]='\0';
raptor_stringbuffer_append_counted_string(sb, msg, len, 1);
}
#if LIBXML_VERSION >= 20618
/* 2005-02-13 - v2.6.18 */
/* str1 has the detailed HTTP error */
if(err->domain == XML_FROM_HTTP && err->str1) {
unsigned char* msg;
size_t len;
msg = (unsigned char*)err->str1;
len= strlen((const char*)msg);
if(len && msg[len-1] == '\n')
msg[--len]='\0';
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)" - ",
3, 1);
raptor_stringbuffer_append_counted_string(sb, msg, len, 1);
}
#endif
/* When err->domain == XML_FROM_XPATH then err->int1 is
* the offset into err->str1, the line with the error
*/
if(err->domain == XML_FROM_XPATH && err->str1) {
raptor_stringbuffer_append_counted_string(sb, (const unsigned char*)" in ",
4, 1);
raptor_stringbuffer_append_string(sb, (const unsigned char*)err->str1, 1);
}
nmsg = (char*)raptor_stringbuffer_as_string(sb);
if(err->level == XML_ERR_FATAL)
level = RAPTOR_LOG_LEVEL_FATAL;
else if(err->level == XML_ERR_ERROR)
level = RAPTOR_LOG_LEVEL_ERROR;
else
level = RAPTOR_LOG_LEVEL_WARN;
raptor_log_error(world, level, locator, nmsg);
raptor_free_stringbuffer(sb);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,574 | raptor_libxml_xmlStructuredError_handler_global(void *user_data,
xmlErrorPtr err)
{
raptor_world *world = NULL;
/* user_data may point to a raptor_world* */
if(user_data) {
world = (raptor_world*)user_data;
if(world->magic != RAPTOR2_WORLD_MAGIC)
world = NULL;
}
raptor_libxml_xmlStructuredError_handler_common(world, NULL, err);
}
| +Info | 0 | raptor_libxml_xmlStructuredError_handler_global(void *user_data,
xmlErrorPtr err)
{
raptor_world *world = NULL;
/* user_data may point to a raptor_world* */
if(user_data) {
world = (raptor_world*)user_data;
if(world->magic != RAPTOR2_WORLD_MAGIC)
world = NULL;
}
raptor_libxml_xmlStructuredError_handler_common(world, NULL, err);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,575 | raptor_libxml_xmlStructuredError_handler_parsing(void *user_data,
xmlErrorPtr err)
{
raptor_sax2* sax2 = NULL;
/* user_data may point to a raptor_sax2* */
if(user_data) {
sax2 = (raptor_sax2*)user_data;
if(sax2->magic != RAPTOR_LIBXML_MAGIC)
sax2 = NULL;
}
/* err->ctxt->userData may point to a raptor_sax2* */
if(err && err->ctxt) {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)err->ctxt;
if(ctxt->userData) {
sax2 = (raptor_sax2*)ctxt->userData;
if(sax2->magic != RAPTOR_LIBXML_MAGIC)
sax2 = NULL;
}
}
if(sax2)
raptor_libxml_xmlStructuredError_handler_common(sax2->world, sax2->locator,
err);
else
raptor_libxml_xmlStructuredError_handler_common(NULL, NULL, err);
}
| +Info | 0 | raptor_libxml_xmlStructuredError_handler_parsing(void *user_data,
xmlErrorPtr err)
{
raptor_sax2* sax2 = NULL;
/* user_data may point to a raptor_sax2* */
if(user_data) {
sax2 = (raptor_sax2*)user_data;
if(sax2->magic != RAPTOR_LIBXML_MAGIC)
sax2 = NULL;
}
/* err->ctxt->userData may point to a raptor_sax2* */
if(err && err->ctxt) {
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)err->ctxt;
if(ctxt->userData) {
sax2 = (raptor_sax2*)ctxt->userData;
if(sax2->magic != RAPTOR_LIBXML_MAGIC)
sax2 = NULL;
}
}
if(sax2)
raptor_libxml_xmlStructuredError_handler_common(sax2->world, sax2->locator,
err);
else
raptor_libxml_xmlStructuredError_handler_common(NULL, NULL, err);
}
| @@ -145,16 +145,117 @@ raptor_libxml_hasExternalSubset (void* user_data)
static xmlParserInputPtr
raptor_libxml_resolveEntity(void* user_data,
- const xmlChar *publicId, const xmlChar *systemId) {
+ const xmlChar *publicId, const xmlChar *systemId)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_resolveEntity(sax2->xc, publicId, systemId);
+ xmlParserCtxtPtr ctxt = sax2->xc;
+ const unsigned char *uri_string = NULL;
+ xmlParserInputPtr entity_input;
+ int load_entity = 0;
+
+ if(ctxt->input)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->input->filename);
+
+ if(!uri_string)
+ uri_string = RAPTOR_GOOD_CAST(const unsigned char *, ctxt->directory);
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, uri_string);
+
+ if(load_entity) {
+ entity_input = xmlLoadExternalEntity(RAPTOR_GOOD_CAST(const char*, uri_string),
+ RAPTOR_GOOD_CAST(const char*, publicId),
+ ctxt);
+ } else {
+ RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
+ }
+
+ return entity_input;
}
static xmlEntityPtr
-raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
+raptor_libxml_getEntity(void* user_data, const xmlChar *name)
+{
raptor_sax2* sax2 = (raptor_sax2*)user_data;
- return libxml2_getEntity(sax2->xc, name);
+ xmlParserCtxtPtr xc = sax2->xc;
+ xmlEntityPtr ret = NULL;
+
+ if(!xc)
+ return NULL;
+
+ if(!xc->inSubset) {
+ /* looks for hardcoded set of entity names - lt, gt etc. */
+ ret = xmlGetPredefinedEntity(name);
+ if(ret) {
+ RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
+ return ret;
+ }
+ }
+
+ /* This section uses xmlGetDocEntity which looks for entities in
+ * memory only, never from a file or URI
+ */
+ if(xc->myDoc && (xc->myDoc->standalone == 1)) {
+ RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
+ /* Document is standalone: no entities are required to interpret doc */
+ if(xc->inSubset == 2) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ if(!ret) {
+ xc->myDoc->standalone = 0;
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ xc->myDoc->standalone = 1;
+ }
+ }
+ } else {
+ ret = xmlGetDocEntity(xc->myDoc, name);
+ }
+
+ if(ret && !ret->children &&
+ (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
+ /* Entity is an external general parsed entity. It may be in a
+ * catalog file, user file or user URI
+ */
+ int val = 0;
+ xmlNodePtr children;
+ int load_entity = 0;
+
+ load_entity = RAPTOR_OPTIONS_GET_NUMERIC(sax2, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES);
+ if(load_entity)
+ load_entity = raptor_sax2_check_load_uri_string(sax2, ret->URI);
+
+ if(!load_entity) {
+ RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
+ children = xmlNewText((const xmlChar*)"");
+ } else {
+ /* Disable SAX2 handlers so that the SAX2 events do not all get
+ * sent to callbacks during dealing with the entity parsing.
+ */
+ sax2->enabled = 0;
+ val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
+ sax2->enabled = 1;
+ }
+
+ if(!val) {
+ xmlAddChildList((xmlNodePtr)ret, children);
+ } else {
+ xc->validate = 0;
+ return NULL;
+ }
+
+ ret->owner = 1;
+
+ /* Mark this entity as having been checked - never do this again */
+ if(!ret->checked)
+ ret->checked = 1;
+ }
+
+ return ret;
}
| CWE-200 | null | null |
17,576 | raptor_free_option_description(raptor_option_description* option_description)
{
if(!option_description)
return;
/* these are shared strings pointing to static data in raptor_options_list[] */
/* RAPTOR_FREE(char*, option_description->name); */
/* RAPTOR_FREE(char*, option_description->label); */
if(option_description->uri)
raptor_free_uri(option_description->uri);
RAPTOR_FREE(raptor_option_description, option_description);
}
| +Info | 0 | raptor_free_option_description(raptor_option_description* option_description)
{
if(!option_description)
return;
/* these are shared strings pointing to static data in raptor_options_list[] */
/* RAPTOR_FREE(char*, option_description->name); */
/* RAPTOR_FREE(char*, option_description->label); */
if(option_description->uri)
raptor_free_uri(option_description->uri);
RAPTOR_FREE(raptor_option_description, option_description);
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,577 | raptor_object_options_copy_state(raptor_object_options* to,
raptor_object_options* from)
{
int rc = 0;
int i;
to->area = from->area;
for(i = 0; !rc && i <= RAPTOR_OPTION_LAST; i++) {
if(raptor_option_value_is_numeric((raptor_option)i))
to->options[i].integer = from->options[i].integer;
else {
/* non-numeric values may need allocations */
char* string = from->options[i].string;
if(string) {
size_t len = strlen(string);
to->options[i].string = RAPTOR_MALLOC(char*, len + 1);
if(to->options[i].string)
memcpy(to->options[i].string, string, len + 1);
else
rc = 1;
}
}
}
return rc;
}
| +Info | 0 | raptor_object_options_copy_state(raptor_object_options* to,
raptor_object_options* from)
{
int rc = 0;
int i;
to->area = from->area;
for(i = 0; !rc && i <= RAPTOR_OPTION_LAST; i++) {
if(raptor_option_value_is_numeric((raptor_option)i))
to->options[i].integer = from->options[i].integer;
else {
/* non-numeric values may need allocations */
char* string = from->options[i].string;
if(string) {
size_t len = strlen(string);
to->options[i].string = RAPTOR_MALLOC(char*, len + 1);
if(to->options[i].string)
memcpy(to->options[i].string, string, len + 1);
else
rc = 1;
}
}
}
return rc;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,578 | raptor_object_options_get_option(raptor_object_options* options,
raptor_option option,
char** string_p, int* integer_p)
{
if(!raptor_option_is_valid_for_area(option, options->area))
return 1;
if(raptor_option_value_is_numeric(option)) {
/* numeric options */
int value = options->options[(int)option].integer;
if(integer_p)
*integer_p = value;
} else {
/* non-numeric options */
char* string = options->options[(int)option].string;
if(string_p)
*string_p = string;
}
return 0;
}
| +Info | 0 | raptor_object_options_get_option(raptor_object_options* options,
raptor_option option,
char** string_p, int* integer_p)
{
if(!raptor_option_is_valid_for_area(option, options->area))
return 1;
if(raptor_option_value_is_numeric(option)) {
/* numeric options */
int value = options->options[(int)option].integer;
if(integer_p)
*integer_p = value;
} else {
/* non-numeric options */
char* string = options->options[(int)option].string;
if(string_p)
*string_p = string;
}
return 0;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,579 | raptor_object_options_init(raptor_object_options* options,
raptor_option_area area)
{
int i;
options->area = area;
for(i = 0; i <= RAPTOR_OPTION_LAST; i++) {
if(raptor_option_value_is_numeric((raptor_option)i))
options->options[i].integer = 0;
else
options->options[i].string = NULL;
}
/* Initialise default options that are not 0 or NULL */
/* Emit @base directive or equivalent */
options->options[RAPTOR_OPTION_WRITE_BASE_URI].integer = 1;
/* Emit relative URIs where possible */
options->options[RAPTOR_OPTION_RELATIVE_URIS].integer = 1;
/* XML 1.0 output */
options->options[RAPTOR_OPTION_WRITER_XML_VERSION].integer = 10;
/* Write XML declaration */
options->options[RAPTOR_OPTION_WRITER_XML_DECLARATION].integer = 1;
/* Indent 2 spaces */
options->options[RAPTOR_OPTION_WRITER_INDENT_WIDTH].integer = 2;
/* lax (no strict) parsing */
options->options[RAPTOR_OPTION_STRICT].integer = 0;
/* SSL verify peers */
options->options[RAPTOR_OPTION_WWW_SSL_VERIFY_PEER].integer = 1;
/* SSL fully verify hosts */
options->options[RAPTOR_OPTION_WWW_SSL_VERIFY_HOST].integer = 2;
}
| +Info | 0 | raptor_object_options_init(raptor_object_options* options,
raptor_option_area area)
{
int i;
options->area = area;
for(i = 0; i <= RAPTOR_OPTION_LAST; i++) {
if(raptor_option_value_is_numeric((raptor_option)i))
options->options[i].integer = 0;
else
options->options[i].string = NULL;
}
/* Initialise default options that are not 0 or NULL */
/* Emit @base directive or equivalent */
options->options[RAPTOR_OPTION_WRITE_BASE_URI].integer = 1;
/* Emit relative URIs where possible */
options->options[RAPTOR_OPTION_RELATIVE_URIS].integer = 1;
/* XML 1.0 output */
options->options[RAPTOR_OPTION_WRITER_XML_VERSION].integer = 10;
/* Write XML declaration */
options->options[RAPTOR_OPTION_WRITER_XML_DECLARATION].integer = 1;
/* Indent 2 spaces */
options->options[RAPTOR_OPTION_WRITER_INDENT_WIDTH].integer = 2;
/* lax (no strict) parsing */
options->options[RAPTOR_OPTION_STRICT].integer = 0;
/* SSL verify peers */
options->options[RAPTOR_OPTION_WWW_SSL_VERIFY_PEER].integer = 1;
/* SSL fully verify hosts */
options->options[RAPTOR_OPTION_WWW_SSL_VERIFY_HOST].integer = 2;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,580 | raptor_object_options_set_option(raptor_object_options *options,
raptor_option option,
const char* string, int integer)
{
if(!raptor_option_is_valid_for_area(option, options->area))
return 1;
if(raptor_option_value_is_numeric(option)) {
/* numeric options */
if(string)
integer = atoi((const char*)string);
options->options[(int)option].integer = integer;
return 0;
} else {
/* non-numeric options */
char *string_copy;
size_t len = 0;
if(string)
len = strlen((const char*)string);
string_copy = RAPTOR_MALLOC(char*, len + 1);
if(!string_copy)
return 1;
if(len)
memcpy(string_copy, string, len);
string_copy[len] = '\0';
options->options[(int)option].string = string_copy;
}
return 0;
}
| +Info | 0 | raptor_object_options_set_option(raptor_object_options *options,
raptor_option option,
const char* string, int integer)
{
if(!raptor_option_is_valid_for_area(option, options->area))
return 1;
if(raptor_option_value_is_numeric(option)) {
/* numeric options */
if(string)
integer = atoi((const char*)string);
options->options[(int)option].integer = integer;
return 0;
} else {
/* non-numeric options */
char *string_copy;
size_t len = 0;
if(string)
len = strlen((const char*)string);
string_copy = RAPTOR_MALLOC(char*, len + 1);
if(!string_copy)
return 1;
if(len)
memcpy(string_copy, string, len);
string_copy[len] = '\0';
options->options[(int)option].string = string_copy;
}
return 0;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,581 | raptor_option_get_option_area_for_domain(raptor_domain domain)
{
raptor_option_area area = RAPTOR_OPTION_AREA_NONE;
if(domain == RAPTOR_DOMAIN_PARSER)
area = RAPTOR_OPTION_AREA_PARSER;
else if(domain == RAPTOR_DOMAIN_SERIALIZER)
area = RAPTOR_OPTION_AREA_SERIALIZER;
else if(domain == RAPTOR_DOMAIN_SAX2)
area = RAPTOR_OPTION_AREA_SAX2;
else if(domain == RAPTOR_DOMAIN_XML_WRITER)
area = RAPTOR_OPTION_AREA_XML_WRITER;
else if(domain == RAPTOR_DOMAIN_TURTLE_WRITER)
area = RAPTOR_OPTION_AREA_TURTLE_WRITER;
return area;
}
| +Info | 0 | raptor_option_get_option_area_for_domain(raptor_domain domain)
{
raptor_option_area area = RAPTOR_OPTION_AREA_NONE;
if(domain == RAPTOR_DOMAIN_PARSER)
area = RAPTOR_OPTION_AREA_PARSER;
else if(domain == RAPTOR_DOMAIN_SERIALIZER)
area = RAPTOR_OPTION_AREA_SERIALIZER;
else if(domain == RAPTOR_DOMAIN_SAX2)
area = RAPTOR_OPTION_AREA_SAX2;
else if(domain == RAPTOR_DOMAIN_XML_WRITER)
area = RAPTOR_OPTION_AREA_XML_WRITER;
else if(domain == RAPTOR_DOMAIN_TURTLE_WRITER)
area = RAPTOR_OPTION_AREA_TURTLE_WRITER;
return area;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,582 | raptor_option_get_value_type_label(const raptor_option_value_type type)
{
if(type > RAPTOR_OPTION_VALUE_TYPE_LAST)
return NULL;
return raptor_option_value_type_labels[type];
}
| +Info | 0 | raptor_option_get_value_type_label(const raptor_option_value_type type)
{
if(type > RAPTOR_OPTION_VALUE_TYPE_LAST)
return NULL;
return raptor_option_value_type_labels[type];
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,583 | raptor_option_is_valid_for_area(const raptor_option option,
raptor_option_area area)
{
if(option > RAPTOR_OPTION_LAST)
return 0;
return (raptor_options_list[option].area & area) != 0;
}
| +Info | 0 | raptor_option_is_valid_for_area(const raptor_option option,
raptor_option_area area)
{
if(option > RAPTOR_OPTION_LAST)
return 0;
return (raptor_options_list[option].area & area) != 0;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,584 | raptor_option_value_is_numeric(const raptor_option option)
{
raptor_option_value_type t = raptor_options_list[option].value_type;
return t == RAPTOR_OPTION_VALUE_TYPE_BOOL ||
t == RAPTOR_OPTION_VALUE_TYPE_INT;
}
| +Info | 0 | raptor_option_value_is_numeric(const raptor_option option)
{
raptor_option_value_type t = raptor_options_list[option].value_type;
return t == RAPTOR_OPTION_VALUE_TYPE_BOOL ||
t == RAPTOR_OPTION_VALUE_TYPE_INT;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,585 | raptor_world_get_option_description(raptor_world* world,
const raptor_domain domain,
const raptor_option option)
{
raptor_option_area area;
raptor_option_description *option_description = NULL;
raptor_uri *base_uri = NULL;
int i;
RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, raptor_world, NULL);
raptor_world_open(world);
area = raptor_option_get_option_area_for_domain(domain);
if(area == RAPTOR_OPTION_AREA_NONE)
return NULL;
for(i = 0; i <= RAPTOR_OPTION_LAST; i++) {
if(raptor_options_list[i].option == option &&
(raptor_options_list[i].area & area))
break;
}
if(i > RAPTOR_OPTION_LAST)
return NULL;
option_description = RAPTOR_CALLOC(raptor_option_description*, 1,
sizeof(*option_description));
if(!option_description)
return NULL;
option_description->domain = domain;
option_description->option = option;
option_description->value_type = raptor_options_list[i].value_type;
option_description->name = raptor_options_list[i].name;
option_description->name_len = strlen(option_description->name);
option_description->label = raptor_options_list[i].label;
base_uri = raptor_new_uri_from_counted_string(world,
(const unsigned char*)raptor_option_uri_prefix,
raptor_option_uri_prefix_len);
if(!base_uri) {
raptor_free_option_description(option_description);
return NULL;
}
option_description->uri = raptor_new_uri_from_uri_local_name(world,
base_uri,
(const unsigned char*)raptor_options_list[i].name);
raptor_free_uri(base_uri);
if(!option_description->uri) {
raptor_free_option_description(option_description);
return NULL;
}
return option_description;
}
| +Info | 0 | raptor_world_get_option_description(raptor_world* world,
const raptor_domain domain,
const raptor_option option)
{
raptor_option_area area;
raptor_option_description *option_description = NULL;
raptor_uri *base_uri = NULL;
int i;
RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, raptor_world, NULL);
raptor_world_open(world);
area = raptor_option_get_option_area_for_domain(domain);
if(area == RAPTOR_OPTION_AREA_NONE)
return NULL;
for(i = 0; i <= RAPTOR_OPTION_LAST; i++) {
if(raptor_options_list[i].option == option &&
(raptor_options_list[i].area & area))
break;
}
if(i > RAPTOR_OPTION_LAST)
return NULL;
option_description = RAPTOR_CALLOC(raptor_option_description*, 1,
sizeof(*option_description));
if(!option_description)
return NULL;
option_description->domain = domain;
option_description->option = option;
option_description->value_type = raptor_options_list[i].value_type;
option_description->name = raptor_options_list[i].name;
option_description->name_len = strlen(option_description->name);
option_description->label = raptor_options_list[i].label;
base_uri = raptor_new_uri_from_counted_string(world,
(const unsigned char*)raptor_option_uri_prefix,
raptor_option_uri_prefix_len);
if(!base_uri) {
raptor_free_option_description(option_description);
return NULL;
}
option_description->uri = raptor_new_uri_from_uri_local_name(world,
base_uri,
(const unsigned char*)raptor_options_list[i].name);
raptor_free_uri(base_uri);
if(!option_description->uri) {
raptor_free_option_description(option_description);
return NULL;
}
return option_description;
}
| @@ -295,6 +295,12 @@ static const struct
RAPTOR_OPTION_VALUE_TYPE_INT,
"wwwSslVerifyHost",
"SSL verify host matching"
+ },
+ { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
+ (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
+ RAPTOR_OPTION_VALUE_TYPE_BOOL,
+ "loadExternalEntities",
+ "Parsers and SAX2 should load external entities."
}
};
| CWE-200 | null | null |
17,586 | raptor_free_rdfxml_element(raptor_rdfxml_element *element)
{
int i;
/* Free special RDF M&S attributes */
for(i = 0; i <= RDF_NS_LAST; i++)
if(element->rdf_attr[i])
RAPTOR_FREE(char*, element->rdf_attr[i]);
if(element->subject)
raptor_free_term(element->subject);
if(element->predicate)
raptor_free_term(element->predicate);
if(element->object)
raptor_free_term(element->object);
if(element->bag)
raptor_free_term(element->bag);
if(element->reified)
raptor_free_term(element->reified);
if(element->tail_id)
RAPTOR_FREE(char*, (char*)element->tail_id);
if(element->object_literal_datatype)
raptor_free_uri(element->object_literal_datatype);
if(element->reified_id)
RAPTOR_FREE(char*, (char*)element->reified_id);
RAPTOR_FREE(raptor_rdfxml_element, element);
}
| +Info | 0 | raptor_free_rdfxml_element(raptor_rdfxml_element *element)
{
int i;
/* Free special RDF M&S attributes */
for(i = 0; i <= RDF_NS_LAST; i++)
if(element->rdf_attr[i])
RAPTOR_FREE(char*, element->rdf_attr[i]);
if(element->subject)
raptor_free_term(element->subject);
if(element->predicate)
raptor_free_term(element->predicate);
if(element->object)
raptor_free_term(element->object);
if(element->bag)
raptor_free_term(element->bag);
if(element->reified)
raptor_free_term(element->reified);
if(element->tail_id)
RAPTOR_FREE(char*, (char*)element->tail_id);
if(element->object_literal_datatype)
raptor_free_uri(element->object_literal_datatype);
if(element->reified_id)
RAPTOR_FREE(char*, (char*)element->reified_id);
RAPTOR_FREE(raptor_rdfxml_element, element);
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,587 | raptor_init_parser_rdfxml(raptor_world* world)
{
return !raptor_world_register_parser_factory(world,
&raptor_rdfxml_parser_register_factory);
}
| +Info | 0 | raptor_init_parser_rdfxml(raptor_world* world)
{
return !raptor_world_register_parser_factory(world,
&raptor_rdfxml_parser_register_factory);
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,588 | raptor_rdfxml_cdata_grammar(raptor_parser *rdf_parser,
const unsigned char *s, int len,
int is_cdata)
{
raptor_rdfxml_parser* rdf_xml_parser;
raptor_rdfxml_element* element;
raptor_xml_element* xml_element;
raptor_state state;
int all_whitespace = 1;
int i;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(rdf_parser->failed)
return;
#ifdef RAPTOR_DEBUG_CDATA
RAPTOR_DEBUG2("Adding characters (is_cdata=%d): '", is_cdata);
(void)fwrite(s, 1, len, stderr);
fprintf(stderr, "' (%d bytes)\n", len);
#endif
for(i = 0; i < len; i++)
if(!isspace(s[i])) {
all_whitespace = 0;
break;
}
element = rdf_xml_parser->current_element;
/* this file is very broke - probably not XML, whatever */
if(!element)
return;
xml_element = element->xml_element;
raptor_rdfxml_update_document_locator(rdf_parser);
/* cdata never changes the parser state
* and the containing element state always determines what to do.
* Use the child_state first if there is one, since that applies
*/
state = element->child_state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Working in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Content type %s (%d)\n",
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
#endif
if(state == RAPTOR_STATE_SKIPPING)
return;
if(state == RAPTOR_STATE_UNKNOWN) {
/* Ignore all cdata if still looking for RDF */
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_SCANNING))
return;
/* Ignore all whitespace cdata before first element */
if(all_whitespace)
return;
/* This probably will never happen since that would make the
* XML not be well-formed
*/
raptor_parser_warning(rdf_parser, "Character data before RDF element.");
}
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES) {
/* If found non-whitespace content, move to literal content */
if(!all_whitespace)
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
}
if(!rdf_content_type_info[element->child_content_type].whitespace_significant) {
/* Whitespace is ignored except for literal or preserved content types */
if(all_whitespace) {
#ifdef RAPTOR_DEBUG_CDATA
RAPTOR_DEBUG2("Ignoring whitespace cdata inside element '%s'\n",
raptor_xml_element_get_name(element->parent->xml_element)->local_name);
#endif
return;
}
if(xml_element->content_cdata_seen && xml_element->content_element_seen) {
raptor_qname* parent_el_name;
parent_el_name = raptor_xml_element_get_name(element->parent->xml_element);
/* Uh oh - mixed content, this element has elements too */
raptor_parser_warning(rdf_parser, "element '%s' has mixed content.",
parent_el_name->local_name);
}
}
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT) {
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Content type changed to %s (%d)\n",
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
#endif
}
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL)
raptor_xml_writer_cdata_counted(rdf_xml_parser->xml_writer, s, len);
else {
raptor_stringbuffer_append_counted_string(xml_element->content_cdata_sb,
s, len, 1);
element->content_cdata_all_whitespace &= all_whitespace;
/* adjust stored length */
xml_element->content_cdata_length += len;
}
#ifdef RAPTOR_DEBUG_CDATA
RAPTOR_DEBUG3("Content cdata now: %d bytes\n",
xml_element->content_cdata_length);
#endif
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Ending in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
}
| +Info | 0 | raptor_rdfxml_cdata_grammar(raptor_parser *rdf_parser,
const unsigned char *s, int len,
int is_cdata)
{
raptor_rdfxml_parser* rdf_xml_parser;
raptor_rdfxml_element* element;
raptor_xml_element* xml_element;
raptor_state state;
int all_whitespace = 1;
int i;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(rdf_parser->failed)
return;
#ifdef RAPTOR_DEBUG_CDATA
RAPTOR_DEBUG2("Adding characters (is_cdata=%d): '", is_cdata);
(void)fwrite(s, 1, len, stderr);
fprintf(stderr, "' (%d bytes)\n", len);
#endif
for(i = 0; i < len; i++)
if(!isspace(s[i])) {
all_whitespace = 0;
break;
}
element = rdf_xml_parser->current_element;
/* this file is very broke - probably not XML, whatever */
if(!element)
return;
xml_element = element->xml_element;
raptor_rdfxml_update_document_locator(rdf_parser);
/* cdata never changes the parser state
* and the containing element state always determines what to do.
* Use the child_state first if there is one, since that applies
*/
state = element->child_state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Working in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Content type %s (%d)\n",
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
#endif
if(state == RAPTOR_STATE_SKIPPING)
return;
if(state == RAPTOR_STATE_UNKNOWN) {
/* Ignore all cdata if still looking for RDF */
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_SCANNING))
return;
/* Ignore all whitespace cdata before first element */
if(all_whitespace)
return;
/* This probably will never happen since that would make the
* XML not be well-formed
*/
raptor_parser_warning(rdf_parser, "Character data before RDF element.");
}
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES) {
/* If found non-whitespace content, move to literal content */
if(!all_whitespace)
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
}
if(!rdf_content_type_info[element->child_content_type].whitespace_significant) {
/* Whitespace is ignored except for literal or preserved content types */
if(all_whitespace) {
#ifdef RAPTOR_DEBUG_CDATA
RAPTOR_DEBUG2("Ignoring whitespace cdata inside element '%s'\n",
raptor_xml_element_get_name(element->parent->xml_element)->local_name);
#endif
return;
}
if(xml_element->content_cdata_seen && xml_element->content_element_seen) {
raptor_qname* parent_el_name;
parent_el_name = raptor_xml_element_get_name(element->parent->xml_element);
/* Uh oh - mixed content, this element has elements too */
raptor_parser_warning(rdf_parser, "element '%s' has mixed content.",
parent_el_name->local_name);
}
}
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT) {
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Content type changed to %s (%d)\n",
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
#endif
}
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL)
raptor_xml_writer_cdata_counted(rdf_xml_parser->xml_writer, s, len);
else {
raptor_stringbuffer_append_counted_string(xml_element->content_cdata_sb,
s, len, 1);
element->content_cdata_all_whitespace &= all_whitespace;
/* adjust stored length */
xml_element->content_cdata_length += len;
}
#ifdef RAPTOR_DEBUG_CDATA
RAPTOR_DEBUG3("Content cdata now: %d bytes\n",
xml_element->content_cdata_length);
#endif
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Ending in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,589 | raptor_rdfxml_cdata_handler(void *user_data, raptor_xml_element* xml_element,
const unsigned char *s, int len)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rdfxml_cdata_grammar(rdf_parser, s, len, 1);
}
| +Info | 0 | raptor_rdfxml_cdata_handler(void *user_data, raptor_xml_element* xml_element,
const unsigned char *s, int len)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rdfxml_cdata_grammar(rdf_parser, s, len, 1);
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,590 | raptor_rdfxml_characters_handler(void *user_data,
raptor_xml_element* xml_element,
const unsigned char *s, int len)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rdfxml_cdata_grammar(rdf_parser, s, len, 0);
}
| +Info | 0 | raptor_rdfxml_characters_handler(void *user_data,
raptor_xml_element* xml_element,
const unsigned char *s, int len)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rdfxml_cdata_grammar(rdf_parser, s, len, 0);
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,591 | raptor_rdfxml_check_nodeElement_name(const char *name)
{
int i;
if(*name == '_')
return 1;
for(i = 0; raptor_rdf_ns_terms_info[i].name; i++)
if(!strcmp(raptor_rdf_ns_terms_info[i].name, name))
return raptor_rdf_ns_terms_info[i].allowed_as_nodeElement;
return -1;
}
| +Info | 0 | raptor_rdfxml_check_nodeElement_name(const char *name)
{
int i;
if(*name == '_')
return 1;
for(i = 0; raptor_rdf_ns_terms_info[i].name; i++)
if(!strcmp(raptor_rdf_ns_terms_info[i].name, name))
return raptor_rdf_ns_terms_info[i].allowed_as_nodeElement;
return -1;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,592 | raptor_rdfxml_check_propertyAttribute_name(const char *name)
{
int i;
if(*name == '_')
return 1;
for(i = 0; raptor_rdf_ns_terms_info[i].name; i++)
if(!strcmp(raptor_rdf_ns_terms_info[i].name, (const char*)name))
return raptor_rdf_ns_terms_info[i].allowed_as_propertyAttribute;
return -1;
}
| +Info | 0 | raptor_rdfxml_check_propertyAttribute_name(const char *name)
{
int i;
if(*name == '_')
return 1;
for(i = 0; raptor_rdf_ns_terms_info[i].name; i++)
if(!strcmp(raptor_rdf_ns_terms_info[i].name, (const char*)name))
return raptor_rdf_ns_terms_info[i].allowed_as_propertyAttribute;
return -1;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,593 | raptor_rdfxml_comment_handler(void *user_data, raptor_xml_element* xml_element,
const unsigned char *s)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rdfxml_parser* rdf_xml_parser;
raptor_rdfxml_element* element;
if(rdf_parser->failed || !xml_element)
return;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
element = rdf_xml_parser->current_element;
if(element) {
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL)
raptor_xml_writer_comment(rdf_xml_parser->xml_writer, s);
}
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("XML Comment '%s'\n", s);
#endif
}
| +Info | 0 | raptor_rdfxml_comment_handler(void *user_data, raptor_xml_element* xml_element,
const unsigned char *s)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rdfxml_parser* rdf_xml_parser;
raptor_rdfxml_element* element;
if(rdf_parser->failed || !xml_element)
return;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
element = rdf_xml_parser->current_element;
if(element) {
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL)
raptor_xml_writer_comment(rdf_xml_parser->xml_writer, s);
}
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("XML Comment '%s'\n", s);
#endif
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,594 | raptor_rdfxml_element_content_type_as_string(raptor_rdfxml_element_content_type type)
{
if(type > RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LAST)
return "INVALID";
return rdf_content_type_info[type].name;
}
| +Info | 0 | raptor_rdfxml_element_content_type_as_string(raptor_rdfxml_element_content_type type)
{
if(type > RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LAST)
return "INVALID";
return rdf_content_type_info[type].name;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,595 | raptor_rdfxml_element_pop(raptor_rdfxml_parser *rdf_xml_parser)
{
raptor_rdfxml_element *element = rdf_xml_parser->current_element;
if(!element)
return NULL;
rdf_xml_parser->current_element = element->parent;
if(rdf_xml_parser->root_element == element) /* just deleted root */
rdf_xml_parser->root_element = NULL;
return element;
}
| +Info | 0 | raptor_rdfxml_element_pop(raptor_rdfxml_parser *rdf_xml_parser)
{
raptor_rdfxml_element *element = rdf_xml_parser->current_element;
if(!element)
return NULL;
rdf_xml_parser->current_element = element->parent;
if(rdf_xml_parser->root_element == element) /* just deleted root */
rdf_xml_parser->root_element = NULL;
return element;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,596 | raptor_rdfxml_end_element_grammar(raptor_parser *rdf_parser,
raptor_rdfxml_element *element)
{
raptor_rdfxml_parser *rdf_xml_parser;
raptor_state state;
int finished;
raptor_xml_element* xml_element = element->xml_element;
raptor_qname* el_qname;
const unsigned char *el_name;
int element_in_rdf_ns;
raptor_uri* element_name_uri;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
el_qname = raptor_xml_element_get_name(xml_element);
el_name = el_qname->local_name;
element_in_rdf_ns= (el_qname->nspace && el_qname->nspace->is_rdf_ms);
element_name_uri = el_qname->uri;
state = element->state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Starting in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
finished= 0;
while(!finished) {
switch(state) {
case RAPTOR_STATE_SKIPPING:
finished = 1;
break;
case RAPTOR_STATE_UNKNOWN:
finished = 1;
break;
case RAPTOR_STATE_NODE_ELEMENT_LIST:
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_RDF_URI(rdf_parser->world))) {
/* end of RDF - boo hoo */
state = RAPTOR_STATE_UNKNOWN;
finished = 1;
break;
}
/* When scanning, another element ending is outside the RDF
* world so this can happen without further work
*/
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_SCANNING)) {
state = RAPTOR_STATE_UNKNOWN;
finished = 1;
break;
}
/* otherwise found some junk after RDF content in an RDF-only
* document (probably never get here since this would be
* a mismatched XML tag and cause an error earlier)
*/
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_warning(rdf_parser,
"Element '%s' ended, expected end of RDF element",
el_name);
state = RAPTOR_STATE_UNKNOWN;
finished = 1;
break;
case RAPTOR_STATE_DESCRIPTION:
case RAPTOR_STATE_NODE_ELEMENT:
case RAPTOR_STATE_PARSETYPE_RESOURCE:
/* If there is a parent element containing this element and
* the parent isn't a description, has an identifier,
* create the statement between this node using parent property
* (Need to check for identifier so that top-level typed nodes
* don't get connect to <rdf:RDF> parent element)
*/
if(state == RAPTOR_STATE_NODE_ELEMENT &&
element->parent && element->parent->subject) {
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
element_name_uri,
element->subject,
NULL,
element);
} else if(state == RAPTOR_STATE_PARSETYPE_RESOURCE &&
element->parent && element->parent->subject) {
/* Handle rdf:li as the rdf:parseType="resource" property */
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_li_URI(rdf_parser->world))) {
raptor_uri* ordinal_predicate_uri;
element->parent->last_ordinal++;
ordinal_predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world, element->parent->last_ordinal);
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
ordinal_predicate_uri,
element->subject,
element->reified,
element->parent);
raptor_free_uri(ordinal_predicate_uri);
} else {
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
element_name_uri,
element->subject,
element->reified,
element->parent);
}
}
finished = 1;
break;
case RAPTOR_STATE_PARSETYPE_COLLECTION:
finished = 1;
break;
case RAPTOR_STATE_PARSETYPE_OTHER:
/* FALLTHROUGH */
case RAPTOR_STATE_PARSETYPE_LITERAL:
element->parent->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
raptor_xml_writer_end_element(rdf_xml_parser->xml_writer, xml_element);
finished = 1;
break;
case RAPTOR_STATE_PROPERTYELT:
case RAPTOR_STATE_MEMBER_PROPERTYELT:
/* A property element
* http://www.w3.org/TR/rdf-syntax-grammar/#propertyElt
*
* Literal content part is handled here.
* The element content is handled in the internal states
* Empty content is checked here.
*/
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT) {
if(xml_element->content_cdata_seen)
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
else if(xml_element->content_element_seen)
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
else {
/* Empty Literal */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
}
}
/* Handle terminating a rdf:parseType="Collection" list */
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION ||
element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
raptor_term* nil_term;
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
raptor_uri* nil_uri = RAPTOR_DAML_nil_URI(rdf_xml_parser);
nil_term = raptor_new_term_from_uri(rdf_parser->world, nil_uri);
} else {
nil_term = raptor_term_copy(RAPTOR_RDF_nil_term(rdf_parser->world));
}
if(!element->tail_id) {
/* If No List: set object of statement to rdf:nil */
element->object = raptor_term_copy(nil_term);
} else {
raptor_uri* rest_uri = NULL;
raptor_term* tail_id_term;
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION)
rest_uri = RAPTOR_DAML_rest_URI(rdf_xml_parser);
else
rest_uri = RAPTOR_RDF_rest_URI(rdf_parser->world);
tail_id_term = raptor_new_term_from_blank(rdf_parser->world,
element->tail_id);
/* terminate the list */
raptor_rdfxml_generate_statement(rdf_parser,
tail_id_term,
rest_uri,
nil_term,
NULL,
NULL);
raptor_free_term(tail_id_term);
}
raptor_free_term(nil_term);
} /* end rdf:parseType="Collection" termination */
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Content type %s (%d)\n",
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
#endif
switch(element->content_type) {
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE:
if(raptor_rdfxml_element_has_property_attributes(element) &&
element->child_state == RAPTOR_STATE_DESCRIPTION) {
raptor_parser_error(rdf_parser,
"Property element '%s' has both property attributes and a node element content",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
if(!element->object) {
if(element->rdf_attr[RDF_NS_resource]) {
raptor_uri* resource_uri;
resource_uri = raptor_new_uri_relative_to_base(rdf_parser->world,
raptor_rdfxml_inscope_base_uri(rdf_parser),
(const unsigned char*)element->rdf_attr[RDF_NS_resource]);
if(!resource_uri)
goto oom;
element->object = raptor_new_term_from_uri(rdf_parser->world,
resource_uri);
raptor_free_uri(resource_uri);
RAPTOR_FREE(char*, element->rdf_attr[RDF_NS_resource]);
element->rdf_attr[RDF_NS_resource] = NULL;
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
} else if(element->rdf_attr[RDF_NS_nodeID]) {
unsigned char* resource_id;
resource_id = raptor_world_internal_generate_id(rdf_parser->world,
(unsigned char*)element->rdf_attr[RDF_NS_nodeID]);
if(!resource_id)
goto oom;
element->object = raptor_new_term_from_blank(rdf_parser->world,
resource_id);
RAPTOR_FREE(char*, resource_id);
element->rdf_attr[RDF_NS_nodeID] = NULL;
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
if(!raptor_valid_xml_ID(rdf_parser,
element->object->value.blank.string)) {
raptor_parser_error(rdf_parser, "Illegal rdf:nodeID value '%s'", (const char*)element->object->value.blank.string);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
} else {
unsigned char* resource_id;
resource_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!resource_id)
goto oom;
element->object = raptor_new_term_from_blank(rdf_parser->world,
resource_id);
RAPTOR_FREE(char*, resource_id);
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
}
if(raptor_rdfxml_process_property_attributes(rdf_parser, element,
element->parent,
element->object))
goto oom;
}
/* We know object is a resource, so delete any unsignficant
* whitespace so that FALLTHROUGH code below finds the object.
*/
if(xml_element->content_cdata_length) {
raptor_free_stringbuffer(xml_element->content_cdata_sb);
xml_element->content_cdata_sb = NULL;
xml_element->content_cdata_length = 0;
}
/* FALLTHROUGH */
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL:
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL) {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID)) {
/* Only an empty literal can have a rdf:bagID */
if(element->bag) {
if(xml_element->content_cdata_length > 0) {
raptor_parser_error(rdf_parser,
"rdf:bagID is forbidden on a literal property element '%s'.",
el_name);
/* prevent this being used later either */
element->rdf_attr[RDF_NS_bagID] = NULL;
} else {
raptor_rdfxml_generate_statement(rdf_parser,
element->bag,
RAPTOR_RDF_type_URI(rdf_parser->world),
RAPTOR_RDF_Bag_term(rdf_parser->world),
NULL,
NULL);
}
}
} /* if rdf:bagID */
/* If there is empty literal content with properties
* generate a node to hang properties off
*/
if(raptor_rdfxml_element_has_property_attributes(element) &&
xml_element->content_cdata_length > 0) {
raptor_parser_error(rdf_parser,
"Literal property element '%s' has property attributes",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL &&
raptor_rdfxml_element_has_property_attributes(element) &&
!element->object) {
unsigned char* object_id;
object_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!object_id)
goto oom;
element->object = raptor_new_term_from_blank(rdf_parser->world,
object_id);
RAPTOR_FREE(char*, object_id);
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
}
if(raptor_rdfxml_process_property_attributes(rdf_parser, element,
element,
element->object))
goto oom;
}
/* just be friendly to older compilers and don't declare
* variables in the middle of a block
*/
if(1) {
raptor_uri *predicate_uri = NULL;
int predicate_ordinal = -1;
raptor_term* object_term = NULL;
if(state == RAPTOR_STATE_MEMBER_PROPERTYELT) {
predicate_ordinal = ++element->parent->last_ordinal;
predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world,
predicate_ordinal);
} else {
predicate_uri = element_name_uri;
}
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL) {
unsigned char* literal = NULL;
raptor_uri* literal_datatype;
unsigned char* literal_language = NULL;
/* an empty stringbuffer - empty CDATA - is OK */
if(raptor_stringbuffer_length(xml_element->content_cdata_sb)) {
literal = raptor_stringbuffer_as_string(xml_element->content_cdata_sb);
if(!literal)
goto oom;
}
literal_datatype = element->object_literal_datatype;
if(!literal_datatype)
literal_language = (unsigned char*)raptor_sax2_inscope_xml_language(rdf_xml_parser->sax2);
if(!literal_datatype && literal &&
!raptor_unicode_check_utf8_nfc_string(literal,
xml_element->content_cdata_length,
NULL)) {
const char *message;
message = "Property element '%s' has a string not in Unicode Normal Form C: %s";
raptor_rdfxml_update_document_locator(rdf_parser);
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NON_NFC_FATAL))
raptor_parser_error(rdf_parser, message, el_name, literal);
else
raptor_parser_warning(rdf_parser, message, el_name, literal);
}
object_term = raptor_new_term_from_literal(rdf_parser->world,
literal,
literal_datatype,
literal_language);
} else {
object_term = raptor_term_copy(element->object);
}
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
predicate_uri,
object_term,
element->reified,
element->parent);
if(predicate_ordinal >= 0)
raptor_free_uri(predicate_uri);
raptor_free_term(object_term);
}
break;
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PRESERVED:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL:
{
unsigned char *buffer;
size_t length;
raptor_term* xmlliteral_term = NULL;
if(rdf_xml_parser->xml_writer) {
raptor_xml_writer_flush(rdf_xml_parser->xml_writer);
raptor_free_iostream(rdf_xml_parser->iostream);
rdf_xml_parser->iostream = NULL;
buffer = (unsigned char*)rdf_xml_parser->xml_content;
length = rdf_xml_parser->xml_content_length;
} else {
buffer = raptor_stringbuffer_as_string(xml_element->content_cdata_sb);
length = xml_element->content_cdata_length;
}
if(!raptor_unicode_check_utf8_nfc_string(buffer, length, NULL)) {
const char *message;
message = "Property element '%s' has XML literal content not in Unicode Normal Form C: %s";
raptor_rdfxml_update_document_locator(rdf_parser);
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NON_NFC_FATAL))
raptor_parser_error(rdf_parser, message, el_name, buffer);
else
raptor_parser_warning(rdf_parser, message, el_name, buffer);
}
xmlliteral_term = raptor_new_term_from_literal(rdf_parser->world,
buffer,
RAPTOR_RDF_XMLLiteral_URI(rdf_parser->world),
NULL);
if(state == RAPTOR_STATE_MEMBER_PROPERTYELT) {
raptor_uri* predicate_uri;
element->parent->last_ordinal++;
predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world, element->parent->last_ordinal);
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
predicate_uri,
xmlliteral_term,
element->reified,
element->parent);
raptor_free_uri(predicate_uri);
} else {
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
element_name_uri,
xmlliteral_term,
element->reified,
element->parent);
}
raptor_free_term(xmlliteral_term);
/* Finish the xml writer iostream for parseType="Literal" */
if(rdf_xml_parser->xml_writer) {
raptor_free_xml_writer(rdf_xml_parser->xml_writer);
RAPTOR_FREE(char*, rdf_xml_parser->xml_content);
rdf_xml_parser->xml_content = NULL;
rdf_xml_parser->xml_content_length = 0;
}
}
break;
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_NODES:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_UNKNOWN:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LAST:
default:
raptor_parser_fatal_error(rdf_parser,
"%s: Internal error in state RAPTOR_STATE_PROPERTYELT - got unexpected content type %s (%d)",
__func__,
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
} /* end switch */
finished = 1;
break;
case RAPTOR_STATE_INVALID:
default:
raptor_parser_fatal_error(rdf_parser,
"%s: Internal error - unexpected parser state %d - %s",
__func__,
state,
raptor_rdfxml_state_as_string(state));
finished = 1;
} /* end switch */
if(state != element->state) {
element->state = state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Moved to state %d - %s\n", state,
raptor_rdfxml_state_as_string(state));
#endif
}
} /* end while */
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Ending in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
return;
oom:
raptor_parser_fatal_error(rdf_parser, "Out of memory, skipping");
element->state = RAPTOR_STATE_SKIPPING;
}
| +Info | 0 | raptor_rdfxml_end_element_grammar(raptor_parser *rdf_parser,
raptor_rdfxml_element *element)
{
raptor_rdfxml_parser *rdf_xml_parser;
raptor_state state;
int finished;
raptor_xml_element* xml_element = element->xml_element;
raptor_qname* el_qname;
const unsigned char *el_name;
int element_in_rdf_ns;
raptor_uri* element_name_uri;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
el_qname = raptor_xml_element_get_name(xml_element);
el_name = el_qname->local_name;
element_in_rdf_ns= (el_qname->nspace && el_qname->nspace->is_rdf_ms);
element_name_uri = el_qname->uri;
state = element->state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Starting in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
finished= 0;
while(!finished) {
switch(state) {
case RAPTOR_STATE_SKIPPING:
finished = 1;
break;
case RAPTOR_STATE_UNKNOWN:
finished = 1;
break;
case RAPTOR_STATE_NODE_ELEMENT_LIST:
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_RDF_URI(rdf_parser->world))) {
/* end of RDF - boo hoo */
state = RAPTOR_STATE_UNKNOWN;
finished = 1;
break;
}
/* When scanning, another element ending is outside the RDF
* world so this can happen without further work
*/
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_SCANNING)) {
state = RAPTOR_STATE_UNKNOWN;
finished = 1;
break;
}
/* otherwise found some junk after RDF content in an RDF-only
* document (probably never get here since this would be
* a mismatched XML tag and cause an error earlier)
*/
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_warning(rdf_parser,
"Element '%s' ended, expected end of RDF element",
el_name);
state = RAPTOR_STATE_UNKNOWN;
finished = 1;
break;
case RAPTOR_STATE_DESCRIPTION:
case RAPTOR_STATE_NODE_ELEMENT:
case RAPTOR_STATE_PARSETYPE_RESOURCE:
/* If there is a parent element containing this element and
* the parent isn't a description, has an identifier,
* create the statement between this node using parent property
* (Need to check for identifier so that top-level typed nodes
* don't get connect to <rdf:RDF> parent element)
*/
if(state == RAPTOR_STATE_NODE_ELEMENT &&
element->parent && element->parent->subject) {
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
element_name_uri,
element->subject,
NULL,
element);
} else if(state == RAPTOR_STATE_PARSETYPE_RESOURCE &&
element->parent && element->parent->subject) {
/* Handle rdf:li as the rdf:parseType="resource" property */
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_li_URI(rdf_parser->world))) {
raptor_uri* ordinal_predicate_uri;
element->parent->last_ordinal++;
ordinal_predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world, element->parent->last_ordinal);
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
ordinal_predicate_uri,
element->subject,
element->reified,
element->parent);
raptor_free_uri(ordinal_predicate_uri);
} else {
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
element_name_uri,
element->subject,
element->reified,
element->parent);
}
}
finished = 1;
break;
case RAPTOR_STATE_PARSETYPE_COLLECTION:
finished = 1;
break;
case RAPTOR_STATE_PARSETYPE_OTHER:
/* FALLTHROUGH */
case RAPTOR_STATE_PARSETYPE_LITERAL:
element->parent->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
raptor_xml_writer_end_element(rdf_xml_parser->xml_writer, xml_element);
finished = 1;
break;
case RAPTOR_STATE_PROPERTYELT:
case RAPTOR_STATE_MEMBER_PROPERTYELT:
/* A property element
* http://www.w3.org/TR/rdf-syntax-grammar/#propertyElt
*
* Literal content part is handled here.
* The element content is handled in the internal states
* Empty content is checked here.
*/
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT) {
if(xml_element->content_cdata_seen)
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
else if(xml_element->content_element_seen)
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
else {
/* Empty Literal */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL;
}
}
/* Handle terminating a rdf:parseType="Collection" list */
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION ||
element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
raptor_term* nil_term;
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
raptor_uri* nil_uri = RAPTOR_DAML_nil_URI(rdf_xml_parser);
nil_term = raptor_new_term_from_uri(rdf_parser->world, nil_uri);
} else {
nil_term = raptor_term_copy(RAPTOR_RDF_nil_term(rdf_parser->world));
}
if(!element->tail_id) {
/* If No List: set object of statement to rdf:nil */
element->object = raptor_term_copy(nil_term);
} else {
raptor_uri* rest_uri = NULL;
raptor_term* tail_id_term;
if(element->child_content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION)
rest_uri = RAPTOR_DAML_rest_URI(rdf_xml_parser);
else
rest_uri = RAPTOR_RDF_rest_URI(rdf_parser->world);
tail_id_term = raptor_new_term_from_blank(rdf_parser->world,
element->tail_id);
/* terminate the list */
raptor_rdfxml_generate_statement(rdf_parser,
tail_id_term,
rest_uri,
nil_term,
NULL,
NULL);
raptor_free_term(tail_id_term);
}
raptor_free_term(nil_term);
} /* end rdf:parseType="Collection" termination */
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Content type %s (%d)\n",
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
#endif
switch(element->content_type) {
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE:
if(raptor_rdfxml_element_has_property_attributes(element) &&
element->child_state == RAPTOR_STATE_DESCRIPTION) {
raptor_parser_error(rdf_parser,
"Property element '%s' has both property attributes and a node element content",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
if(!element->object) {
if(element->rdf_attr[RDF_NS_resource]) {
raptor_uri* resource_uri;
resource_uri = raptor_new_uri_relative_to_base(rdf_parser->world,
raptor_rdfxml_inscope_base_uri(rdf_parser),
(const unsigned char*)element->rdf_attr[RDF_NS_resource]);
if(!resource_uri)
goto oom;
element->object = raptor_new_term_from_uri(rdf_parser->world,
resource_uri);
raptor_free_uri(resource_uri);
RAPTOR_FREE(char*, element->rdf_attr[RDF_NS_resource]);
element->rdf_attr[RDF_NS_resource] = NULL;
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
} else if(element->rdf_attr[RDF_NS_nodeID]) {
unsigned char* resource_id;
resource_id = raptor_world_internal_generate_id(rdf_parser->world,
(unsigned char*)element->rdf_attr[RDF_NS_nodeID]);
if(!resource_id)
goto oom;
element->object = raptor_new_term_from_blank(rdf_parser->world,
resource_id);
RAPTOR_FREE(char*, resource_id);
element->rdf_attr[RDF_NS_nodeID] = NULL;
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
if(!raptor_valid_xml_ID(rdf_parser,
element->object->value.blank.string)) {
raptor_parser_error(rdf_parser, "Illegal rdf:nodeID value '%s'", (const char*)element->object->value.blank.string);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
} else {
unsigned char* resource_id;
resource_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!resource_id)
goto oom;
element->object = raptor_new_term_from_blank(rdf_parser->world,
resource_id);
RAPTOR_FREE(char*, resource_id);
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
}
if(raptor_rdfxml_process_property_attributes(rdf_parser, element,
element->parent,
element->object))
goto oom;
}
/* We know object is a resource, so delete any unsignficant
* whitespace so that FALLTHROUGH code below finds the object.
*/
if(xml_element->content_cdata_length) {
raptor_free_stringbuffer(xml_element->content_cdata_sb);
xml_element->content_cdata_sb = NULL;
xml_element->content_cdata_length = 0;
}
/* FALLTHROUGH */
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL:
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL) {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID)) {
/* Only an empty literal can have a rdf:bagID */
if(element->bag) {
if(xml_element->content_cdata_length > 0) {
raptor_parser_error(rdf_parser,
"rdf:bagID is forbidden on a literal property element '%s'.",
el_name);
/* prevent this being used later either */
element->rdf_attr[RDF_NS_bagID] = NULL;
} else {
raptor_rdfxml_generate_statement(rdf_parser,
element->bag,
RAPTOR_RDF_type_URI(rdf_parser->world),
RAPTOR_RDF_Bag_term(rdf_parser->world),
NULL,
NULL);
}
}
} /* if rdf:bagID */
/* If there is empty literal content with properties
* generate a node to hang properties off
*/
if(raptor_rdfxml_element_has_property_attributes(element) &&
xml_element->content_cdata_length > 0) {
raptor_parser_error(rdf_parser,
"Literal property element '%s' has property attributes",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL &&
raptor_rdfxml_element_has_property_attributes(element) &&
!element->object) {
unsigned char* object_id;
object_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!object_id)
goto oom;
element->object = raptor_new_term_from_blank(rdf_parser->world,
object_id);
RAPTOR_FREE(char*, object_id);
if(!element->object)
goto oom;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
}
if(raptor_rdfxml_process_property_attributes(rdf_parser, element,
element,
element->object))
goto oom;
}
/* just be friendly to older compilers and don't declare
* variables in the middle of a block
*/
if(1) {
raptor_uri *predicate_uri = NULL;
int predicate_ordinal = -1;
raptor_term* object_term = NULL;
if(state == RAPTOR_STATE_MEMBER_PROPERTYELT) {
predicate_ordinal = ++element->parent->last_ordinal;
predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world,
predicate_ordinal);
} else {
predicate_uri = element_name_uri;
}
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LITERAL) {
unsigned char* literal = NULL;
raptor_uri* literal_datatype;
unsigned char* literal_language = NULL;
/* an empty stringbuffer - empty CDATA - is OK */
if(raptor_stringbuffer_length(xml_element->content_cdata_sb)) {
literal = raptor_stringbuffer_as_string(xml_element->content_cdata_sb);
if(!literal)
goto oom;
}
literal_datatype = element->object_literal_datatype;
if(!literal_datatype)
literal_language = (unsigned char*)raptor_sax2_inscope_xml_language(rdf_xml_parser->sax2);
if(!literal_datatype && literal &&
!raptor_unicode_check_utf8_nfc_string(literal,
xml_element->content_cdata_length,
NULL)) {
const char *message;
message = "Property element '%s' has a string not in Unicode Normal Form C: %s";
raptor_rdfxml_update_document_locator(rdf_parser);
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NON_NFC_FATAL))
raptor_parser_error(rdf_parser, message, el_name, literal);
else
raptor_parser_warning(rdf_parser, message, el_name, literal);
}
object_term = raptor_new_term_from_literal(rdf_parser->world,
literal,
literal_datatype,
literal_language);
} else {
object_term = raptor_term_copy(element->object);
}
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
predicate_uri,
object_term,
element->reified,
element->parent);
if(predicate_ordinal >= 0)
raptor_free_uri(predicate_uri);
raptor_free_term(object_term);
}
break;
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PRESERVED:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL:
{
unsigned char *buffer;
size_t length;
raptor_term* xmlliteral_term = NULL;
if(rdf_xml_parser->xml_writer) {
raptor_xml_writer_flush(rdf_xml_parser->xml_writer);
raptor_free_iostream(rdf_xml_parser->iostream);
rdf_xml_parser->iostream = NULL;
buffer = (unsigned char*)rdf_xml_parser->xml_content;
length = rdf_xml_parser->xml_content_length;
} else {
buffer = raptor_stringbuffer_as_string(xml_element->content_cdata_sb);
length = xml_element->content_cdata_length;
}
if(!raptor_unicode_check_utf8_nfc_string(buffer, length, NULL)) {
const char *message;
message = "Property element '%s' has XML literal content not in Unicode Normal Form C: %s";
raptor_rdfxml_update_document_locator(rdf_parser);
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NON_NFC_FATAL))
raptor_parser_error(rdf_parser, message, el_name, buffer);
else
raptor_parser_warning(rdf_parser, message, el_name, buffer);
}
xmlliteral_term = raptor_new_term_from_literal(rdf_parser->world,
buffer,
RAPTOR_RDF_XMLLiteral_URI(rdf_parser->world),
NULL);
if(state == RAPTOR_STATE_MEMBER_PROPERTYELT) {
raptor_uri* predicate_uri;
element->parent->last_ordinal++;
predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world, element->parent->last_ordinal);
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
predicate_uri,
xmlliteral_term,
element->reified,
element->parent);
raptor_free_uri(predicate_uri);
} else {
raptor_rdfxml_generate_statement(rdf_parser,
element->parent->subject,
element_name_uri,
xmlliteral_term,
element->reified,
element->parent);
}
raptor_free_term(xmlliteral_term);
/* Finish the xml writer iostream for parseType="Literal" */
if(rdf_xml_parser->xml_writer) {
raptor_free_xml_writer(rdf_xml_parser->xml_writer);
RAPTOR_FREE(char*, rdf_xml_parser->xml_content);
rdf_xml_parser->xml_content = NULL;
rdf_xml_parser->xml_content_length = 0;
}
}
break;
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_NODES:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_UNKNOWN:
case RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_LAST:
default:
raptor_parser_fatal_error(rdf_parser,
"%s: Internal error in state RAPTOR_STATE_PROPERTYELT - got unexpected content type %s (%d)",
__func__,
raptor_rdfxml_element_content_type_as_string(element->content_type),
element->content_type);
} /* end switch */
finished = 1;
break;
case RAPTOR_STATE_INVALID:
default:
raptor_parser_fatal_error(rdf_parser,
"%s: Internal error - unexpected parser state %d - %s",
__func__,
state,
raptor_rdfxml_state_as_string(state));
finished = 1;
} /* end switch */
if(state != element->state) {
element->state = state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Moved to state %d - %s\n", state,
raptor_rdfxml_state_as_string(state));
#endif
}
} /* end while */
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Ending in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
return;
oom:
raptor_parser_fatal_error(rdf_parser, "Out of memory, skipping");
element->state = RAPTOR_STATE_SKIPPING;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,597 | raptor_rdfxml_generate_statement(raptor_parser *rdf_parser,
raptor_term *subject_term,
raptor_uri *predicate_uri,
raptor_term *object_term,
raptor_term *reified_term,
raptor_rdfxml_element* bag_element)
{
raptor_statement *statement = &rdf_parser->statement;
raptor_term* predicate_term = NULL;
int free_reified_term = 0;
if(rdf_parser->failed)
return;
#ifdef RAPTOR_DEBUG_VERBOSE
if(!subject_term)
RAPTOR_FATAL1("Statement has no subject\n");
if(!predicate_uri)
RAPTOR_FATAL1("Statement has no predicate\n");
if(!object_term)
RAPTOR_FATAL1("Statement has no object\n");
#endif
predicate_term = raptor_new_term_from_uri(rdf_parser->world, predicate_uri);
if(!predicate_term)
return;
statement->subject = subject_term;
statement->predicate = predicate_term;
statement->object = object_term;
#ifdef RAPTOR_DEBUG_VERBOSE
fprintf(stderr, "raptor_rdfxml_generate_statement: Generating statement: ");
raptor_statement_print(statement, stderr);
fputc('\n', stderr);
#endif
if(!rdf_parser->emitted_default_graph) {
raptor_parser_start_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph++;
}
if(!rdf_parser->statement_handler)
goto generate_tidy;
/* Generate the statement; or is it a fact? */
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* the bagID mess */
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID) &&
bag_element && bag_element->bag) {
raptor_term* bag = bag_element->bag;
raptor_uri* bag_predicate_uri = NULL;
raptor_term* bag_predicate_term = NULL;
statement->subject = bag;
bag_element->last_bag_ordinal++;
/* new URI object */
bag_predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world,
bag_element->last_bag_ordinal);
if(!bag_predicate_uri)
goto generate_tidy;
bag_predicate_term = raptor_new_term_from_uri(rdf_parser->world,
bag_predicate_uri);
raptor_free_uri(bag_predicate_uri);
if(!bag_predicate_term)
goto generate_tidy;
statement->predicate = bag_predicate_term;
if(!reified_term || !reified_term->value.blank.string) {
unsigned char *reified_id = NULL;
/* reified_term is NULL so generate a bag ID */
reified_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!reified_id)
goto generate_tidy;
reified_term = raptor_new_term_from_blank(rdf_parser->world, reified_id);
RAPTOR_FREE(char*, reified_id);
if(!reified_term)
goto generate_tidy;
free_reified_term = 1;
}
statement->object = reified_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
if(bag_predicate_term)
raptor_free_term(bag_predicate_term);
}
/* return if is there no reified ID (that is valid) */
if(!reified_term || !reified_term->value.blank.string)
goto generate_tidy;
/* otherwise generate reified statements */
statement->subject = reified_term;
statement->predicate = RAPTOR_RDF_type_term(rdf_parser->world);
statement->object = RAPTOR_RDF_Statement_term(rdf_parser->world);
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* statement->subject = reified_term; */
statement->predicate = RAPTOR_RDF_subject_term(rdf_parser->world);
statement->object = subject_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* statement->subject = reified_term; */
statement->predicate = RAPTOR_RDF_predicate_term(rdf_parser->world);
statement->object = predicate_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* statement->subject = reified_term; */
statement->predicate = RAPTOR_RDF_object_term(rdf_parser->world);
statement->object = object_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
generate_tidy:
/* Tidy up things allocated here */
if(predicate_term)
raptor_free_term(predicate_term);
if(free_reified_term && reified_term)
raptor_free_term(reified_term);
}
| +Info | 0 | raptor_rdfxml_generate_statement(raptor_parser *rdf_parser,
raptor_term *subject_term,
raptor_uri *predicate_uri,
raptor_term *object_term,
raptor_term *reified_term,
raptor_rdfxml_element* bag_element)
{
raptor_statement *statement = &rdf_parser->statement;
raptor_term* predicate_term = NULL;
int free_reified_term = 0;
if(rdf_parser->failed)
return;
#ifdef RAPTOR_DEBUG_VERBOSE
if(!subject_term)
RAPTOR_FATAL1("Statement has no subject\n");
if(!predicate_uri)
RAPTOR_FATAL1("Statement has no predicate\n");
if(!object_term)
RAPTOR_FATAL1("Statement has no object\n");
#endif
predicate_term = raptor_new_term_from_uri(rdf_parser->world, predicate_uri);
if(!predicate_term)
return;
statement->subject = subject_term;
statement->predicate = predicate_term;
statement->object = object_term;
#ifdef RAPTOR_DEBUG_VERBOSE
fprintf(stderr, "raptor_rdfxml_generate_statement: Generating statement: ");
raptor_statement_print(statement, stderr);
fputc('\n', stderr);
#endif
if(!rdf_parser->emitted_default_graph) {
raptor_parser_start_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph++;
}
if(!rdf_parser->statement_handler)
goto generate_tidy;
/* Generate the statement; or is it a fact? */
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* the bagID mess */
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID) &&
bag_element && bag_element->bag) {
raptor_term* bag = bag_element->bag;
raptor_uri* bag_predicate_uri = NULL;
raptor_term* bag_predicate_term = NULL;
statement->subject = bag;
bag_element->last_bag_ordinal++;
/* new URI object */
bag_predicate_uri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world,
bag_element->last_bag_ordinal);
if(!bag_predicate_uri)
goto generate_tidy;
bag_predicate_term = raptor_new_term_from_uri(rdf_parser->world,
bag_predicate_uri);
raptor_free_uri(bag_predicate_uri);
if(!bag_predicate_term)
goto generate_tidy;
statement->predicate = bag_predicate_term;
if(!reified_term || !reified_term->value.blank.string) {
unsigned char *reified_id = NULL;
/* reified_term is NULL so generate a bag ID */
reified_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!reified_id)
goto generate_tidy;
reified_term = raptor_new_term_from_blank(rdf_parser->world, reified_id);
RAPTOR_FREE(char*, reified_id);
if(!reified_term)
goto generate_tidy;
free_reified_term = 1;
}
statement->object = reified_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
if(bag_predicate_term)
raptor_free_term(bag_predicate_term);
}
/* return if is there no reified ID (that is valid) */
if(!reified_term || !reified_term->value.blank.string)
goto generate_tidy;
/* otherwise generate reified statements */
statement->subject = reified_term;
statement->predicate = RAPTOR_RDF_type_term(rdf_parser->world);
statement->object = RAPTOR_RDF_Statement_term(rdf_parser->world);
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* statement->subject = reified_term; */
statement->predicate = RAPTOR_RDF_subject_term(rdf_parser->world);
statement->object = subject_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* statement->subject = reified_term; */
statement->predicate = RAPTOR_RDF_predicate_term(rdf_parser->world);
statement->object = predicate_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
/* statement->subject = reified_term; */
statement->predicate = RAPTOR_RDF_object_term(rdf_parser->world);
statement->object = object_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data, statement);
generate_tidy:
/* Tidy up things allocated here */
if(predicate_term)
raptor_free_term(predicate_term);
if(free_reified_term && reified_term)
raptor_free_term(reified_term);
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,598 | raptor_rdfxml_inscope_base_uri(raptor_parser *rdf_parser)
{
raptor_rdfxml_parser* rdf_xml_parser;
raptor_uri* base_uri;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
base_uri = raptor_sax2_inscope_base_uri(rdf_xml_parser->sax2);
if(!base_uri)
base_uri = rdf_parser->base_uri;
return base_uri;
}
| +Info | 0 | raptor_rdfxml_inscope_base_uri(raptor_parser *rdf_parser)
{
raptor_rdfxml_parser* rdf_xml_parser;
raptor_uri* base_uri;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
base_uri = raptor_sax2_inscope_base_uri(rdf_xml_parser->sax2);
if(!base_uri)
base_uri = rdf_parser->base_uri;
return base_uri;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,599 | raptor_rdfxml_parse_chunk(raptor_parser* rdf_parser,
const unsigned char *buffer,
size_t len, int is_end)
{
raptor_rdfxml_parser* rdf_xml_parser;
int rc;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(rdf_parser->failed)
return 1;
rc = raptor_sax2_parse_chunk(rdf_xml_parser->sax2, buffer, len, is_end);
if(is_end) {
if(rdf_parser->emitted_default_graph) {
raptor_parser_end_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph--;
}
}
return rc;
}
| +Info | 0 | raptor_rdfxml_parse_chunk(raptor_parser* rdf_parser,
const unsigned char *buffer,
size_t len, int is_end)
{
raptor_rdfxml_parser* rdf_xml_parser;
int rc;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(rdf_parser->failed)
return 1;
rc = raptor_sax2_parse_chunk(rdf_xml_parser->sax2, buffer, len, is_end);
if(is_end) {
if(rdf_parser->emitted_default_graph) {
raptor_parser_end_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph--;
}
}
return rc;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.