idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
11,100 | ZEND_METHOD(CURLFile, getPostFilename)
{
curlfile_get_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| DoS | 0 | ZEND_METHOD(CURLFile, getPostFilename)
{
curlfile_get_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| @@ -137,7 +137,10 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
- zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
+ zval *_this = getThis();
+
+ zend_unset_property(curl_CURLFile_class, _this, "name", sizeof("name")-1 TSRMLS_CC);
+ zend_update_property_string(curl_CURLFile_class, _this, "name", sizeof("name")-1, "" TSRMLS_CC);
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
}
/* }}} */ | CWE-416 | null | null |
11,101 | ZEND_METHOD(CURLFile, setMimeType)
{
curlfile_set_property("mime", INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| DoS | 0 | ZEND_METHOD(CURLFile, setMimeType)
{
curlfile_set_property("mime", INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| @@ -137,7 +137,10 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
- zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
+ zval *_this = getThis();
+
+ zend_unset_property(curl_CURLFile_class, _this, "name", sizeof("name")-1 TSRMLS_CC);
+ zend_update_property_string(curl_CURLFile_class, _this, "name", sizeof("name")-1, "" TSRMLS_CC);
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
}
/* }}} */ | CWE-416 | null | null |
11,102 | ZEND_METHOD(CURLFile, setPostFilename)
{
curlfile_set_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| DoS | 0 | ZEND_METHOD(CURLFile, setPostFilename)
{
curlfile_set_property("postname", INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
| @@ -137,7 +137,10 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
- zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
+ zval *_this = getThis();
+
+ zend_unset_property(curl_CURLFile_class, _this, "name", sizeof("name")-1 TSRMLS_CC);
+ zend_update_property_string(curl_CURLFile_class, _this, "name", sizeof("name")-1, "" TSRMLS_CC);
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
}
/* }}} */ | CWE-416 | null | null |
11,103 | static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
{
char *fname = NULL, *mime = NULL, *postname = NULL;
int fname_len, mime_len, postname_len;
zval *cf = return_value;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) {
return;
}
if (fname) {
zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, fname TSRMLS_CC);
}
if (mime) {
zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, mime TSRMLS_CC);
}
if (postname) {
zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, postname TSRMLS_CC);
}
}
| DoS | 0 | static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
{
char *fname = NULL, *mime = NULL, *postname = NULL;
int fname_len, mime_len, postname_len;
zval *cf = return_value;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) {
return;
}
if (fname) {
zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, fname TSRMLS_CC);
}
if (mime) {
zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, mime TSRMLS_CC);
}
if (postname) {
zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, postname TSRMLS_CC);
}
}
| @@ -137,7 +137,10 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
- zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
+ zval *_this = getThis();
+
+ zend_unset_property(curl_CURLFile_class, _this, "name", sizeof("name")-1 TSRMLS_CC);
+ zend_update_property_string(curl_CURLFile_class, _this, "name", sizeof("name")-1, "" TSRMLS_CC);
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
}
/* }}} */ | CWE-416 | null | null |
11,104 | static void curlfile_get_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
{
zval *res;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
res = zend_read_property(curl_CURLFile_class, getThis(), name, strlen(name), 1 TSRMLS_CC);
*return_value = *res;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
}
| DoS | 0 | static void curlfile_get_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
{
zval *res;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
res = zend_read_property(curl_CURLFile_class, getThis(), name, strlen(name), 1 TSRMLS_CC);
*return_value = *res;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
}
| @@ -137,7 +137,10 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
- zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
+ zval *_this = getThis();
+
+ zend_unset_property(curl_CURLFile_class, _this, "name", sizeof("name")-1 TSRMLS_CC);
+ zend_update_property_string(curl_CURLFile_class, _this, "name", sizeof("name")-1, "" TSRMLS_CC);
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
}
/* }}} */ | CWE-416 | null | null |
11,105 | void curlfile_register_class(TSRMLS_D)
{
zend_class_entry ce;
INIT_CLASS_ENTRY( ce, "CURLFile", curlfile_funcs );
curl_CURLFile_class = zend_register_internal_class(&ce TSRMLS_CC);
zend_declare_property_string(curl_CURLFile_class, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_string(curl_CURLFile_class, "mime", sizeof("mime")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_string(curl_CURLFile_class, "postname", sizeof("postname")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
}
| DoS | 0 | void curlfile_register_class(TSRMLS_D)
{
zend_class_entry ce;
INIT_CLASS_ENTRY( ce, "CURLFile", curlfile_funcs );
curl_CURLFile_class = zend_register_internal_class(&ce TSRMLS_CC);
zend_declare_property_string(curl_CURLFile_class, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_string(curl_CURLFile_class, "mime", sizeof("mime")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_string(curl_CURLFile_class, "postname", sizeof("postname")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC);
}
| @@ -137,7 +137,10 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
- zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
+ zval *_this = getThis();
+
+ zend_unset_property(curl_CURLFile_class, _this, "name", sizeof("name")-1 TSRMLS_CC);
+ zend_update_property_string(curl_CURLFile_class, _this, "name", sizeof("name")-1, "" TSRMLS_CC);
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
}
/* }}} */ | CWE-416 | null | null |
11,106 | static void curlfile_set_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
{
char *arg = NULL;
int arg_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
return;
}
zend_update_property_string(curl_CURLFile_class, getThis(), name, strlen(name), arg TSRMLS_CC);
}
| DoS | 0 | static void curlfile_set_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
{
char *arg = NULL;
int arg_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
return;
}
zend_update_property_string(curl_CURLFile_class, getThis(), name, strlen(name), arg TSRMLS_CC);
}
| @@ -137,7 +137,10 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
- zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "" TSRMLS_CC);
+ zval *_this = getThis();
+
+ zend_unset_property(curl_CURLFile_class, _this, "name", sizeof("name")-1 TSRMLS_CC);
+ zend_update_property_string(curl_CURLFile_class, _this, "name", sizeof("name")-1, "" TSRMLS_CC);
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0 TSRMLS_CC);
}
/* }}} */ | CWE-416 | null | null |
11,107 | namecmp(const void *key, const void *name)
{
return strcmp((char *)key, *(char **)name);
}
| DoS | 0 | namecmp(const void *key, const void *name)
{
return strcmp((char *)key, *(char **)name);
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,108 | pdf_array_delete(fz_context *ctx, pdf_obj *obj, int i)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
if (i < 0 || i >= ARRAY(obj)->len)
fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
pdf_drop_obj(ctx, ARRAY(obj)->items[i]);
ARRAY(obj)->items[i] = 0;
ARRAY(obj)->len--;
memmove(ARRAY(obj)->items + i, ARRAY(obj)->items + i + 1, (ARRAY(obj)->len - i) * sizeof(pdf_obj*));
}
| DoS | 0 | pdf_array_delete(fz_context *ctx, pdf_obj *obj, int i)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
if (i < 0 || i >= ARRAY(obj)->len)
fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
pdf_drop_obj(ctx, ARRAY(obj)->items[i]);
ARRAY(obj)->items[i] = 0;
ARRAY(obj)->len--;
memmove(ARRAY(obj)->items + i, ARRAY(obj)->items + i + 1, (ARRAY(obj)->len - i) * sizeof(pdf_obj*));
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,109 | pdf_array_find(fz_context *ctx, pdf_obj *arr, pdf_obj *obj)
{
int i, len;
len = pdf_array_len(ctx, arr);
for (i = 0; i < len; i++)
if (!pdf_objcmp(ctx, pdf_array_get(ctx, arr, i), obj))
return i;
return -1;
}
| DoS | 0 | pdf_array_find(fz_context *ctx, pdf_obj *arr, pdf_obj *obj)
{
int i, len;
len = pdf_array_len(ctx, arr);
for (i = 0; i < len; i++)
if (!pdf_objcmp(ctx, pdf_array_get(ctx, arr, i), obj))
return i;
return -1;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,110 | pdf_array_get(fz_context *ctx, pdf_obj *obj, int i)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
return NULL;
if (i < 0 || i >= ARRAY(obj)->len)
return NULL;
return ARRAY(obj)->items[i];
}
| DoS | 0 | pdf_array_get(fz_context *ctx, pdf_obj *obj, int i)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
return NULL;
if (i < 0 || i >= ARRAY(obj)->len)
return NULL;
return ARRAY(obj)->items[i];
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,111 | pdf_array_grow(fz_context *ctx, pdf_obj_array *obj)
{
int i;
int new_cap = (obj->cap * 3) / 2;
obj->items = fz_resize_array(ctx, obj->items, new_cap, sizeof(pdf_obj*));
obj->cap = new_cap;
for (i = obj->len ; i < obj->cap; i++)
obj->items[i] = NULL;
}
| DoS | 0 | pdf_array_grow(fz_context *ctx, pdf_obj_array *obj)
{
int i;
int new_cap = (obj->cap * 3) / 2;
obj->items = fz_resize_array(ctx, obj->items, new_cap, sizeof(pdf_obj*));
obj->cap = new_cap;
for (i = obj->len ; i < obj->cap; i++)
obj->items[i] = NULL;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,112 | pdf_array_insert(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
if (i < 0 || i > ARRAY(obj)->len)
fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
if (!item)
item = PDF_OBJ_NULL;
prepare_object_for_alteration(ctx, obj, item);
if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
pdf_array_grow(ctx, ARRAY(obj));
memmove(ARRAY(obj)->items + i + 1, ARRAY(obj)->items + i, (ARRAY(obj)->len - i) * sizeof(pdf_obj*));
ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item);
ARRAY(obj)->len++;
}
| DoS | 0 | pdf_array_insert(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
if (i < 0 || i > ARRAY(obj)->len)
fz_throw(ctx, FZ_ERROR_GENERIC, "index out of bounds");
if (!item)
item = PDF_OBJ_NULL;
prepare_object_for_alteration(ctx, obj, item);
if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
pdf_array_grow(ctx, ARRAY(obj));
memmove(ARRAY(obj)->items + i + 1, ARRAY(obj)->items + i, (ARRAY(obj)->len - i) * sizeof(pdf_obj*));
ARRAY(obj)->items[i] = pdf_keep_obj(ctx, item);
ARRAY(obj)->len++;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,113 | pdf_array_insert_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i)
{
RESOLVE(obj);
if (obj >= PDF_OBJ__LIMIT)
{
fz_try(ctx)
pdf_array_insert(ctx, obj, item, i);
fz_always(ctx)
pdf_drop_obj(ctx, item);
fz_catch(ctx)
fz_rethrow(ctx);
}
}
| DoS | 0 | pdf_array_insert_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i)
{
RESOLVE(obj);
if (obj >= PDF_OBJ__LIMIT)
{
fz_try(ctx)
pdf_array_insert(ctx, obj, item, i);
fz_always(ctx)
pdf_drop_obj(ctx, item);
fz_catch(ctx)
fz_rethrow(ctx);
}
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,114 | pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
if (!item)
item = PDF_OBJ_NULL;
prepare_object_for_alteration(ctx, obj, item);
if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
pdf_array_grow(ctx, ARRAY(obj));
ARRAY(obj)->items[ARRAY(obj)->len] = pdf_keep_obj(ctx, item);
ARRAY(obj)->len++;
}
| DoS | 0 | pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item)
{
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
if (!item)
item = PDF_OBJ_NULL;
prepare_object_for_alteration(ctx, obj, item);
if (ARRAY(obj)->len + 1 > ARRAY(obj)->cap)
pdf_array_grow(ctx, ARRAY(obj));
ARRAY(obj)->items[ARRAY(obj)->len] = pdf_keep_obj(ctx, item);
ARRAY(obj)->len++;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,115 | pdf_array_push_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item)
{
RESOLVE(obj);
if (obj >= PDF_OBJ__LIMIT)
{
fz_try(ctx)
pdf_array_push(ctx, obj, item);
fz_always(ctx)
pdf_drop_obj(ctx, item);
fz_catch(ctx)
fz_rethrow(ctx);
}
}
| DoS | 0 | pdf_array_push_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item)
{
RESOLVE(obj);
if (obj >= PDF_OBJ__LIMIT)
{
fz_try(ctx)
pdf_array_push(ctx, obj, item);
fz_always(ctx)
pdf_drop_obj(ctx, item);
fz_catch(ctx)
fz_rethrow(ctx);
}
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,116 | pdf_array_put_drop(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item)
{
pdf_array_put(ctx, obj, i, item);
pdf_drop_obj(ctx, item);
}
| DoS | 0 | pdf_array_put_drop(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item)
{
pdf_array_put(ctx, obj, i, item);
pdf_drop_obj(ctx, item);
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,117 | pdf_copy_array(fz_context *ctx, pdf_obj *obj)
{
pdf_document *doc;
pdf_obj *arr;
int i;
int n;
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
doc = ARRAY(obj)->doc;
n = pdf_array_len(ctx, obj);
arr = pdf_new_array(ctx, doc, n);
for (i = 0; i < n; i++)
pdf_array_push(ctx, arr, pdf_array_get(ctx, obj, i));
return arr;
}
| DoS | 0 | pdf_copy_array(fz_context *ctx, pdf_obj *obj)
{
pdf_document *doc;
pdf_obj *arr;
int i;
int n;
RESOLVE(obj);
if (!OBJ_IS_ARRAY(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not an array (%s)", pdf_objkindstr(obj));
doc = ARRAY(obj)->doc;
n = pdf_array_len(ctx, obj);
arr = pdf_new_array(ctx, doc, n);
for (i = 0; i < n; i++)
pdf_array_push(ctx, arr, pdf_array_get(ctx, obj, i));
return arr;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,118 | pdf_copy_dict(fz_context *ctx, pdf_obj *obj)
{
pdf_document *doc;
pdf_obj *dict;
int i, n;
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
doc = DICT(obj)->doc;
n = pdf_dict_len(ctx, obj);
dict = pdf_new_dict(ctx, doc, n);
for (i = 0; i < n; i++)
pdf_dict_put(ctx, dict, pdf_dict_get_key(ctx, obj, i), pdf_dict_get_val(ctx, obj, i));
return dict;
}
| DoS | 0 | pdf_copy_dict(fz_context *ctx, pdf_obj *obj)
{
pdf_document *doc;
pdf_obj *dict;
int i, n;
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
doc = DICT(obj)->doc;
n = pdf_dict_len(ctx, obj);
dict = pdf_new_dict(ctx, doc, n);
for (i = 0; i < n; i++)
pdf_dict_put(ctx, dict, pdf_dict_get_key(ctx, obj, i), pdf_dict_get_val(ctx, obj, i));
return dict;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,119 | pdf_dict_find(fz_context *ctx, pdf_obj *obj, pdf_obj *key)
{
int len = DICT(obj)->len;
if ((obj->flags & PDF_FLAGS_SORTED) && len > 0)
{
int l = 0;
int r = len - 1;
pdf_obj *k = DICT(obj)->items[r].k;
if (k == key || (k >= PDF_OBJ__LIMIT && strcmp(NAME(k)->n, PDF_NAMES[(intptr_t)key]) < 0))
{
return -1 - (r+1);
}
while (l <= r)
{
int m = (l + r) >> 1;
int c;
k = DICT(obj)->items[m].k;
c = (k < PDF_OBJ__LIMIT ? (char *)key-(char *)k : -strcmp(NAME(k)->n, PDF_NAMES[(intptr_t)key]));
if (c < 0)
r = m - 1;
else if (c > 0)
l = m + 1;
else
return m;
}
return -1 - l;
}
else
{
int i;
for (i = 0; i < len; i++)
{
pdf_obj *k = DICT(obj)->items[i].k;
if (k < PDF_OBJ__LIMIT)
{
if (k == key)
return i;
}
else
{
if (!strcmp(PDF_NAMES[(intptr_t)key], NAME(k)->n))
return i;
}
}
return -1 - len;
}
}
| DoS | 0 | pdf_dict_find(fz_context *ctx, pdf_obj *obj, pdf_obj *key)
{
int len = DICT(obj)->len;
if ((obj->flags & PDF_FLAGS_SORTED) && len > 0)
{
int l = 0;
int r = len - 1;
pdf_obj *k = DICT(obj)->items[r].k;
if (k == key || (k >= PDF_OBJ__LIMIT && strcmp(NAME(k)->n, PDF_NAMES[(intptr_t)key]) < 0))
{
return -1 - (r+1);
}
while (l <= r)
{
int m = (l + r) >> 1;
int c;
k = DICT(obj)->items[m].k;
c = (k < PDF_OBJ__LIMIT ? (char *)key-(char *)k : -strcmp(NAME(k)->n, PDF_NAMES[(intptr_t)key]));
if (c < 0)
r = m - 1;
else if (c > 0)
l = m + 1;
else
return m;
}
return -1 - l;
}
else
{
int i;
for (i = 0; i < len; i++)
{
pdf_obj *k = DICT(obj)->items[i].k;
if (k < PDF_OBJ__LIMIT)
{
if (k == key)
return i;
}
else
{
if (!strcmp(PDF_NAMES[(intptr_t)key], NAME(k)->n))
return i;
}
}
return -1 - len;
}
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,120 | pdf_dict_finds(fz_context *ctx, pdf_obj *obj, const char *key)
{
int len = DICT(obj)->len;
if ((obj->flags & PDF_FLAGS_SORTED) && len > 0)
{
int l = 0;
int r = len - 1;
if (strcmp(pdf_to_name(ctx, DICT(obj)->items[r].k), key) < 0)
{
return -1 - (r+1);
}
while (l <= r)
{
int m = (l + r) >> 1;
int c = -strcmp(pdf_to_name(ctx, DICT(obj)->items[m].k), key);
if (c < 0)
r = m - 1;
else if (c > 0)
l = m + 1;
else
return m;
}
return -1 - l;
}
else
{
int i;
for (i = 0; i < len; i++)
if (strcmp(pdf_to_name(ctx, DICT(obj)->items[i].k), key) == 0)
return i;
return -1 - len;
}
}
| DoS | 0 | pdf_dict_finds(fz_context *ctx, pdf_obj *obj, const char *key)
{
int len = DICT(obj)->len;
if ((obj->flags & PDF_FLAGS_SORTED) && len > 0)
{
int l = 0;
int r = len - 1;
if (strcmp(pdf_to_name(ctx, DICT(obj)->items[r].k), key) < 0)
{
return -1 - (r+1);
}
while (l <= r)
{
int m = (l + r) >> 1;
int c = -strcmp(pdf_to_name(ctx, DICT(obj)->items[m].k), key);
if (c < 0)
r = m - 1;
else if (c > 0)
l = m + 1;
else
return m;
}
return -1 - l;
}
else
{
int i;
for (i = 0; i < len; i++)
if (strcmp(pdf_to_name(ctx, DICT(obj)->items[i].k), key) == 0)
return i;
return -1 - len;
}
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,121 | pdf_dict_get(fz_context *ctx, pdf_obj *obj, pdf_obj *key)
{
int i;
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
return NULL;
if (!OBJ_IS_NAME(key))
return NULL;
if (key < PDF_OBJ_NAME__LIMIT)
i = pdf_dict_find(ctx, obj, key);
else
i = pdf_dict_finds(ctx, obj, pdf_to_name(ctx, key));
if (i >= 0)
return DICT(obj)->items[i].v;
return NULL;
}
| DoS | 0 | pdf_dict_get(fz_context *ctx, pdf_obj *obj, pdf_obj *key)
{
int i;
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
return NULL;
if (!OBJ_IS_NAME(key))
return NULL;
if (key < PDF_OBJ_NAME__LIMIT)
i = pdf_dict_find(ctx, obj, key);
else
i = pdf_dict_finds(ctx, obj, pdf_to_name(ctx, key));
if (i >= 0)
return DICT(obj)->items[i].v;
return NULL;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,122 | pdf_dict_get_key(fz_context *ctx, pdf_obj *obj, int i)
{
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
return NULL;
if (i < 0 || i >= DICT(obj)->len)
return NULL;
return DICT(obj)->items[i].k;
}
| DoS | 0 | pdf_dict_get_key(fz_context *ctx, pdf_obj *obj, int i)
{
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
return NULL;
if (i < 0 || i >= DICT(obj)->len)
return NULL;
return DICT(obj)->items[i].k;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,123 | pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
{
pdf_obj *v;
v = pdf_dict_get(ctx, obj, key);
if (v)
return v;
return pdf_dict_get(ctx, obj, abbrev);
}
| DoS | 0 | pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
{
pdf_obj *v;
v = pdf_dict_get(ctx, obj, key);
if (v)
return v;
return pdf_dict_get(ctx, obj, abbrev);
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,124 | pdf_dict_getl(fz_context *ctx, pdf_obj *obj, ...)
{
va_list keys;
pdf_obj *key;
va_start(keys, obj);
while (obj != NULL && (key = va_arg(keys, pdf_obj *)) != NULL)
{
obj = pdf_dict_get(ctx, obj, key);
}
va_end(keys);
return obj;
}
| DoS | 0 | pdf_dict_getl(fz_context *ctx, pdf_obj *obj, ...)
{
va_list keys;
pdf_obj *key;
va_start(keys, obj);
while (obj != NULL && (key = va_arg(keys, pdf_obj *)) != NULL)
{
obj = pdf_dict_get(ctx, obj, key);
}
va_end(keys);
return obj;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,125 | pdf_dict_getp(fz_context *ctx, pdf_obj *obj, const char *keys)
{
char buf[256];
char *k, *e;
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
return NULL;
if (strlen(keys)+1 > 256)
fz_throw(ctx, FZ_ERROR_GENERIC, "path too long");
strcpy(buf, keys);
e = buf;
while (*e && obj)
{
k = e;
while (*e != '/' && *e != '\0')
e++;
if (*e == '/')
{
*e = '\0';
e++;
}
obj = pdf_dict_gets(ctx, obj, k);
}
return obj;
}
| DoS | 0 | pdf_dict_getp(fz_context *ctx, pdf_obj *obj, const char *keys)
{
char buf[256];
char *k, *e;
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
return NULL;
if (strlen(keys)+1 > 256)
fz_throw(ctx, FZ_ERROR_GENERIC, "path too long");
strcpy(buf, keys);
e = buf;
while (*e && obj)
{
k = e;
while (*e != '/' && *e != '\0')
e++;
if (*e == '/')
{
*e = '\0';
e++;
}
obj = pdf_dict_gets(ctx, obj, k);
}
return obj;
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,126 | pdf_dict_getsa(fz_context *ctx, pdf_obj *obj, const char *key, const char *abbrev)
{
pdf_obj *v;
v = pdf_dict_gets(ctx, obj, key);
if (v)
return v;
return pdf_dict_gets(ctx, obj, abbrev);
}
| DoS | 0 | pdf_dict_getsa(fz_context *ctx, pdf_obj *obj, const char *key, const char *abbrev)
{
pdf_obj *v;
v = pdf_dict_gets(ctx, obj, key);
if (v)
return v;
return pdf_dict_gets(ctx, obj, abbrev);
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,127 | pdf_dict_grow(fz_context *ctx, pdf_obj *obj)
{
int i;
int new_cap = (DICT(obj)->cap * 3) / 2;
DICT(obj)->items = fz_resize_array(ctx, DICT(obj)->items, new_cap, sizeof(struct keyval));
DICT(obj)->cap = new_cap;
for (i = DICT(obj)->len; i < DICT(obj)->cap; i++)
{
DICT(obj)->items[i].k = NULL;
DICT(obj)->items[i].v = NULL;
}
}
| DoS | 0 | pdf_dict_grow(fz_context *ctx, pdf_obj *obj)
{
int i;
int new_cap = (DICT(obj)->cap * 3) / 2;
DICT(obj)->items = fz_resize_array(ctx, DICT(obj)->items, new_cap, sizeof(struct keyval));
DICT(obj)->cap = new_cap;
for (i = DICT(obj)->len; i < DICT(obj)->cap; i++)
{
DICT(obj)->items[i].k = NULL;
DICT(obj)->items[i].v = NULL;
}
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,128 | pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
}
| DoS | 0 | pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
}
| @@ -1265,11 +1265,14 @@ pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev)
return pdf_dict_get(ctx, obj, abbrev);
}
-void
-pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+static void
+pdf_dict_get_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
{
int i;
+ if (old_val)
+ *old_val = NULL;
+
RESOLVE(obj);
if (!OBJ_IS_DICT(obj))
fz_throw(ctx, FZ_ERROR_GENERIC, "not a dict (%s)", pdf_objkindstr(obj));
@@ -1295,7 +1298,10 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
pdf_obj *d = DICT(obj)->items[i].v;
DICT(obj)->items[i].v = pdf_keep_obj(ctx, val);
- pdf_drop_obj(ctx, d);
+ if (old_val)
+ *old_val = d;
+ else
+ pdf_drop_obj(ctx, d);
}
}
else
@@ -1316,10 +1322,27 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
}
void
+pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
+{
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+}
+
+void
pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val)
{
fz_try(ctx)
- pdf_dict_put(ctx, obj, key, val);
+ pdf_dict_get_put(ctx, obj, key, val, NULL);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+}
+
+void
+pdf_dict_get_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val, pdf_obj **old_val)
+{
+ fz_try(ctx)
+ pdf_dict_get_put(ctx, obj, key, val, old_val);
fz_always(ctx)
pdf_drop_obj(ctx, val);
fz_catch(ctx) | CWE-416 | null | null |
11,129 | static void add_root(fz_context *ctx, pdf_obj *obj, pdf_obj ***roots, int *num_roots, int *max_roots)
{
if (*num_roots == *max_roots)
{
int new_max_roots = *max_roots * 2;
if (new_max_roots == 0)
new_max_roots = 4;
*roots = fz_resize_array(ctx, *roots, new_max_roots, sizeof(**roots));
*max_roots = new_max_roots;
}
(*roots)[(*num_roots)++] = pdf_keep_obj(ctx, obj);
}
| DoS | 0 | static void add_root(fz_context *ctx, pdf_obj *obj, pdf_obj ***roots, int *num_roots, int *max_roots)
{
if (*num_roots == *max_roots)
{
int new_max_roots = *max_roots * 2;
if (new_max_roots == 0)
new_max_roots = 4;
*roots = fz_resize_array(ctx, *roots, new_max_roots, sizeof(**roots));
*max_roots = new_max_roots;
}
(*roots)[(*num_roots)++] = pdf_keep_obj(ctx, obj);
}
| @@ -260,6 +260,27 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
}
}
+static void
+orphan_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
+{
+ if (doc->orphans_count == doc->orphans_max)
+ {
+ int new_max = (doc->orphans_max ? doc->orphans_max*2 : 32);
+
+ fz_try(ctx)
+ {
+ doc->orphans = fz_resize_array(ctx, doc->orphans, new_max, sizeof(*doc->orphans));
+ doc->orphans_max = new_max;
+ }
+ fz_catch(ctx)
+ {
+ pdf_drop_obj(ctx, obj);
+ fz_rethrow(ctx);
+ }
+ }
+ doc->orphans[doc->orphans_count++] = obj;
+}
+
void
pdf_repair_xref(fz_context *ctx, pdf_document *doc)
{
@@ -528,12 +549,13 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
/* correct stream length for unencrypted documents */
if (!encrypt && list[i].stm_len >= 0)
{
+ pdf_obj *old_obj = NULL;
dict = pdf_load_object(ctx, doc, list[i].num);
length = pdf_new_int(ctx, doc, list[i].stm_len);
- pdf_dict_put(ctx, dict, PDF_NAME_Length, length);
- pdf_drop_obj(ctx, length);
-
+ pdf_dict_get_put_drop(ctx, dict, PDF_NAME_Length, length, &old_obj);
+ if (old_obj)
+ orphan_object(ctx, doc, old_obj);
pdf_drop_obj(ctx, dict);
}
} | CWE-416 | null | null |
11,130 | fz_catch(ctx)
{
pdf_drop_obj(ctx, encrypt);
pdf_drop_obj(ctx, id);
pdf_drop_obj(ctx, obj);
pdf_drop_obj(ctx, info);
fz_free(ctx, list);
fz_rethrow(ctx);
}
| DoS | 0 | fz_catch(ctx)
{
pdf_drop_obj(ctx, encrypt);
pdf_drop_obj(ctx, id);
pdf_drop_obj(ctx, obj);
pdf_drop_obj(ctx, info);
fz_free(ctx, list);
fz_rethrow(ctx);
}
| @@ -260,6 +260,27 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
}
}
+static void
+orphan_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
+{
+ if (doc->orphans_count == doc->orphans_max)
+ {
+ int new_max = (doc->orphans_max ? doc->orphans_max*2 : 32);
+
+ fz_try(ctx)
+ {
+ doc->orphans = fz_resize_array(ctx, doc->orphans, new_max, sizeof(*doc->orphans));
+ doc->orphans_max = new_max;
+ }
+ fz_catch(ctx)
+ {
+ pdf_drop_obj(ctx, obj);
+ fz_rethrow(ctx);
+ }
+ }
+ doc->orphans[doc->orphans_count++] = obj;
+}
+
void
pdf_repair_xref(fz_context *ctx, pdf_document *doc)
{
@@ -528,12 +549,13 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
/* correct stream length for unencrypted documents */
if (!encrypt && list[i].stm_len >= 0)
{
+ pdf_obj *old_obj = NULL;
dict = pdf_load_object(ctx, doc, list[i].num);
length = pdf_new_int(ctx, doc, list[i].stm_len);
- pdf_dict_put(ctx, dict, PDF_NAME_Length, length);
- pdf_drop_obj(ctx, length);
-
+ pdf_dict_get_put_drop(ctx, dict, PDF_NAME_Length, length, &old_obj);
+ if (old_obj)
+ orphan_object(ctx, doc, old_obj);
pdf_drop_obj(ctx, dict);
}
} | CWE-416 | null | null |
11,131 | pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, fz_off_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, fz_off_t *tmpofs, pdf_obj **root)
{
fz_stream *file = doc->file;
pdf_token tok;
int stm_len;
*stmofsp = 0;
if (stmlenp)
*stmlenp = -1;
stm_len = 0;
/* On entry to this function, we know that we've just seen
* '<int> <int> obj'. We expect the next thing we see to be a
* pdf object. Regardless of the type of thing we meet next
* we only need to fully parse it if it is a dictionary. */
tok = pdf_lex(ctx, file, buf);
if (tok == PDF_TOK_OPEN_DICT)
{
pdf_obj *dict, *obj;
fz_try(ctx)
{
dict = pdf_parse_dict(ctx, doc, file, buf);
}
fz_catch(ctx)
{
fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
/* Don't let a broken object at EOF overwrite a good one */
if (file->eof)
fz_rethrow(ctx);
/* Silently swallow the error */
dict = pdf_new_dict(ctx, NULL, 2);
}
/* We must be careful not to try to resolve any indirections
* here. We have just read dict, so we know it to be a non
* indirected dictionary. Before we look at any values that
* we get back from looking up in it, we need to check they
* aren't indirected. */
if (encrypt || id || root)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_Type);
if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_XRef))
{
if (encrypt)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_Encrypt);
if (obj)
{
pdf_drop_obj(ctx, *encrypt);
*encrypt = pdf_keep_obj(ctx, obj);
}
}
if (id)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_ID);
if (obj)
{
pdf_drop_obj(ctx, *id);
*id = pdf_keep_obj(ctx, obj);
}
}
if (root)
*root = pdf_keep_obj(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Root));
}
}
obj = pdf_dict_get(ctx, dict, PDF_NAME_Length);
if (!pdf_is_indirect(ctx, obj) && pdf_is_int(ctx, obj))
stm_len = pdf_to_int(ctx, obj);
if (doc->file_reading_linearly && page)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_Type);
if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_Page))
{
pdf_drop_obj(ctx, *page);
*page = pdf_keep_obj(ctx, dict);
}
}
pdf_drop_obj(ctx, dict);
}
while ( tok != PDF_TOK_STREAM &&
tok != PDF_TOK_ENDOBJ &&
tok != PDF_TOK_ERROR &&
tok != PDF_TOK_EOF &&
tok != PDF_TOK_INT )
{
*tmpofs = fz_tell(ctx, file);
if (*tmpofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(ctx, file, buf);
}
if (tok == PDF_TOK_STREAM)
{
int c = fz_read_byte(ctx, file);
if (c == '\r') {
c = fz_peek_byte(ctx, file);
if (c == '\n')
fz_read_byte(ctx, file);
}
*stmofsp = fz_tell(ctx, file);
if (*stmofsp < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in file");
if (stm_len > 0)
{
fz_seek(ctx, file, *stmofsp + stm_len, 0);
fz_try(ctx)
{
tok = pdf_lex(ctx, file, buf);
}
fz_catch(ctx)
{
fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
fz_warn(ctx, "cannot find endstream token, falling back to scanning");
}
if (tok == PDF_TOK_ENDSTREAM)
goto atobjend;
fz_seek(ctx, file, *stmofsp, 0);
}
(void)fz_read(ctx, file, (unsigned char *) buf->scratch, 9);
while (memcmp(buf->scratch, "endstream", 9) != 0)
{
c = fz_read_byte(ctx, file);
if (c == EOF)
break;
memmove(&buf->scratch[0], &buf->scratch[1], 8);
buf->scratch[8] = c;
}
if (stmlenp)
*stmlenp = fz_tell(ctx, file) - *stmofsp - 9;
atobjend:
*tmpofs = fz_tell(ctx, file);
if (*tmpofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(ctx, file, buf);
if (tok != PDF_TOK_ENDOBJ)
fz_warn(ctx, "object missing 'endobj' token");
else
{
/* Read another token as we always return the next one */
*tmpofs = fz_tell(ctx, file);
if (*tmpofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(ctx, file, buf);
}
}
return tok;
}
| DoS | 0 | pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, fz_off_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, fz_off_t *tmpofs, pdf_obj **root)
{
fz_stream *file = doc->file;
pdf_token tok;
int stm_len;
*stmofsp = 0;
if (stmlenp)
*stmlenp = -1;
stm_len = 0;
/* On entry to this function, we know that we've just seen
* '<int> <int> obj'. We expect the next thing we see to be a
* pdf object. Regardless of the type of thing we meet next
* we only need to fully parse it if it is a dictionary. */
tok = pdf_lex(ctx, file, buf);
if (tok == PDF_TOK_OPEN_DICT)
{
pdf_obj *dict, *obj;
fz_try(ctx)
{
dict = pdf_parse_dict(ctx, doc, file, buf);
}
fz_catch(ctx)
{
fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
/* Don't let a broken object at EOF overwrite a good one */
if (file->eof)
fz_rethrow(ctx);
/* Silently swallow the error */
dict = pdf_new_dict(ctx, NULL, 2);
}
/* We must be careful not to try to resolve any indirections
* here. We have just read dict, so we know it to be a non
* indirected dictionary. Before we look at any values that
* we get back from looking up in it, we need to check they
* aren't indirected. */
if (encrypt || id || root)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_Type);
if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_XRef))
{
if (encrypt)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_Encrypt);
if (obj)
{
pdf_drop_obj(ctx, *encrypt);
*encrypt = pdf_keep_obj(ctx, obj);
}
}
if (id)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_ID);
if (obj)
{
pdf_drop_obj(ctx, *id);
*id = pdf_keep_obj(ctx, obj);
}
}
if (root)
*root = pdf_keep_obj(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Root));
}
}
obj = pdf_dict_get(ctx, dict, PDF_NAME_Length);
if (!pdf_is_indirect(ctx, obj) && pdf_is_int(ctx, obj))
stm_len = pdf_to_int(ctx, obj);
if (doc->file_reading_linearly && page)
{
obj = pdf_dict_get(ctx, dict, PDF_NAME_Type);
if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_Page))
{
pdf_drop_obj(ctx, *page);
*page = pdf_keep_obj(ctx, dict);
}
}
pdf_drop_obj(ctx, dict);
}
while ( tok != PDF_TOK_STREAM &&
tok != PDF_TOK_ENDOBJ &&
tok != PDF_TOK_ERROR &&
tok != PDF_TOK_EOF &&
tok != PDF_TOK_INT )
{
*tmpofs = fz_tell(ctx, file);
if (*tmpofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(ctx, file, buf);
}
if (tok == PDF_TOK_STREAM)
{
int c = fz_read_byte(ctx, file);
if (c == '\r') {
c = fz_peek_byte(ctx, file);
if (c == '\n')
fz_read_byte(ctx, file);
}
*stmofsp = fz_tell(ctx, file);
if (*stmofsp < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in file");
if (stm_len > 0)
{
fz_seek(ctx, file, *stmofsp + stm_len, 0);
fz_try(ctx)
{
tok = pdf_lex(ctx, file, buf);
}
fz_catch(ctx)
{
fz_rethrow_if(ctx, FZ_ERROR_TRYLATER);
fz_warn(ctx, "cannot find endstream token, falling back to scanning");
}
if (tok == PDF_TOK_ENDSTREAM)
goto atobjend;
fz_seek(ctx, file, *stmofsp, 0);
}
(void)fz_read(ctx, file, (unsigned char *) buf->scratch, 9);
while (memcmp(buf->scratch, "endstream", 9) != 0)
{
c = fz_read_byte(ctx, file);
if (c == EOF)
break;
memmove(&buf->scratch[0], &buf->scratch[1], 8);
buf->scratch[8] = c;
}
if (stmlenp)
*stmlenp = fz_tell(ctx, file) - *stmofsp - 9;
atobjend:
*tmpofs = fz_tell(ctx, file);
if (*tmpofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(ctx, file, buf);
if (tok != PDF_TOK_ENDOBJ)
fz_warn(ctx, "object missing 'endobj' token");
else
{
/* Read another token as we always return the next one */
*tmpofs = fz_tell(ctx, file);
if (*tmpofs < 0)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file");
tok = pdf_lex(ctx, file, buf);
}
}
return tok;
}
| @@ -260,6 +260,27 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
}
}
+static void
+orphan_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
+{
+ if (doc->orphans_count == doc->orphans_max)
+ {
+ int new_max = (doc->orphans_max ? doc->orphans_max*2 : 32);
+
+ fz_try(ctx)
+ {
+ doc->orphans = fz_resize_array(ctx, doc->orphans, new_max, sizeof(*doc->orphans));
+ doc->orphans_max = new_max;
+ }
+ fz_catch(ctx)
+ {
+ pdf_drop_obj(ctx, obj);
+ fz_rethrow(ctx);
+ }
+ }
+ doc->orphans[doc->orphans_count++] = obj;
+}
+
void
pdf_repair_xref(fz_context *ctx, pdf_document *doc)
{
@@ -528,12 +549,13 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
/* correct stream length for unencrypted documents */
if (!encrypt && list[i].stm_len >= 0)
{
+ pdf_obj *old_obj = NULL;
dict = pdf_load_object(ctx, doc, list[i].num);
length = pdf_new_int(ctx, doc, list[i].stm_len);
- pdf_dict_put(ctx, dict, PDF_NAME_Length, length);
- pdf_drop_obj(ctx, length);
-
+ pdf_dict_get_put_drop(ctx, dict, PDF_NAME_Length, length, &old_obj);
+ if (old_obj)
+ orphan_object(ctx, doc, old_obj);
pdf_drop_obj(ctx, dict);
}
} | CWE-416 | null | null |
11,132 | pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
{
pdf_obj *obj;
fz_stream *stm = NULL;
pdf_token tok;
int i, n, count;
pdf_lexbuf buf;
fz_var(stm);
pdf_lexbuf_init(ctx, &buf, PDF_LEXBUF_SMALL);
fz_try(ctx)
{
obj = pdf_load_object(ctx, doc, stm_num);
count = pdf_to_int(ctx, pdf_dict_get(ctx, obj, PDF_NAME_N));
pdf_drop_obj(ctx, obj);
stm = pdf_open_stream_number(ctx, doc, stm_num);
for (i = 0; i < count; i++)
{
pdf_xref_entry *entry;
tok = pdf_lex(ctx, stm, &buf);
if (tok != PDF_TOK_INT)
fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num);
n = buf.i;
if (n < 0)
{
fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i);
continue;
}
else if (n >= pdf_xref_len(ctx, doc))
{
fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i);
continue;
}
entry = pdf_get_populating_xref_entry(ctx, doc, n);
entry->ofs = stm_num;
entry->gen = i;
entry->num = n;
entry->stm_ofs = 0;
pdf_drop_obj(ctx, entry->obj);
entry->obj = NULL;
entry->type = 'o';
tok = pdf_lex(ctx, stm, &buf);
if (tok != PDF_TOK_INT)
fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num);
}
}
fz_always(ctx)
{
fz_drop_stream(ctx, stm);
pdf_lexbuf_fin(ctx, &buf);
}
fz_catch(ctx)
{
fz_rethrow(ctx);
}
}
| DoS | 0 | pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
{
pdf_obj *obj;
fz_stream *stm = NULL;
pdf_token tok;
int i, n, count;
pdf_lexbuf buf;
fz_var(stm);
pdf_lexbuf_init(ctx, &buf, PDF_LEXBUF_SMALL);
fz_try(ctx)
{
obj = pdf_load_object(ctx, doc, stm_num);
count = pdf_to_int(ctx, pdf_dict_get(ctx, obj, PDF_NAME_N));
pdf_drop_obj(ctx, obj);
stm = pdf_open_stream_number(ctx, doc, stm_num);
for (i = 0; i < count; i++)
{
pdf_xref_entry *entry;
tok = pdf_lex(ctx, stm, &buf);
if (tok != PDF_TOK_INT)
fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num);
n = buf.i;
if (n < 0)
{
fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i);
continue;
}
else if (n >= pdf_xref_len(ctx, doc))
{
fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i);
continue;
}
entry = pdf_get_populating_xref_entry(ctx, doc, n);
entry->ofs = stm_num;
entry->gen = i;
entry->num = n;
entry->stm_ofs = 0;
pdf_drop_obj(ctx, entry->obj);
entry->obj = NULL;
entry->type = 'o';
tok = pdf_lex(ctx, stm, &buf);
if (tok != PDF_TOK_INT)
fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num);
}
}
fz_always(ctx)
{
fz_drop_stream(ctx, stm);
pdf_lexbuf_fin(ctx, &buf);
}
fz_catch(ctx)
{
fz_rethrow(ctx);
}
}
| @@ -260,6 +260,27 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num)
}
}
+static void
+orphan_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
+{
+ if (doc->orphans_count == doc->orphans_max)
+ {
+ int new_max = (doc->orphans_max ? doc->orphans_max*2 : 32);
+
+ fz_try(ctx)
+ {
+ doc->orphans = fz_resize_array(ctx, doc->orphans, new_max, sizeof(*doc->orphans));
+ doc->orphans_max = new_max;
+ }
+ fz_catch(ctx)
+ {
+ pdf_drop_obj(ctx, obj);
+ fz_rethrow(ctx);
+ }
+ }
+ doc->orphans[doc->orphans_count++] = obj;
+}
+
void
pdf_repair_xref(fz_context *ctx, pdf_document *doc)
{
@@ -528,12 +549,13 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc)
/* correct stream length for unencrypted documents */
if (!encrypt && list[i].stm_len >= 0)
{
+ pdf_obj *old_obj = NULL;
dict = pdf_load_object(ctx, doc, list[i].num);
length = pdf_new_int(ctx, doc, list[i].stm_len);
- pdf_dict_put(ctx, dict, PDF_NAME_Length, length);
- pdf_drop_obj(ctx, length);
-
+ pdf_dict_get_put_drop(ctx, dict, PDF_NAME_Length, length, &old_obj);
+ if (old_obj)
+ orphan_object(ctx, doc, old_obj);
pdf_drop_obj(ctx, dict);
}
} | CWE-416 | null | null |
11,133 | static void ensure_incremental_xref(fz_context *ctx, pdf_document *doc)
{
/* If there are as yet no incremental sections, or if the most recent
* one has been used to sign a signature field, then we need a new one.
* After a signing, any further document changes require a new increment */
if ((doc->num_incremental_sections == 0 || doc->xref_sections[0].unsaved_sigs != NULL)
&& !doc->disallow_new_increments)
{
pdf_xref *xref = &doc->xref_sections[0];
pdf_xref *pxref;
pdf_xref_entry *new_table = fz_calloc(ctx, xref->num_objects, sizeof(pdf_xref_entry));
pdf_xref_subsec *sub;
pdf_obj *trailer = NULL;
int i;
fz_var(trailer);
fz_try(ctx)
{
sub = fz_malloc_struct(ctx, pdf_xref_subsec);
trailer = xref->trailer ? pdf_copy_dict(ctx, xref->trailer) : NULL;
doc->xref_sections = fz_resize_array(ctx, doc->xref_sections, doc->num_xref_sections + 1, sizeof(pdf_xref));
xref = &doc->xref_sections[0];
pxref = &doc->xref_sections[1];
memmove(pxref, xref, doc->num_xref_sections * sizeof(pdf_xref));
/* xref->num_objects is already correct */
xref->subsec = sub;
xref->trailer = trailer;
xref->pre_repair_trailer = NULL;
xref->unsaved_sigs = NULL;
xref->unsaved_sigs_end = NULL;
sub->next = NULL;
sub->len = xref->num_objects;
sub->start = 0;
sub->table = new_table;
doc->num_xref_sections++;
doc->num_incremental_sections++;
}
fz_catch(ctx)
{
fz_free(ctx, new_table);
pdf_drop_obj(ctx, trailer);
fz_rethrow(ctx);
}
/* Update the xref_index */
for (i = 0; i < doc->max_xref_len; i++)
{
doc->xref_index[i]++;
}
}
}
| DoS | 0 | static void ensure_incremental_xref(fz_context *ctx, pdf_document *doc)
{
/* If there are as yet no incremental sections, or if the most recent
* one has been used to sign a signature field, then we need a new one.
* After a signing, any further document changes require a new increment */
if ((doc->num_incremental_sections == 0 || doc->xref_sections[0].unsaved_sigs != NULL)
&& !doc->disallow_new_increments)
{
pdf_xref *xref = &doc->xref_sections[0];
pdf_xref *pxref;
pdf_xref_entry *new_table = fz_calloc(ctx, xref->num_objects, sizeof(pdf_xref_entry));
pdf_xref_subsec *sub;
pdf_obj *trailer = NULL;
int i;
fz_var(trailer);
fz_try(ctx)
{
sub = fz_malloc_struct(ctx, pdf_xref_subsec);
trailer = xref->trailer ? pdf_copy_dict(ctx, xref->trailer) : NULL;
doc->xref_sections = fz_resize_array(ctx, doc->xref_sections, doc->num_xref_sections + 1, sizeof(pdf_xref));
xref = &doc->xref_sections[0];
pxref = &doc->xref_sections[1];
memmove(pxref, xref, doc->num_xref_sections * sizeof(pdf_xref));
/* xref->num_objects is already correct */
xref->subsec = sub;
xref->trailer = trailer;
xref->pre_repair_trailer = NULL;
xref->unsaved_sigs = NULL;
xref->unsaved_sigs_end = NULL;
sub->next = NULL;
sub->len = xref->num_objects;
sub->start = 0;
sub->table = new_table;
doc->num_xref_sections++;
doc->num_incremental_sections++;
}
fz_catch(ctx)
{
fz_free(ctx, new_table);
pdf_drop_obj(ctx, trailer);
fz_rethrow(ctx);
}
/* Update the xref_index */
for (i = 0; i < doc->max_xref_len; i++)
{
doc->xref_index[i]++;
}
}
}
| @@ -1620,6 +1620,12 @@ pdf_drop_document_imp(fz_context *ctx, pdf_document *doc)
pdf_drop_resource_tables(ctx, doc);
+ for (i = 0; i < doc->orphans_count; i++)
+ {
+ pdf_drop_obj(ctx, doc->orphans[i]);
+ }
+ fz_free(ctx, doc->orphans);
+
fz_free(ctx, doc);
}
fz_always(ctx) | CWE-416 | null | null |
11,134 | ensure_solid_xref(fz_context *ctx, pdf_document *doc, int num, int which)
{
pdf_xref *xref = &doc->xref_sections[which];
pdf_xref_subsec *sub = xref->subsec;
pdf_xref_subsec *new_sub;
if (num < xref->num_objects)
num = xref->num_objects;
if (sub != NULL && sub->next == NULL && sub->start == 0 && sub->len >= num)
return;
new_sub = fz_malloc_struct(ctx, pdf_xref_subsec);
fz_try(ctx)
{
new_sub->table = fz_calloc(ctx, num, sizeof(pdf_xref_entry));
new_sub->start = 0;
new_sub->len = num;
new_sub->next = NULL;
}
fz_catch(ctx)
{
fz_free(ctx, new_sub);
fz_rethrow(ctx);
}
/* Move objects over to the new subsection and destroy the old
* ones */
sub = xref->subsec;
while (sub != NULL)
{
pdf_xref_subsec *next = sub->next;
int i;
for (i = 0; i < sub->len; i++)
{
new_sub->table[i+sub->start] = sub->table[i];
}
fz_free(ctx, sub->table);
fz_free(ctx, sub);
sub = next;
}
xref->num_objects = num;
xref->subsec = new_sub;
if (doc->max_xref_len < num)
extend_xref_index(ctx, doc, num);
}
| DoS | 0 | ensure_solid_xref(fz_context *ctx, pdf_document *doc, int num, int which)
{
pdf_xref *xref = &doc->xref_sections[which];
pdf_xref_subsec *sub = xref->subsec;
pdf_xref_subsec *new_sub;
if (num < xref->num_objects)
num = xref->num_objects;
if (sub != NULL && sub->next == NULL && sub->start == 0 && sub->len >= num)
return;
new_sub = fz_malloc_struct(ctx, pdf_xref_subsec);
fz_try(ctx)
{
new_sub->table = fz_calloc(ctx, num, sizeof(pdf_xref_entry));
new_sub->start = 0;
new_sub->len = num;
new_sub->next = NULL;
}
fz_catch(ctx)
{
fz_free(ctx, new_sub);
fz_rethrow(ctx);
}
/* Move objects over to the new subsection and destroy the old
* ones */
sub = xref->subsec;
while (sub != NULL)
{
pdf_xref_subsec *next = sub->next;
int i;
for (i = 0; i < sub->len; i++)
{
new_sub->table[i+sub->start] = sub->table[i];
}
fz_free(ctx, sub->table);
fz_free(ctx, sub);
sub = next;
}
xref->num_objects = num;
xref->subsec = new_sub;
if (doc->max_xref_len < num)
extend_xref_index(ctx, doc, num);
}
| @@ -1620,6 +1620,12 @@ pdf_drop_document_imp(fz_context *ctx, pdf_document *doc)
pdf_drop_resource_tables(ctx, doc);
+ for (i = 0; i < doc->orphans_count; i++)
+ {
+ pdf_drop_obj(ctx, doc->orphans[i]);
+ }
+ fz_free(ctx, doc->orphans);
+
fz_free(ctx, doc);
}
fz_always(ctx) | CWE-416 | null | null |
11,135 | extend_xref_index(fz_context *ctx, pdf_document *doc, int newlen)
{
int i;
doc->xref_index = fz_resize_array(ctx, doc->xref_index, newlen, sizeof(int));
for (i = doc->max_xref_len; i < newlen; i++)
{
doc->xref_index[i] = 0;
}
doc->max_xref_len = newlen;
}
| DoS | 0 | extend_xref_index(fz_context *ctx, pdf_document *doc, int newlen)
{
int i;
doc->xref_index = fz_resize_array(ctx, doc->xref_index, newlen, sizeof(int));
for (i = doc->max_xref_len; i < newlen; i++)
{
doc->xref_index[i] = 0;
}
doc->max_xref_len = newlen;
}
| @@ -1620,6 +1620,12 @@ pdf_drop_document_imp(fz_context *ctx, pdf_document *doc)
pdf_drop_resource_tables(ctx, doc);
+ for (i = 0; i < doc->orphans_count; i++)
+ {
+ pdf_drop_obj(ctx, doc->orphans[i]);
+ }
+ fz_free(ctx, doc->orphans);
+
fz_free(ctx, doc);
}
fz_always(ctx) | CWE-416 | null | null |
11,136 | fz_skip_space(fz_context *ctx, fz_stream *stm)
{
do
{
int c = fz_peek_byte(ctx, stm);
if (c > 32 && c != EOF)
return;
(void)fz_read_byte(ctx, stm);
}
while (1);
}
| DoS | 0 | fz_skip_space(fz_context *ctx, fz_stream *stm)
{
do
{
int c = fz_peek_byte(ctx, stm);
if (c > 32 && c != EOF)
return;
(void)fz_read_byte(ctx, stm);
}
while (1);
}
| @@ -1620,6 +1620,12 @@ pdf_drop_document_imp(fz_context *ctx, pdf_document *doc)
pdf_drop_resource_tables(ctx, doc);
+ for (i = 0; i < doc->orphans_count; i++)
+ {
+ pdf_drop_obj(ctx, doc->orphans[i]);
+ }
+ fz_free(ctx, doc->orphans);
+
fz_free(ctx, doc);
}
fz_always(ctx) | CWE-416 | null | null |
11,137 | static int fz_skip_string(fz_context *ctx, fz_stream *stm, const char *str)
{
while (*str)
{
int c = fz_peek_byte(ctx, stm);
if (c == EOF || c != *str++)
return 1;
(void)fz_read_byte(ctx, stm);
}
return 0;
}
| DoS | 0 | static int fz_skip_string(fz_context *ctx, fz_stream *stm, const char *str)
{
while (*str)
{
int c = fz_peek_byte(ctx, stm);
if (c == EOF || c != *str++)
return 1;
(void)fz_read_byte(ctx, stm);
}
return 0;
}
| @@ -1620,6 +1620,12 @@ pdf_drop_document_imp(fz_context *ctx, pdf_document *doc)
pdf_drop_resource_tables(ctx, doc);
+ for (i = 0; i < doc->orphans_count; i++)
+ {
+ pdf_drop_obj(ctx, doc->orphans[i]);
+ }
+ fz_free(ctx, doc->orphans);
+
fz_free(ctx, doc);
}
fz_always(ctx) | CWE-416 | null | null |
11,138 | static inline int iswhite(int ch)
{
return
ch == '\000' || ch == '\011' || ch == '\012' ||
ch == '\014' || ch == '\015' || ch == '\040';
}
| DoS | 0 | static inline int iswhite(int ch)
{
return
ch == '\000' || ch == '\011' || ch == '\012' ||
ch == '\014' || ch == '\015' || ch == '\040';
}
| @@ -1620,6 +1620,12 @@ pdf_drop_document_imp(fz_context *ctx, pdf_document *doc)
pdf_drop_resource_tables(ctx, doc);
+ for (i = 0; i < doc->orphans_count; i++)
+ {
+ pdf_drop_obj(ctx, doc->orphans[i]);
+ }
+ fz_free(ctx, doc->orphans);
+
fz_free(ctx, doc);
}
fz_always(ctx) | CWE-416 | null | null |
11,139 | int do_dtls1_write(SSL *s, int type, const unsigned char *buf,
unsigned int len, int create_empty_fragment)
{
unsigned char *p, *pseq;
int i, mac_size, clear = 0;
int prefix_len = 0;
int eivlen;
SSL3_RECORD wr;
SSL3_BUFFER *wb;
SSL_SESSION *sess;
wb = &s->rlayer.wbuf[0];
/*
* first check if there is a SSL3_BUFFER still being written out. This
* will happen with non blocking IO
*/
if (SSL3_BUFFER_get_left(wb) != 0) {
OPENSSL_assert(0); /* XDTLS: want to see if we ever get here */
return (ssl3_write_pending(s, type, buf, len));
}
/* If we have an alert to send, lets send it */
if (s->s3->alert_dispatch) {
i = s->method->ssl_dispatch_alert(s);
if (i <= 0)
return (i);
/* if it went, fall through and send more stuff */
}
if (len == 0 && !create_empty_fragment)
return 0;
sess = s->session;
if ((sess == NULL) ||
(s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL))
clear = 1;
if (clear)
mac_size = 0;
else {
mac_size = EVP_MD_CTX_size(s->write_hash);
if (mac_size < 0)
goto err;
}
p = SSL3_BUFFER_get_buf(wb) + prefix_len;
/* write the header */
*(p++) = type & 0xff;
SSL3_RECORD_set_type(&wr, type);
/*
* Special case: for hello verify request, client version 1.0 and we
* haven't decided which version to use yet send back using version 1.0
* header: otherwise some clients will ignore it.
*/
if (s->method->version == DTLS_ANY_VERSION &&
s->max_proto_version != DTLS1_BAD_VER) {
*(p++) = DTLS1_VERSION >> 8;
*(p++) = DTLS1_VERSION & 0xff;
} else {
*(p++) = s->version >> 8;
*(p++) = s->version & 0xff;
}
/* field where we are to write out packet epoch, seq num and len */
pseq = p;
p += 10;
/* Explicit IV length, block ciphers appropriate version flag */
if (s->enc_write_ctx) {
int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);
if (mode == EVP_CIPH_CBC_MODE) {
eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);
if (eivlen <= 1)
eivlen = 0;
}
/* Need explicit part of IV for GCM mode */
else if (mode == EVP_CIPH_GCM_MODE)
eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;
else if (mode == EVP_CIPH_CCM_MODE)
eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;
else
eivlen = 0;
} else
eivlen = 0;
/* lets setup the record stuff. */
SSL3_RECORD_set_data(&wr, p + eivlen); /* make room for IV in case of CBC */
SSL3_RECORD_set_length(&wr, (int)len);
SSL3_RECORD_set_input(&wr, (unsigned char *)buf);
/*
* we now 'read' from wr.input, wr.length bytes into wr.data
*/
/* first we compress */
if (s->compress != NULL) {
if (!ssl3_do_compress(s, &wr)) {
SSLerr(SSL_F_DO_DTLS1_WRITE, SSL_R_COMPRESSION_FAILURE);
goto err;
}
} else {
memcpy(SSL3_RECORD_get_data(&wr), SSL3_RECORD_get_input(&wr),
SSL3_RECORD_get_length(&wr));
SSL3_RECORD_reset_input(&wr);
}
/*
* we should still have the output to wr.data and the input from
* wr.input. Length should be wr.length. wr.data still points in the
* wb->buf
*/
if (mac_size != 0) {
if (s->method->ssl3_enc->mac(s, &wr,
&(p[SSL3_RECORD_get_length(&wr) + eivlen]),
1) < 0)
goto err;
SSL3_RECORD_add_length(&wr, mac_size);
}
/* this is true regardless of mac size */
SSL3_RECORD_set_data(&wr, p);
SSL3_RECORD_reset_input(&wr);
if (eivlen)
SSL3_RECORD_add_length(&wr, eivlen);
if (s->method->ssl3_enc->enc(s, &wr, 1, 1) < 1)
goto err;
/* record length after mac and block padding */
/*
* if (type == SSL3_RT_APPLICATION_DATA || (type == SSL3_RT_ALERT && !
* SSL_in_init(s)))
*/
/* there's only one epoch between handshake and app data */
s2n(s->rlayer.d->w_epoch, pseq);
/* XDTLS: ?? */
/*
* else s2n(s->d1->handshake_epoch, pseq);
*/
memcpy(pseq, &(s->rlayer.write_sequence[2]), 6);
pseq += 6;
s2n(SSL3_RECORD_get_length(&wr), pseq);
if (s->msg_callback)
s->msg_callback(1, 0, SSL3_RT_HEADER, pseq - DTLS1_RT_HEADER_LENGTH,
DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);
/*
* we should now have wr.data pointing to the encrypted data, which is
* wr->length long
*/
SSL3_RECORD_set_type(&wr, type); /* not needed but helps for debugging */
SSL3_RECORD_add_length(&wr, DTLS1_RT_HEADER_LENGTH);
ssl3_record_sequence_update(&(s->rlayer.write_sequence[0]));
if (create_empty_fragment) {
/*
* we are in a recursive call; just return the length, don't write
* out anything here
*/
return wr.length;
}
/* now let's set up wb */
SSL3_BUFFER_set_left(wb, prefix_len + SSL3_RECORD_get_length(&wr));
SSL3_BUFFER_set_offset(wb, 0);
/*
* memorize arguments so that ssl3_write_pending can detect bad write
* retries later
*/
s->rlayer.wpend_tot = len;
s->rlayer.wpend_buf = buf;
s->rlayer.wpend_type = type;
s->rlayer.wpend_ret = len;
/* we now just need to write the buffer */
return ssl3_write_pending(s, type, buf, len);
err:
return -1;
}
| DoS | 0 | int do_dtls1_write(SSL *s, int type, const unsigned char *buf,
unsigned int len, int create_empty_fragment)
{
unsigned char *p, *pseq;
int i, mac_size, clear = 0;
int prefix_len = 0;
int eivlen;
SSL3_RECORD wr;
SSL3_BUFFER *wb;
SSL_SESSION *sess;
wb = &s->rlayer.wbuf[0];
/*
* first check if there is a SSL3_BUFFER still being written out. This
* will happen with non blocking IO
*/
if (SSL3_BUFFER_get_left(wb) != 0) {
OPENSSL_assert(0); /* XDTLS: want to see if we ever get here */
return (ssl3_write_pending(s, type, buf, len));
}
/* If we have an alert to send, lets send it */
if (s->s3->alert_dispatch) {
i = s->method->ssl_dispatch_alert(s);
if (i <= 0)
return (i);
/* if it went, fall through and send more stuff */
}
if (len == 0 && !create_empty_fragment)
return 0;
sess = s->session;
if ((sess == NULL) ||
(s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL))
clear = 1;
if (clear)
mac_size = 0;
else {
mac_size = EVP_MD_CTX_size(s->write_hash);
if (mac_size < 0)
goto err;
}
p = SSL3_BUFFER_get_buf(wb) + prefix_len;
/* write the header */
*(p++) = type & 0xff;
SSL3_RECORD_set_type(&wr, type);
/*
* Special case: for hello verify request, client version 1.0 and we
* haven't decided which version to use yet send back using version 1.0
* header: otherwise some clients will ignore it.
*/
if (s->method->version == DTLS_ANY_VERSION &&
s->max_proto_version != DTLS1_BAD_VER) {
*(p++) = DTLS1_VERSION >> 8;
*(p++) = DTLS1_VERSION & 0xff;
} else {
*(p++) = s->version >> 8;
*(p++) = s->version & 0xff;
}
/* field where we are to write out packet epoch, seq num and len */
pseq = p;
p += 10;
/* Explicit IV length, block ciphers appropriate version flag */
if (s->enc_write_ctx) {
int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);
if (mode == EVP_CIPH_CBC_MODE) {
eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);
if (eivlen <= 1)
eivlen = 0;
}
/* Need explicit part of IV for GCM mode */
else if (mode == EVP_CIPH_GCM_MODE)
eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;
else if (mode == EVP_CIPH_CCM_MODE)
eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;
else
eivlen = 0;
} else
eivlen = 0;
/* lets setup the record stuff. */
SSL3_RECORD_set_data(&wr, p + eivlen); /* make room for IV in case of CBC */
SSL3_RECORD_set_length(&wr, (int)len);
SSL3_RECORD_set_input(&wr, (unsigned char *)buf);
/*
* we now 'read' from wr.input, wr.length bytes into wr.data
*/
/* first we compress */
if (s->compress != NULL) {
if (!ssl3_do_compress(s, &wr)) {
SSLerr(SSL_F_DO_DTLS1_WRITE, SSL_R_COMPRESSION_FAILURE);
goto err;
}
} else {
memcpy(SSL3_RECORD_get_data(&wr), SSL3_RECORD_get_input(&wr),
SSL3_RECORD_get_length(&wr));
SSL3_RECORD_reset_input(&wr);
}
/*
* we should still have the output to wr.data and the input from
* wr.input. Length should be wr.length. wr.data still points in the
* wb->buf
*/
if (mac_size != 0) {
if (s->method->ssl3_enc->mac(s, &wr,
&(p[SSL3_RECORD_get_length(&wr) + eivlen]),
1) < 0)
goto err;
SSL3_RECORD_add_length(&wr, mac_size);
}
/* this is true regardless of mac size */
SSL3_RECORD_set_data(&wr, p);
SSL3_RECORD_reset_input(&wr);
if (eivlen)
SSL3_RECORD_add_length(&wr, eivlen);
if (s->method->ssl3_enc->enc(s, &wr, 1, 1) < 1)
goto err;
/* record length after mac and block padding */
/*
* if (type == SSL3_RT_APPLICATION_DATA || (type == SSL3_RT_ALERT && !
* SSL_in_init(s)))
*/
/* there's only one epoch between handshake and app data */
s2n(s->rlayer.d->w_epoch, pseq);
/* XDTLS: ?? */
/*
* else s2n(s->d1->handshake_epoch, pseq);
*/
memcpy(pseq, &(s->rlayer.write_sequence[2]), 6);
pseq += 6;
s2n(SSL3_RECORD_get_length(&wr), pseq);
if (s->msg_callback)
s->msg_callback(1, 0, SSL3_RT_HEADER, pseq - DTLS1_RT_HEADER_LENGTH,
DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);
/*
* we should now have wr.data pointing to the encrypted data, which is
* wr->length long
*/
SSL3_RECORD_set_type(&wr, type); /* not needed but helps for debugging */
SSL3_RECORD_add_length(&wr, DTLS1_RT_HEADER_LENGTH);
ssl3_record_sequence_update(&(s->rlayer.write_sequence[0]));
if (create_empty_fragment) {
/*
* we are in a recursive call; just return the length, don't write
* out anything here
*/
return wr.length;
}
/* now let's set up wb */
SSL3_BUFFER_set_left(wb, prefix_len + SSL3_RECORD_get_length(&wr));
SSL3_BUFFER_set_offset(wb, 0);
/*
* memorize arguments so that ssl3_write_pending can detect bad write
* retries later
*/
s->rlayer.wpend_tot = len;
s->rlayer.wpend_buf = buf;
s->rlayer.wpend_type = type;
s->rlayer.wpend_ret = len;
/* we now just need to write the buffer */
return ssl3_write_pending(s, type, buf, len);
err:
return -1;
}
| @@ -443,6 +443,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
}
}
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -722,6 +730,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
#ifndef OPENSSL_NO_SCTP
/* | CWE-400 | null | null |
11,140 | DTLS1_BITMAP *dtls1_get_bitmap(SSL *s, SSL3_RECORD *rr,
unsigned int *is_next_epoch)
{
*is_next_epoch = 0;
/* In current epoch, accept HM, CCS, DATA, & ALERT */
if (rr->epoch == s->rlayer.d->r_epoch)
return &s->rlayer.d->bitmap;
/*
* Only HM and ALERT messages can be from the next epoch and only if we
* have already processed all of the unprocessed records from the last
* epoch
*/
else if (rr->epoch == (unsigned long)(s->rlayer.d->r_epoch + 1) &&
s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch &&
(rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) {
*is_next_epoch = 1;
return &s->rlayer.d->next_bitmap;
}
return NULL;
}
| DoS | 0 | DTLS1_BITMAP *dtls1_get_bitmap(SSL *s, SSL3_RECORD *rr,
unsigned int *is_next_epoch)
{
*is_next_epoch = 0;
/* In current epoch, accept HM, CCS, DATA, & ALERT */
if (rr->epoch == s->rlayer.d->r_epoch)
return &s->rlayer.d->bitmap;
/*
* Only HM and ALERT messages can be from the next epoch and only if we
* have already processed all of the unprocessed records from the last
* epoch
*/
else if (rr->epoch == (unsigned long)(s->rlayer.d->r_epoch + 1) &&
s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch &&
(rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) {
*is_next_epoch = 1;
return &s->rlayer.d->next_bitmap;
}
return NULL;
}
| @@ -443,6 +443,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
}
}
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -722,6 +730,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
#ifndef OPENSSL_NO_SCTP
/* | CWE-400 | null | null |
11,141 | void dtls1_reset_seq_numbers(SSL *s, int rw)
{
unsigned char *seq;
unsigned int seq_bytes = sizeof(s->rlayer.read_sequence);
if (rw & SSL3_CC_READ) {
seq = s->rlayer.read_sequence;
s->rlayer.d->r_epoch++;
memcpy(&s->rlayer.d->bitmap, &s->rlayer.d->next_bitmap,
sizeof(s->rlayer.d->bitmap));
memset(&s->rlayer.d->next_bitmap, 0, sizeof(s->rlayer.d->next_bitmap));
/*
* We must not use any buffered messages received from the previous
* epoch
*/
dtls1_clear_received_buffer(s);
} else {
seq = s->rlayer.write_sequence;
memcpy(s->rlayer.d->last_write_sequence, seq,
sizeof(s->rlayer.write_sequence));
s->rlayer.d->w_epoch++;
}
memset(seq, 0, seq_bytes);
}
| DoS | 0 | void dtls1_reset_seq_numbers(SSL *s, int rw)
{
unsigned char *seq;
unsigned int seq_bytes = sizeof(s->rlayer.read_sequence);
if (rw & SSL3_CC_READ) {
seq = s->rlayer.read_sequence;
s->rlayer.d->r_epoch++;
memcpy(&s->rlayer.d->bitmap, &s->rlayer.d->next_bitmap,
sizeof(s->rlayer.d->bitmap));
memset(&s->rlayer.d->next_bitmap, 0, sizeof(s->rlayer.d->next_bitmap));
/*
* We must not use any buffered messages received from the previous
* epoch
*/
dtls1_clear_received_buffer(s);
} else {
seq = s->rlayer.write_sequence;
memcpy(s->rlayer.d->last_write_sequence, seq,
sizeof(s->rlayer.write_sequence));
s->rlayer.d->w_epoch++;
}
memset(seq, 0, seq_bytes);
}
| @@ -443,6 +443,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
}
}
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -722,6 +730,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
#ifndef OPENSSL_NO_SCTP
/* | CWE-400 | null | null |
11,142 | static int have_handshake_fragment(SSL *s, int type, unsigned char *buf,
int len)
{
if ((type == SSL3_RT_HANDSHAKE)
&& (s->rlayer.d->handshake_fragment_len > 0))
/* (partially) satisfy request from storage */
{
unsigned char *src = s->rlayer.d->handshake_fragment;
unsigned char *dst = buf;
unsigned int k, n;
/* peek == 0 */
n = 0;
while ((len > 0) && (s->rlayer.d->handshake_fragment_len > 0)) {
*dst++ = *src++;
len--;
s->rlayer.d->handshake_fragment_len--;
n++;
}
/* move any remaining fragment bytes: */
for (k = 0; k < s->rlayer.d->handshake_fragment_len; k++)
s->rlayer.d->handshake_fragment[k] = *src++;
return n;
}
return 0;
}
| DoS | 0 | static int have_handshake_fragment(SSL *s, int type, unsigned char *buf,
int len)
{
if ((type == SSL3_RT_HANDSHAKE)
&& (s->rlayer.d->handshake_fragment_len > 0))
/* (partially) satisfy request from storage */
{
unsigned char *src = s->rlayer.d->handshake_fragment;
unsigned char *dst = buf;
unsigned int k, n;
/* peek == 0 */
n = 0;
while ((len > 0) && (s->rlayer.d->handshake_fragment_len > 0)) {
*dst++ = *src++;
len--;
s->rlayer.d->handshake_fragment_len--;
n++;
}
/* move any remaining fragment bytes: */
for (k = 0; k < s->rlayer.d->handshake_fragment_len; k++)
s->rlayer.d->handshake_fragment[k] = *src++;
return n;
}
return 0;
}
| @@ -443,6 +443,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
}
}
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -722,6 +730,14 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
#ifndef OPENSSL_NO_SCTP
/* | CWE-400 | null | null |
11,143 | void RECORD_LAYER_clear(RECORD_LAYER *rl)
{
unsigned int pipes;
rl->rstate = SSL_ST_READ_HEADER;
/*
* Do I need to clear read_ahead? As far as I can tell read_ahead did not
* previously get reset by SSL_clear...so I'll keep it that way..but is
* that right?
*/
rl->packet = NULL;
rl->packet_length = 0;
rl->wnum = 0;
memset(rl->alert_fragment, 0, sizeof(rl->alert_fragment));
rl->alert_fragment_len = 0;
memset(rl->handshake_fragment, 0, sizeof(rl->handshake_fragment));
rl->handshake_fragment_len = 0;
rl->wpend_tot = 0;
rl->wpend_type = 0;
rl->wpend_ret = 0;
rl->wpend_buf = NULL;
SSL3_BUFFER_clear(&rl->rbuf);
for (pipes = 0; pipes < rl->numwpipes; pipes++)
SSL3_BUFFER_clear(&rl->wbuf[pipes]);
rl->numwpipes = 0;
rl->numrpipes = 0;
SSL3_RECORD_clear(rl->rrec, SSL_MAX_PIPELINES);
RECORD_LAYER_reset_read_sequence(rl);
RECORD_LAYER_reset_write_sequence(rl);
if (rl->d)
DTLS_RECORD_LAYER_clear(rl);
}
| DoS | 0 | void RECORD_LAYER_clear(RECORD_LAYER *rl)
{
unsigned int pipes;
rl->rstate = SSL_ST_READ_HEADER;
/*
* Do I need to clear read_ahead? As far as I can tell read_ahead did not
* previously get reset by SSL_clear...so I'll keep it that way..but is
* that right?
*/
rl->packet = NULL;
rl->packet_length = 0;
rl->wnum = 0;
memset(rl->alert_fragment, 0, sizeof(rl->alert_fragment));
rl->alert_fragment_len = 0;
memset(rl->handshake_fragment, 0, sizeof(rl->handshake_fragment));
rl->handshake_fragment_len = 0;
rl->wpend_tot = 0;
rl->wpend_type = 0;
rl->wpend_ret = 0;
rl->wpend_buf = NULL;
SSL3_BUFFER_clear(&rl->rbuf);
for (pipes = 0; pipes < rl->numwpipes; pipes++)
SSL3_BUFFER_clear(&rl->wbuf[pipes]);
rl->numwpipes = 0;
rl->numrpipes = 0;
SSL3_RECORD_clear(rl->rrec, SSL_MAX_PIPELINES);
RECORD_LAYER_reset_read_sequence(rl);
RECORD_LAYER_reset_write_sequence(rl);
if (rl->d)
DTLS_RECORD_LAYER_clear(rl);
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,144 | void RECORD_LAYER_init(RECORD_LAYER *rl, SSL *s)
{
rl->s = s;
RECORD_LAYER_set_first_record(&s->rlayer);
SSL3_RECORD_clear(rl->rrec, SSL_MAX_PIPELINES);
}
| DoS | 0 | void RECORD_LAYER_init(RECORD_LAYER *rl, SSL *s)
{
rl->s = s;
RECORD_LAYER_set_first_record(&s->rlayer);
SSL3_RECORD_clear(rl->rrec, SSL_MAX_PIPELINES);
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,145 | int RECORD_LAYER_read_pending(const RECORD_LAYER *rl)
{
return SSL3_BUFFER_get_left(&rl->rbuf) != 0;
}
| DoS | 0 | int RECORD_LAYER_read_pending(const RECORD_LAYER *rl)
{
return SSL3_BUFFER_get_left(&rl->rbuf) != 0;
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,146 | void RECORD_LAYER_release(RECORD_LAYER *rl)
{
if (SSL3_BUFFER_is_initialised(&rl->rbuf))
ssl3_release_read_buffer(rl->s);
if (rl->numwpipes > 0)
ssl3_release_write_buffer(rl->s);
SSL3_RECORD_release(rl->rrec, SSL_MAX_PIPELINES);
}
| DoS | 0 | void RECORD_LAYER_release(RECORD_LAYER *rl)
{
if (SSL3_BUFFER_is_initialised(&rl->rbuf))
ssl3_release_read_buffer(rl->s);
if (rl->numwpipes > 0)
ssl3_release_write_buffer(rl->s);
SSL3_RECORD_release(rl->rrec, SSL_MAX_PIPELINES);
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,147 | void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl)
{
memset(rl->read_sequence, 0, sizeof(rl->read_sequence));
}
| DoS | 0 | void RECORD_LAYER_reset_read_sequence(RECORD_LAYER *rl)
{
memset(rl->read_sequence, 0, sizeof(rl->read_sequence));
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,148 | int RECORD_LAYER_set_data(RECORD_LAYER *rl, const unsigned char *buf, int len)
{
rl->packet_length = len;
if (len != 0) {
rl->rstate = SSL_ST_READ_HEADER;
if (!SSL3_BUFFER_is_initialised(&rl->rbuf))
if (!ssl3_setup_read_buffer(rl->s))
return 0;
}
rl->packet = SSL3_BUFFER_get_buf(&rl->rbuf);
SSL3_BUFFER_set_data(&rl->rbuf, buf, len);
return 1;
}
| DoS | 0 | int RECORD_LAYER_set_data(RECORD_LAYER *rl, const unsigned char *buf, int len)
{
rl->packet_length = len;
if (len != 0) {
rl->rstate = SSL_ST_READ_HEADER;
if (!SSL3_BUFFER_is_initialised(&rl->rbuf))
if (!ssl3_setup_read_buffer(rl->s))
return 0;
}
rl->packet = SSL3_BUFFER_get_buf(&rl->rbuf);
SSL3_BUFFER_set_data(&rl->rbuf, buf, len);
return 1;
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,149 | int RECORD_LAYER_write_pending(const RECORD_LAYER *rl)
{
return (rl->numwpipes > 0)
&& SSL3_BUFFER_get_left(&rl->wbuf[rl->numwpipes - 1]) != 0;
}
| DoS | 0 | int RECORD_LAYER_write_pending(const RECORD_LAYER *rl)
{
return (rl->numwpipes > 0)
&& SSL3_BUFFER_get_left(&rl->wbuf[rl->numwpipes - 1]) != 0;
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,150 | void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len)
{
ctx->default_read_buf_len = len;
}
| DoS | 0 | void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len)
{
ctx->default_read_buf_len = len;
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,151 | const char *SSL_rstate_string_long(const SSL *s)
{
switch (s->rlayer.rstate) {
case SSL_ST_READ_HEADER:
return "read header";
case SSL_ST_READ_BODY:
return "read body";
case SSL_ST_READ_DONE:
return "read done";
default:
return "unknown";
}
}
| DoS | 0 | const char *SSL_rstate_string_long(const SSL *s)
{
switch (s->rlayer.rstate) {
case SSL_ST_READ_HEADER:
return "read header";
case SSL_ST_READ_BODY:
return "read body";
case SSL_ST_READ_DONE:
return "read done";
default:
return "unknown";
}
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,152 | void SSL_set_default_read_buffer_len(SSL *s, size_t len)
{
SSL3_BUFFER_set_default_len(RECORD_LAYER_get_rbuf(&s->rlayer), len);
}
| DoS | 0 | void SSL_set_default_read_buffer_len(SSL *s, size_t len)
{
SSL3_BUFFER_set_default_len(RECORD_LAYER_get_rbuf(&s->rlayer), len);
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,153 | int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
unsigned int *pipelens, unsigned int numpipes,
int create_empty_fragment)
{
unsigned char *outbuf[SSL_MAX_PIPELINES], *plen[SSL_MAX_PIPELINES];
SSL3_RECORD wr[SSL_MAX_PIPELINES];
int i, mac_size, clear = 0;
int prefix_len = 0;
int eivlen;
size_t align = 0;
SSL3_BUFFER *wb;
SSL_SESSION *sess;
unsigned int totlen = 0;
unsigned int j;
for (j = 0; j < numpipes; j++)
totlen += pipelens[j];
/*
* first check if there is a SSL3_BUFFER still being written out. This
* will happen with non blocking IO
*/
if (RECORD_LAYER_write_pending(&s->rlayer))
return (ssl3_write_pending(s, type, buf, totlen));
/* If we have an alert to send, lets send it */
if (s->s3->alert_dispatch) {
i = s->method->ssl_dispatch_alert(s);
if (i <= 0)
return (i);
/* if it went, fall through and send more stuff */
}
if (s->rlayer.numwpipes < numpipes)
if (!ssl3_setup_write_buffer(s, numpipes, 0))
return -1;
if (totlen == 0 && !create_empty_fragment)
return 0;
sess = s->session;
if ((sess == NULL) ||
(s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL)) {
clear = s->enc_write_ctx ? 0 : 1; /* must be AEAD cipher */
mac_size = 0;
} else {
mac_size = EVP_MD_CTX_size(s->write_hash);
if (mac_size < 0)
goto err;
}
/*
* 'create_empty_fragment' is true only when this function calls itself
*/
if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done) {
/*
* countermeasure against known-IV weakness in CBC ciphersuites (see
* http://www.openssl.org/~bodo/tls-cbc.txt)
*/
if (s->s3->need_empty_fragments && type == SSL3_RT_APPLICATION_DATA) {
/*
* recursive function call with 'create_empty_fragment' set; this
* prepares and buffers the data for an empty fragment (these
* 'prefix_len' bytes are sent out later together with the actual
* payload)
*/
unsigned int tmppipelen = 0;
prefix_len = do_ssl3_write(s, type, buf, &tmppipelen, 1, 1);
if (prefix_len <= 0)
goto err;
if (prefix_len >
(SSL3_RT_HEADER_LENGTH + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD)) {
/* insufficient space */
SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);
goto err;
}
}
s->s3->empty_fragment_done = 1;
}
if (create_empty_fragment) {
wb = &s->rlayer.wbuf[0];
#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
/*
* extra fragment would be couple of cipher blocks, which would be
* multiple of SSL3_ALIGN_PAYLOAD, so if we want to align the real
* payload, then we can just pretend we simply have two headers.
*/
align = (size_t)SSL3_BUFFER_get_buf(wb) + 2 * SSL3_RT_HEADER_LENGTH;
align = SSL3_ALIGN_PAYLOAD - 1 - ((align - 1) % SSL3_ALIGN_PAYLOAD);
#endif
outbuf[0] = SSL3_BUFFER_get_buf(wb) + align;
SSL3_BUFFER_set_offset(wb, align);
} else if (prefix_len) {
wb = &s->rlayer.wbuf[0];
outbuf[0] = SSL3_BUFFER_get_buf(wb) + SSL3_BUFFER_get_offset(wb)
+ prefix_len;
} else {
for (j = 0; j < numpipes; j++) {
wb = &s->rlayer.wbuf[j];
#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
align = (size_t)SSL3_BUFFER_get_buf(wb) + SSL3_RT_HEADER_LENGTH;
align = SSL3_ALIGN_PAYLOAD - 1 - ((align - 1) % SSL3_ALIGN_PAYLOAD);
#endif
outbuf[j] = SSL3_BUFFER_get_buf(wb) + align;
SSL3_BUFFER_set_offset(wb, align);
}
}
/* Explicit IV length, block ciphers appropriate version flag */
if (s->enc_write_ctx && SSL_USE_EXPLICIT_IV(s)) {
int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);
if (mode == EVP_CIPH_CBC_MODE) {
eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);
if (eivlen <= 1)
eivlen = 0;
}
/* Need explicit part of IV for GCM mode */
else if (mode == EVP_CIPH_GCM_MODE)
eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;
else if (mode == EVP_CIPH_CCM_MODE)
eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;
else
eivlen = 0;
} else
eivlen = 0;
totlen = 0;
/* Clear our SSL3_RECORD structures */
memset(wr, 0, sizeof wr);
for (j = 0; j < numpipes; j++) {
/* write the header */
*(outbuf[j]++) = type & 0xff;
SSL3_RECORD_set_type(&wr[j], type);
*(outbuf[j]++) = (s->version >> 8);
/*
* Some servers hang if initial client hello is larger than 256 bytes
* and record version number > TLS 1.0
*/
if (SSL_get_state(s) == TLS_ST_CW_CLNT_HELLO
&& !s->renegotiate && TLS1_get_version(s) > TLS1_VERSION)
*(outbuf[j]++) = 0x1;
else
*(outbuf[j]++) = s->version & 0xff;
/* field where we are to write out packet length */
plen[j] = outbuf[j];
outbuf[j] += 2;
/* lets setup the record stuff. */
SSL3_RECORD_set_data(&wr[j], outbuf[j] + eivlen);
SSL3_RECORD_set_length(&wr[j], (int)pipelens[j]);
SSL3_RECORD_set_input(&wr[j], (unsigned char *)&buf[totlen]);
totlen += pipelens[j];
/*
* we now 'read' from wr->input, wr->length bytes into wr->data
*/
/* first we compress */
if (s->compress != NULL) {
if (!ssl3_do_compress(s, &wr[j])) {
SSLerr(SSL_F_DO_SSL3_WRITE, SSL_R_COMPRESSION_FAILURE);
goto err;
}
} else {
memcpy(wr[j].data, wr[j].input, wr[j].length);
SSL3_RECORD_reset_input(&wr[j]);
}
/*
* we should still have the output to wr->data and the input from
* wr->input. Length should be wr->length. wr->data still points in the
* wb->buf
*/
if (!SSL_USE_ETM(s) && mac_size != 0) {
if (s->method->ssl3_enc->mac(s, &wr[j],
&(outbuf[j][wr[j].length + eivlen]),
1) < 0)
goto err;
SSL3_RECORD_add_length(&wr[j], mac_size);
}
SSL3_RECORD_set_data(&wr[j], outbuf[j]);
SSL3_RECORD_reset_input(&wr[j]);
if (eivlen) {
/*
* if (RAND_pseudo_bytes(p, eivlen) <= 0) goto err;
*/
SSL3_RECORD_add_length(&wr[j], eivlen);
}
}
if (s->method->ssl3_enc->enc(s, wr, numpipes, 1) < 1)
goto err;
for (j = 0; j < numpipes; j++) {
if (SSL_USE_ETM(s) && mac_size != 0) {
if (s->method->ssl3_enc->mac(s, &wr[j],
outbuf[j] + wr[j].length, 1) < 0)
goto err;
SSL3_RECORD_add_length(&wr[j], mac_size);
}
/* record length after mac and block padding */
s2n(SSL3_RECORD_get_length(&wr[j]), plen[j]);
if (s->msg_callback)
s->msg_callback(1, 0, SSL3_RT_HEADER, plen[j] - 5, 5, s,
s->msg_callback_arg);
/*
* we should now have wr->data pointing to the encrypted data, which is
* wr->length long
*/
SSL3_RECORD_set_type(&wr[j], type); /* not needed but helps for
* debugging */
SSL3_RECORD_add_length(&wr[j], SSL3_RT_HEADER_LENGTH);
if (create_empty_fragment) {
/*
* we are in a recursive call; just return the length, don't write
* out anything here
*/
if (j > 0) {
/* We should never be pipelining an empty fragment!! */
SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);
goto err;
}
return SSL3_RECORD_get_length(wr);
}
/* now let's set up wb */
SSL3_BUFFER_set_left(&s->rlayer.wbuf[j],
prefix_len + SSL3_RECORD_get_length(&wr[j]));
}
/*
* memorize arguments so that ssl3_write_pending can detect bad write
* retries later
*/
s->rlayer.wpend_tot = totlen;
s->rlayer.wpend_buf = buf;
s->rlayer.wpend_type = type;
s->rlayer.wpend_ret = totlen;
/* we now just need to write the buffer */
return ssl3_write_pending(s, type, buf, totlen);
err:
return -1;
}
| DoS | 0 | int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
unsigned int *pipelens, unsigned int numpipes,
int create_empty_fragment)
{
unsigned char *outbuf[SSL_MAX_PIPELINES], *plen[SSL_MAX_PIPELINES];
SSL3_RECORD wr[SSL_MAX_PIPELINES];
int i, mac_size, clear = 0;
int prefix_len = 0;
int eivlen;
size_t align = 0;
SSL3_BUFFER *wb;
SSL_SESSION *sess;
unsigned int totlen = 0;
unsigned int j;
for (j = 0; j < numpipes; j++)
totlen += pipelens[j];
/*
* first check if there is a SSL3_BUFFER still being written out. This
* will happen with non blocking IO
*/
if (RECORD_LAYER_write_pending(&s->rlayer))
return (ssl3_write_pending(s, type, buf, totlen));
/* If we have an alert to send, lets send it */
if (s->s3->alert_dispatch) {
i = s->method->ssl_dispatch_alert(s);
if (i <= 0)
return (i);
/* if it went, fall through and send more stuff */
}
if (s->rlayer.numwpipes < numpipes)
if (!ssl3_setup_write_buffer(s, numpipes, 0))
return -1;
if (totlen == 0 && !create_empty_fragment)
return 0;
sess = s->session;
if ((sess == NULL) ||
(s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL)) {
clear = s->enc_write_ctx ? 0 : 1; /* must be AEAD cipher */
mac_size = 0;
} else {
mac_size = EVP_MD_CTX_size(s->write_hash);
if (mac_size < 0)
goto err;
}
/*
* 'create_empty_fragment' is true only when this function calls itself
*/
if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done) {
/*
* countermeasure against known-IV weakness in CBC ciphersuites (see
* http://www.openssl.org/~bodo/tls-cbc.txt)
*/
if (s->s3->need_empty_fragments && type == SSL3_RT_APPLICATION_DATA) {
/*
* recursive function call with 'create_empty_fragment' set; this
* prepares and buffers the data for an empty fragment (these
* 'prefix_len' bytes are sent out later together with the actual
* payload)
*/
unsigned int tmppipelen = 0;
prefix_len = do_ssl3_write(s, type, buf, &tmppipelen, 1, 1);
if (prefix_len <= 0)
goto err;
if (prefix_len >
(SSL3_RT_HEADER_LENGTH + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD)) {
/* insufficient space */
SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);
goto err;
}
}
s->s3->empty_fragment_done = 1;
}
if (create_empty_fragment) {
wb = &s->rlayer.wbuf[0];
#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
/*
* extra fragment would be couple of cipher blocks, which would be
* multiple of SSL3_ALIGN_PAYLOAD, so if we want to align the real
* payload, then we can just pretend we simply have two headers.
*/
align = (size_t)SSL3_BUFFER_get_buf(wb) + 2 * SSL3_RT_HEADER_LENGTH;
align = SSL3_ALIGN_PAYLOAD - 1 - ((align - 1) % SSL3_ALIGN_PAYLOAD);
#endif
outbuf[0] = SSL3_BUFFER_get_buf(wb) + align;
SSL3_BUFFER_set_offset(wb, align);
} else if (prefix_len) {
wb = &s->rlayer.wbuf[0];
outbuf[0] = SSL3_BUFFER_get_buf(wb) + SSL3_BUFFER_get_offset(wb)
+ prefix_len;
} else {
for (j = 0; j < numpipes; j++) {
wb = &s->rlayer.wbuf[j];
#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0
align = (size_t)SSL3_BUFFER_get_buf(wb) + SSL3_RT_HEADER_LENGTH;
align = SSL3_ALIGN_PAYLOAD - 1 - ((align - 1) % SSL3_ALIGN_PAYLOAD);
#endif
outbuf[j] = SSL3_BUFFER_get_buf(wb) + align;
SSL3_BUFFER_set_offset(wb, align);
}
}
/* Explicit IV length, block ciphers appropriate version flag */
if (s->enc_write_ctx && SSL_USE_EXPLICIT_IV(s)) {
int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);
if (mode == EVP_CIPH_CBC_MODE) {
eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);
if (eivlen <= 1)
eivlen = 0;
}
/* Need explicit part of IV for GCM mode */
else if (mode == EVP_CIPH_GCM_MODE)
eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;
else if (mode == EVP_CIPH_CCM_MODE)
eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;
else
eivlen = 0;
} else
eivlen = 0;
totlen = 0;
/* Clear our SSL3_RECORD structures */
memset(wr, 0, sizeof wr);
for (j = 0; j < numpipes; j++) {
/* write the header */
*(outbuf[j]++) = type & 0xff;
SSL3_RECORD_set_type(&wr[j], type);
*(outbuf[j]++) = (s->version >> 8);
/*
* Some servers hang if initial client hello is larger than 256 bytes
* and record version number > TLS 1.0
*/
if (SSL_get_state(s) == TLS_ST_CW_CLNT_HELLO
&& !s->renegotiate && TLS1_get_version(s) > TLS1_VERSION)
*(outbuf[j]++) = 0x1;
else
*(outbuf[j]++) = s->version & 0xff;
/* field where we are to write out packet length */
plen[j] = outbuf[j];
outbuf[j] += 2;
/* lets setup the record stuff. */
SSL3_RECORD_set_data(&wr[j], outbuf[j] + eivlen);
SSL3_RECORD_set_length(&wr[j], (int)pipelens[j]);
SSL3_RECORD_set_input(&wr[j], (unsigned char *)&buf[totlen]);
totlen += pipelens[j];
/*
* we now 'read' from wr->input, wr->length bytes into wr->data
*/
/* first we compress */
if (s->compress != NULL) {
if (!ssl3_do_compress(s, &wr[j])) {
SSLerr(SSL_F_DO_SSL3_WRITE, SSL_R_COMPRESSION_FAILURE);
goto err;
}
} else {
memcpy(wr[j].data, wr[j].input, wr[j].length);
SSL3_RECORD_reset_input(&wr[j]);
}
/*
* we should still have the output to wr->data and the input from
* wr->input. Length should be wr->length. wr->data still points in the
* wb->buf
*/
if (!SSL_USE_ETM(s) && mac_size != 0) {
if (s->method->ssl3_enc->mac(s, &wr[j],
&(outbuf[j][wr[j].length + eivlen]),
1) < 0)
goto err;
SSL3_RECORD_add_length(&wr[j], mac_size);
}
SSL3_RECORD_set_data(&wr[j], outbuf[j]);
SSL3_RECORD_reset_input(&wr[j]);
if (eivlen) {
/*
* if (RAND_pseudo_bytes(p, eivlen) <= 0) goto err;
*/
SSL3_RECORD_add_length(&wr[j], eivlen);
}
}
if (s->method->ssl3_enc->enc(s, wr, numpipes, 1) < 1)
goto err;
for (j = 0; j < numpipes; j++) {
if (SSL_USE_ETM(s) && mac_size != 0) {
if (s->method->ssl3_enc->mac(s, &wr[j],
outbuf[j] + wr[j].length, 1) < 0)
goto err;
SSL3_RECORD_add_length(&wr[j], mac_size);
}
/* record length after mac and block padding */
s2n(SSL3_RECORD_get_length(&wr[j]), plen[j]);
if (s->msg_callback)
s->msg_callback(1, 0, SSL3_RT_HEADER, plen[j] - 5, 5, s,
s->msg_callback_arg);
/*
* we should now have wr->data pointing to the encrypted data, which is
* wr->length long
*/
SSL3_RECORD_set_type(&wr[j], type); /* not needed but helps for
* debugging */
SSL3_RECORD_add_length(&wr[j], SSL3_RT_HEADER_LENGTH);
if (create_empty_fragment) {
/*
* we are in a recursive call; just return the length, don't write
* out anything here
*/
if (j > 0) {
/* We should never be pipelining an empty fragment!! */
SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);
goto err;
}
return SSL3_RECORD_get_length(wr);
}
/* now let's set up wb */
SSL3_BUFFER_set_left(&s->rlayer.wbuf[j],
prefix_len + SSL3_RECORD_get_length(&wr[j]));
}
/*
* memorize arguments so that ssl3_write_pending can detect bad write
* retries later
*/
s->rlayer.wpend_tot = totlen;
s->rlayer.wpend_buf = buf;
s->rlayer.wpend_type = type;
s->rlayer.wpend_ret = totlen;
/* we now just need to write the buffer */
return ssl3_write_pending(s, type, buf, totlen);
err:
return -1;
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,154 | int ssl3_pending(const SSL *s)
{
unsigned int i;
int num = 0;
if (s->rlayer.rstate == SSL_ST_READ_BODY)
return 0;
for (i = 0; i < RECORD_LAYER_get_numrpipes(&s->rlayer); i++) {
if (SSL3_RECORD_get_type(&s->rlayer.rrec[i])
!= SSL3_RT_APPLICATION_DATA)
return 0;
num += SSL3_RECORD_get_length(&s->rlayer.rrec[i]);
}
return num;
}
| DoS | 0 | int ssl3_pending(const SSL *s)
{
unsigned int i;
int num = 0;
if (s->rlayer.rstate == SSL_ST_READ_BODY)
return 0;
for (i = 0; i < RECORD_LAYER_get_numrpipes(&s->rlayer); i++) {
if (SSL3_RECORD_get_type(&s->rlayer.rrec[i])
!= SSL3_RT_APPLICATION_DATA)
return 0;
num += SSL3_RECORD_get_length(&s->rlayer.rrec[i]);
}
return num;
}
| @@ -1063,6 +1063,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
} while (num_recs == 0);
rr = &rr[curr_rec];
+ /*
+ * Reset the count of consecutive warning alerts if we've got a non-empty
+ * record that isn't an alert.
+ */
+ if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
+ && SSL3_RECORD_get_length(rr) != 0)
+ s->rlayer.alert_count = 0;
+
/* we now have a packet which can be read and processed */
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
@@ -1333,6 +1341,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
if (alert_level == SSL3_AL_WARNING) {
s->s3->warn_alert = alert_descr;
SSL3_RECORD_set_read(rr);
+
+ s->rlayer.alert_count++;
+ if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
+ al = SSL_AD_UNEXPECTED_MESSAGE;
+ SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);
+ goto f_err;
+ }
+
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
return (0); | CWE-400 | null | null |
11,155 | dict_real_result(i_ctx_t *i_ctx_p, ref * pdict, const char *kstr, double val)
{
int code = 0;
ref *ignore;
if (dict_find_string(pdict, kstr, &ignore) > 0) {
ref rval;
check_dict_write(*pdict);
make_real(&rval, val);
code = idict_put_string(pdict, kstr, &rval);
}
return code;
}
| DoS Exec Code | 0 | dict_real_result(i_ctx_t *i_ctx_p, ref * pdict, const char *kstr, double val)
{
int code = 0;
ref *ignore;
if (dict_find_string(pdict, kstr, &ignore) > 0) {
ref rval;
check_dict_write(*pdict);
make_real(&rval, val);
code = idict_put_string(pdict, kstr, &rval);
}
return code;
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,156 | dict_spot_params(const ref * pdict, gs_spot_halftone * psp,
ref * psproc, ref * ptproc, gs_memory_t *mem)
{
int code;
check_dict_read(*pdict);
if ((code = dict_float_param(pdict, "Frequency", 0.0,
&psp->screen.frequency)) != 0 ||
(code = dict_float_param(pdict, "Angle", 0.0,
&psp->screen.angle)) != 0 ||
(code = dict_proc_param(pdict, "SpotFunction", psproc, false)) != 0 ||
(code = dict_bool_param(pdict, "AccurateScreens",
gs_currentaccuratescreens(mem),
&psp->accurate_screens)) < 0 ||
(code = dict_proc_param(pdict, "TransferFunction", ptproc, false)) < 0
)
return (code < 0 ? code : gs_error_undefined);
psp->transfer = (code > 0 ? (gs_mapping_proc) 0 : gs_mapped_transfer);
psp->transfer_closure.proc = 0;
psp->transfer_closure.data = 0;
return 0;
}
| DoS Exec Code | 0 | dict_spot_params(const ref * pdict, gs_spot_halftone * psp,
ref * psproc, ref * ptproc, gs_memory_t *mem)
{
int code;
check_dict_read(*pdict);
if ((code = dict_float_param(pdict, "Frequency", 0.0,
&psp->screen.frequency)) != 0 ||
(code = dict_float_param(pdict, "Angle", 0.0,
&psp->screen.angle)) != 0 ||
(code = dict_proc_param(pdict, "SpotFunction", psproc, false)) != 0 ||
(code = dict_bool_param(pdict, "AccurateScreens",
gs_currentaccuratescreens(mem),
&psp->accurate_screens)) < 0 ||
(code = dict_proc_param(pdict, "TransferFunction", ptproc, false)) < 0
)
return (code < 0 ? code : gs_error_undefined);
psp->transfer = (code > 0 ? (gs_mapping_proc) 0 : gs_mapped_transfer);
psp->transfer_closure.proc = 0;
psp->transfer_closure.data = 0;
return 0;
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,157 | dict_spot_results(i_ctx_t *i_ctx_p, ref * pdict, const gs_spot_halftone * psp)
{
int code;
code = dict_real_result(i_ctx_p, pdict, "ActualFrequency",
psp->screen.actual_frequency);
if (code < 0)
return code;
return dict_real_result(i_ctx_p, pdict, "ActualAngle",
psp->screen.actual_angle);
}
| DoS Exec Code | 0 | dict_spot_results(i_ctx_t *i_ctx_p, ref * pdict, const gs_spot_halftone * psp)
{
int code;
code = dict_real_result(i_ctx_p, pdict, "ActualFrequency",
psp->screen.actual_frequency);
if (code < 0)
return code;
return dict_real_result(i_ctx_p, pdict, "ActualAngle",
psp->screen.actual_angle);
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,158 | dict_threshold2_params(const ref * pdict, gs_threshold2_halftone * ptp,
ref * ptproc, gs_memory_t *mem)
{
ref *tstring;
int code =
dict_threshold_common_params(pdict,
(gs_threshold_halftone_common *)ptp,
&tstring, ptproc);
int bps;
uint size;
int cw2, ch2;
if (code < 0 ||
(code = cw2 = dict_int_param(pdict, "Width2", 0, 0x7fff, 0,
&ptp->width2)) < 0 ||
(code = ch2 = dict_int_param(pdict, "Height2", 0, 0x7fff, 0,
&ptp->height2)) < 0 ||
(code = dict_int_param(pdict, "BitsPerSample", 8, 16, -1, &bps)) < 0
)
return code;
if ((bps != 8 && bps != 16) || cw2 != ch2 ||
(!cw2 && (ptp->width2 == 0 || ptp->height2 == 0))
)
return_error(gs_error_rangecheck);
ptp->bytes_per_sample = bps / 8;
switch (r_type(tstring)) {
case t_string:
size = r_size(tstring);
gs_bytestring_from_string(&ptp->thresholds, tstring->value.const_bytes,
size);
break;
case t_astruct:
if (gs_object_type(mem, tstring->value.pstruct) != &st_bytes)
return_error(gs_error_typecheck);
size = gs_object_size(mem, tstring->value.pstruct);
gs_bytestring_from_bytes(&ptp->thresholds, r_ptr(tstring, byte),
0, size);
break;
default:
return_error(gs_error_typecheck);
}
check_read(*tstring);
if (size != (ptp->width * ptp->height + ptp->width2 * ptp->height2) *
ptp->bytes_per_sample)
return_error(gs_error_rangecheck);
return 0;
}
| DoS Exec Code | 0 | dict_threshold2_params(const ref * pdict, gs_threshold2_halftone * ptp,
ref * ptproc, gs_memory_t *mem)
{
ref *tstring;
int code =
dict_threshold_common_params(pdict,
(gs_threshold_halftone_common *)ptp,
&tstring, ptproc);
int bps;
uint size;
int cw2, ch2;
if (code < 0 ||
(code = cw2 = dict_int_param(pdict, "Width2", 0, 0x7fff, 0,
&ptp->width2)) < 0 ||
(code = ch2 = dict_int_param(pdict, "Height2", 0, 0x7fff, 0,
&ptp->height2)) < 0 ||
(code = dict_int_param(pdict, "BitsPerSample", 8, 16, -1, &bps)) < 0
)
return code;
if ((bps != 8 && bps != 16) || cw2 != ch2 ||
(!cw2 && (ptp->width2 == 0 || ptp->height2 == 0))
)
return_error(gs_error_rangecheck);
ptp->bytes_per_sample = bps / 8;
switch (r_type(tstring)) {
case t_string:
size = r_size(tstring);
gs_bytestring_from_string(&ptp->thresholds, tstring->value.const_bytes,
size);
break;
case t_astruct:
if (gs_object_type(mem, tstring->value.pstruct) != &st_bytes)
return_error(gs_error_typecheck);
size = gs_object_size(mem, tstring->value.pstruct);
gs_bytestring_from_bytes(&ptp->thresholds, r_ptr(tstring, byte),
0, size);
break;
default:
return_error(gs_error_typecheck);
}
check_read(*tstring);
if (size != (ptp->width * ptp->height + ptp->width2 * ptp->height2) *
ptp->bytes_per_sample)
return_error(gs_error_rangecheck);
return 0;
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,159 | dict_threshold_common_params(const ref * pdict,
gs_threshold_halftone_common * ptp,
ref **pptstring, ref *ptproc)
{
int code;
check_dict_read(*pdict);
if ((code = dict_int_param(pdict, "Width", 1, 0x7fff, -1,
&ptp->width)) < 0 ||
(code = dict_int_param(pdict, "Height", 1, 0x7fff, -1,
&ptp->height)) < 0 ||
(code = dict_find_string(pdict, "Thresholds", pptstring)) <= 0 ||
(code = dict_proc_param(pdict, "TransferFunction", ptproc, false)) < 0
)
return (code < 0 ? code : gs_error_undefined);
ptp->transfer_closure.proc = 0;
ptp->transfer_closure.data = 0;
return code;
}
| DoS Exec Code | 0 | dict_threshold_common_params(const ref * pdict,
gs_threshold_halftone_common * ptp,
ref **pptstring, ref *ptproc)
{
int code;
check_dict_read(*pdict);
if ((code = dict_int_param(pdict, "Width", 1, 0x7fff, -1,
&ptp->width)) < 0 ||
(code = dict_int_param(pdict, "Height", 1, 0x7fff, -1,
&ptp->height)) < 0 ||
(code = dict_find_string(pdict, "Thresholds", pptstring)) <= 0 ||
(code = dict_proc_param(pdict, "TransferFunction", ptproc, false)) < 0
)
return (code < 0 ? code : gs_error_undefined);
ptp->transfer_closure.proc = 0;
ptp->transfer_closure.data = 0;
return code;
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,160 | dict_threshold_params(const ref * pdict, gs_threshold_halftone * ptp,
ref * ptproc)
{
ref *tstring;
int code =
dict_threshold_common_params(pdict,
(gs_threshold_halftone_common *)ptp,
&tstring, ptproc);
if (code < 0)
return code;
check_read_type_only(*tstring, t_string);
if (r_size(tstring) != (long)ptp->width * ptp->height)
return_error(gs_error_rangecheck);
ptp->thresholds.data = tstring->value.const_bytes;
ptp->thresholds.size = r_size(tstring);
ptp->transfer = (code > 0 ? (gs_mapping_proc) 0 : gs_mapped_transfer);
return 0;
}
| DoS Exec Code | 0 | dict_threshold_params(const ref * pdict, gs_threshold_halftone * ptp,
ref * ptproc)
{
ref *tstring;
int code =
dict_threshold_common_params(pdict,
(gs_threshold_halftone_common *)ptp,
&tstring, ptproc);
if (code < 0)
return code;
check_read_type_only(*tstring, t_string);
if (r_size(tstring) != (long)ptp->width * ptp->height)
return_error(gs_error_rangecheck);
ptp->thresholds.data = tstring->value.const_bytes;
ptp->thresholds.size = r_size(tstring);
ptp->transfer = (code > 0 ? (gs_mapping_proc) 0 : gs_mapped_transfer);
return 0;
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,161 | gs_get_colorname_string(const gs_memory_t *mem, gs_separation_name colorname_index,
unsigned char **ppstr, unsigned int *pname_size)
{
ref nref;
name_index_ref(mem, colorname_index, &nref);
name_string_ref(mem, &nref, &nref);
return obj_string_data(mem, &nref, (const unsigned char**) ppstr, pname_size);
}
| DoS Exec Code | 0 | gs_get_colorname_string(const gs_memory_t *mem, gs_separation_name colorname_index,
unsigned char **ppstr, unsigned int *pname_size)
{
ref nref;
name_index_ref(mem, colorname_index, &nref);
name_string_ref(mem, &nref, &nref);
return obj_string_data(mem, &nref, (const unsigned char**) ppstr, pname_size);
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,162 | sethalftone_cleanup(i_ctx_t *i_ctx_p)
{
gx_device_halftone *pdht = r_ptr(&esp[4], gx_device_halftone);
gs_halftone *pht = r_ptr(&esp[3], gs_halftone);
gs_free_object(pdht->rc.memory, pdht,
"sethalftone_cleanup(device halftone)");
gs_free_object(pht->rc.memory, pht,
"sethalftone_cleanup(halftone)");
return 0;
}
| DoS Exec Code | 0 | sethalftone_cleanup(i_ctx_t *i_ctx_p)
{
gx_device_halftone *pdht = r_ptr(&esp[4], gx_device_halftone);
gs_halftone *pht = r_ptr(&esp[3], gs_halftone);
gs_free_object(pdht->rc.memory, pdht,
"sethalftone_cleanup(device halftone)");
gs_free_object(pht->rc.memory, pht,
"sethalftone_cleanup(halftone)");
return 0;
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,163 | spot1_dummy(double x, double y)
{
return (x + y) / 2;
}
| DoS Exec Code | 0 | spot1_dummy(double x, double y)
{
return (x + y) / 2;
}
| @@ -82,14 +82,22 @@ zsethalftone5(i_ctx_t *i_ctx_p)
gs_memory_t *mem;
uint edepth = ref_stack_count(&e_stack);
int npop = 2;
- int dict_enum = dict_first(op);
+ int dict_enum;
ref rvalue[2];
int cname, colorant_number;
byte * pname;
uint name_size;
int halftonetype, type = 0;
gs_gstate *pgs = igs;
- int space_index = r_space_index(op - 1);
+ int space_index;
+
+ if (ref_stack_count(&o_stack) < 2)
+ return_error(gs_error_stackunderflow);
+ check_type(*op, t_dictionary);
+ check_type(*(op - 1), t_dictionary);
+
+ dict_enum = dict_first(op);
+ space_index = r_space_index(op - 1);
mem = (gs_memory_t *) idmemory->spaces_indexed[space_index]; | CWE-704 | null | null |
11,164 | zstatus(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
switch (r_type(op)) {
case t_file:
{
stream *s;
make_bool(op, (file_is_valid(s, op) ? 1 : 0));
}
return 0;
case t_string:
{
gs_parsed_file_name_t pname;
struct stat fstat;
int code = parse_file_name(op, &pname,
i_ctx_p->LockFilePermissions, imemory);
if (code < 0) {
if (code == gs_error_undefinedfilename) {
make_bool(op, 0);
code = 0;
}
return code;
}
code = gs_terminate_file_name(&pname, imemory, "status");
if (code < 0)
return code;
code = (*pname.iodev->procs.file_status)(pname.iodev,
pname.fname, &fstat);
switch (code) {
case 0:
check_ostack(4);
/*
* Check to make sure that the file size fits into
* a PostScript integer. (On some systems, long is
* 32 bits, but file sizes are 64 bits.)
*/
push(4);
make_int(op - 4, stat_blocks(&fstat));
make_int(op - 3, fstat.st_size);
/*
* We can't check the value simply by using ==,
* because signed/unsigned == does the wrong thing.
* Instead, since integer assignment only keeps the
* bottom bits, we convert the values to double
* and then test for equality. This handles all
* cases of signed/unsigned or width mismatch.
*/
if ((double)op[-4].value.intval !=
(double)stat_blocks(&fstat) ||
(double)op[-3].value.intval !=
(double)fstat.st_size
)
return_error(gs_error_limitcheck);
make_int(op - 2, fstat.st_mtime);
make_int(op - 1, fstat.st_ctime);
make_bool(op, 1);
break;
case gs_error_undefinedfilename:
make_bool(op, 0);
code = 0;
}
gs_free_file_name(&pname, "status");
return code;
}
default:
return_op_typecheck(op);
}
}
| Bypass +Info | 0 | zstatus(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
switch (r_type(op)) {
case t_file:
{
stream *s;
make_bool(op, (file_is_valid(s, op) ? 1 : 0));
}
return 0;
case t_string:
{
gs_parsed_file_name_t pname;
struct stat fstat;
int code = parse_file_name(op, &pname,
i_ctx_p->LockFilePermissions, imemory);
if (code < 0) {
if (code == gs_error_undefinedfilename) {
make_bool(op, 0);
code = 0;
}
return code;
}
code = gs_terminate_file_name(&pname, imemory, "status");
if (code < 0)
return code;
code = (*pname.iodev->procs.file_status)(pname.iodev,
pname.fname, &fstat);
switch (code) {
case 0:
check_ostack(4);
/*
* Check to make sure that the file size fits into
* a PostScript integer. (On some systems, long is
* 32 bits, but file sizes are 64 bits.)
*/
push(4);
make_int(op - 4, stat_blocks(&fstat));
make_int(op - 3, fstat.st_size);
/*
* We can't check the value simply by using ==,
* because signed/unsigned == does the wrong thing.
* Instead, since integer assignment only keeps the
* bottom bits, we convert the values to double
* and then test for equality. This handles all
* cases of signed/unsigned or width mismatch.
*/
if ((double)op[-4].value.intval !=
(double)stat_blocks(&fstat) ||
(double)op[-3].value.intval !=
(double)fstat.st_size
)
return_error(gs_error_limitcheck);
make_int(op - 2, fstat.st_mtime);
make_int(op - 1, fstat.st_ctime);
make_bool(op, 1);
break;
case gs_error_undefinedfilename:
make_bool(op, 0);
code = 0;
}
gs_free_file_name(&pname, "status");
return code;
}
default:
return_op_typecheck(op);
}
}
| @@ -1081,6 +1081,9 @@ lib_file_open(gs_file_path_ptr lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx
gs_main_instance *minst = get_minst_from_memory(mem);
int code;
+ if (i_ctx_p && starting_arg_file)
+ i_ctx_p->starting_arg_file = false;
+
/* when starting arg files (@ files) iodev_default is not yet set */
if (iodev == 0)
iodev = (gx_io_device *)gx_io_device_table[0]; | CWE-200 | null | null |
11,165 | dump_icc_buffer(int buffersize, char filename[],byte *Buffer)
{
char full_file_name[50];
FILE *fid;
gs_sprintf(full_file_name,"%d)%s_debug.icc",global_icc_index,filename);
fid = gp_fopen(full_file_name,"wb");
fwrite(Buffer,sizeof(unsigned char),buffersize,fid);
fclose(fid);
}
| Exec Code | 0 | dump_icc_buffer(int buffersize, char filename[],byte *Buffer)
{
char full_file_name[50];
FILE *fid;
gs_sprintf(full_file_name,"%d)%s_debug.icc",global_icc_index,filename);
fid = gp_fopen(full_file_name,"wb");
fwrite(Buffer,sizeof(unsigned char),buffersize,fid);
fclose(fid);
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,166 | gs_currentdefaultgrayicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = DEFAULT_GRAY_ICC;
if (pgs->icc_manager->default_gray == NULL) {
pval->data = (const byte *) rfs;
pval->persistent = true;
} else {
pval->data = (const byte *) (pgs->icc_manager->default_gray->name);
pval->persistent = false;
}
pval->size = strlen((const char *)pval->data);
}
| Exec Code | 0 | gs_currentdefaultgrayicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = DEFAULT_GRAY_ICC;
if (pgs->icc_manager->default_gray == NULL) {
pval->data = (const byte *) rfs;
pval->persistent = true;
} else {
pval->data = (const byte *) (pgs->icc_manager->default_gray->name);
pval->persistent = false;
}
pval->size = strlen((const char *)pval->data);
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,167 | gs_currentdevicenicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = "";
/*FIXME: This should return the entire list !!! */
/* Just return the first one for now */
if (pgs->icc_manager->device_n == NULL) {
pval->data = (const byte *) rfs;
pval->persistent = true;
} else {
pval->data =
(const byte *) (pgs->icc_manager->device_n->head->iccprofile->name);
pval->persistent = false;
}
pval->size = strlen((const char *)pval->data);
}
| Exec Code | 0 | gs_currentdevicenicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = "";
/*FIXME: This should return the entire list !!! */
/* Just return the first one for now */
if (pgs->icc_manager->device_n == NULL) {
pval->data = (const byte *) rfs;
pval->persistent = true;
} else {
pval->data =
(const byte *) (pgs->icc_manager->device_n->head->iccprofile->name);
pval->persistent = false;
}
pval->size = strlen((const char *)pval->data);
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,168 | gs_currenticcdirectory(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = DEFAULT_DIR_ICC; /* as good as any other */
const gs_lib_ctx_t *lib_ctx = pgs->memory->gs_lib_ctx;
if (lib_ctx->profiledir == NULL) {
pval->data = (const byte *)rfs;
pval->size = strlen(rfs);
pval->persistent = true;
} else {
pval->data = (const byte *)(lib_ctx->profiledir);
pval->size = lib_ctx->profiledir_len;
pval->persistent = false;
}
}
| Exec Code | 0 | gs_currenticcdirectory(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = DEFAULT_DIR_ICC; /* as good as any other */
const gs_lib_ctx_t *lib_ctx = pgs->memory->gs_lib_ctx;
if (lib_ctx->profiledir == NULL) {
pval->data = (const byte *)rfs;
pval->size = strlen(rfs);
pval->persistent = true;
} else {
pval->data = (const byte *)(lib_ctx->profiledir);
pval->size = lib_ctx->profiledir_len;
pval->persistent = false;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,169 | gs_currentlabicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = LAB_ICC;
pval->data = (const byte *)( (pgs->icc_manager->lab_profile == NULL) ?
rfs : pgs->icc_manager->lab_profile->name);
pval->size = strlen((const char *)pval->data);
pval->persistent = true;
}
| Exec Code | 0 | gs_currentlabicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = LAB_ICC;
pval->data = (const byte *)( (pgs->icc_manager->lab_profile == NULL) ?
rfs : pgs->icc_manager->lab_profile->name);
pval->size = strlen((const char *)pval->data);
pval->persistent = true;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,170 | gs_currentnamedicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = "";
if (pgs->icc_manager->device_named == NULL) {
pval->data = (const byte *) rfs;
pval->persistent = true;
} else {
pval->data = (const byte *) (pgs->icc_manager->device_named->name);
pval->persistent = false;
}
pval->size = strlen((const char *)pval->data);
}
| Exec Code | 0 | gs_currentnamedicc(const gs_gstate * pgs, gs_param_string * pval)
{
static const char *const rfs = "";
if (pgs->icc_manager->device_named == NULL) {
pval->data = (const byte *) rfs;
pval->persistent = true;
} else {
pval->data = (const byte *) (pgs->icc_manager->device_named->name);
pval->persistent = false;
}
pval->size = strlen((const char *)pval->data);
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,171 | gs_currentoverrideicc(const gs_gstate *pgs)
{
if (pgs->icc_manager != NULL) {
return pgs->icc_manager->override_internal;
} else {
return false;
}
}
| Exec Code | 0 | gs_currentoverrideicc(const gs_gstate *pgs)
{
if (pgs->icc_manager != NULL) {
return pgs->icc_manager->override_internal;
} else {
return false;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,172 | gs_currentsrcgtagicc(const gs_gstate * pgs, gs_param_string * pval)
{
if (pgs->icc_manager->srcgtag_profile == NULL) {
pval->data = NULL;
pval->size = 0;
pval->persistent = true;
} else {
pval->data = (byte *)pgs->icc_manager->srcgtag_profile->name;
pval->size = strlen((const char *)pval->data);
pval->persistent = false;
}
}
| Exec Code | 0 | gs_currentsrcgtagicc(const gs_gstate * pgs, gs_param_string * pval)
{
if (pgs->icc_manager->srcgtag_profile == NULL) {
pval->data = NULL;
pval->size = 0;
pval->persistent = true;
} else {
pval->data = (byte *)pgs->icc_manager->srcgtag_profile->name;
pval->size = strlen((const char *)pval->data);
pval->persistent = false;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,173 | gs_setdefaultcmykicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char* pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_default_cmyk_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_profile(pgs->icc_manager,
(const char*) pname, namelen, DEFAULT_CMYK);
gs_free_object(mem, pname,
"set_default_cmyk_icc");
if (code < 0)
return gs_throw(code, "cannot find default cmyk icc profile");
return code;
}
| Exec Code | 0 | gs_setdefaultcmykicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char* pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_default_cmyk_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_profile(pgs->icc_manager,
(const char*) pname, namelen, DEFAULT_CMYK);
gs_free_object(mem, pname,
"set_default_cmyk_icc");
if (code < 0)
return gs_throw(code, "cannot find default cmyk icc profile");
return code;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,174 | gs_setdefaultgrayicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char *pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
bool not_initialized;
/* Detect if this is our first time in here. If so, then we need to
reset up the default gray color spaces that are in the graphic state
to be ICC based. It was not possible to do it until after we get
the profile */
not_initialized = (pgs->icc_manager->default_gray == NULL);
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_default_gray_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_profile(pgs->icc_manager,
(const char*) pname, namelen, DEFAULT_GRAY);
gs_free_object(mem, pname,
"set_default_gray_icc");
if (code < 0)
return gs_throw(code, "cannot find default gray icc profile");
/* if this is our first time in here then we need to properly install the
color spaces that were initialized in the graphic state at this time */
if (not_initialized) {
code = gsicc_init_gs_colors((gs_gstate*) pgs);
}
if (code < 0)
return gs_throw(code, "error initializing gstate color spaces to icc");
return code;
}
| Exec Code | 0 | gs_setdefaultgrayicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char *pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
bool not_initialized;
/* Detect if this is our first time in here. If so, then we need to
reset up the default gray color spaces that are in the graphic state
to be ICC based. It was not possible to do it until after we get
the profile */
not_initialized = (pgs->icc_manager->default_gray == NULL);
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_default_gray_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_profile(pgs->icc_manager,
(const char*) pname, namelen, DEFAULT_GRAY);
gs_free_object(mem, pname,
"set_default_gray_icc");
if (code < 0)
return gs_throw(code, "cannot find default gray icc profile");
/* if this is our first time in here then we need to properly install the
color spaces that were initialized in the graphic state at this time */
if (not_initialized) {
code = gsicc_init_gs_colors((gs_gstate*) pgs);
}
if (code < 0)
return gs_throw(code, "error initializing gstate color spaces to icc");
return code;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,175 | gs_setdevicenprofileicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code = 0;
char *pname, *pstr, *pstrend, *last = NULL;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
/* Check if it was "NULL" */
if (pval->size != 0) {
/* The DeviceN name can have multiple files
in it. This way we can define all the
DeviceN color spaces with ICC profiles.
divide using , and ; delimeters as well as
remove leading and ending spaces (file names
can have internal spaces). */
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_devicen_profile_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
pstr = gs_strtok(pname, ",;", &last);
while (pstr != NULL) {
namelen = strlen(pstr);
/* Remove leading and trailing spaces from the name */
while ( namelen > 0 && pstr[0] == 0x20) {
pstr++;
namelen--;
}
namelen = strlen(pstr);
pstrend = &(pstr[namelen-1]);
while ( namelen > 0 && pstrend[0] == 0x20) {
pstrend--;
namelen--;
}
code = gsicc_set_profile(pgs->icc_manager, (const char*) pstr, namelen, DEVICEN_TYPE);
if (code < 0)
return gs_throw(code, "cannot find devicen icc profile");
pstr = gs_strtok(NULL, ",;", &last);
}
gs_free_object(mem, pname,
"set_devicen_profile_icc");
return code;
}
return 0;
}
| Exec Code | 0 | gs_setdevicenprofileicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code = 0;
char *pname, *pstr, *pstrend, *last = NULL;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
/* Check if it was "NULL" */
if (pval->size != 0) {
/* The DeviceN name can have multiple files
in it. This way we can define all the
DeviceN color spaces with ICC profiles.
divide using , and ; delimeters as well as
remove leading and ending spaces (file names
can have internal spaces). */
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_devicen_profile_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
pstr = gs_strtok(pname, ",;", &last);
while (pstr != NULL) {
namelen = strlen(pstr);
/* Remove leading and trailing spaces from the name */
while ( namelen > 0 && pstr[0] == 0x20) {
pstr++;
namelen--;
}
namelen = strlen(pstr);
pstrend = &(pstr[namelen-1]);
while ( namelen > 0 && pstrend[0] == 0x20) {
pstrend--;
namelen--;
}
code = gsicc_set_profile(pgs->icc_manager, (const char*) pstr, namelen, DEVICEN_TYPE);
if (code < 0)
return gs_throw(code, "cannot find devicen icc profile");
pstr = gs_strtok(NULL, ",;", &last);
}
gs_free_object(mem, pname,
"set_devicen_profile_icc");
return code;
}
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,176 | gs_seticcdirectory(const gs_gstate * pgs, gs_param_string * pval)
{
char *pname;
int namelen = (pval->size)+1;
const gs_memory_t *mem = pgs->memory;
/* Check if it was "NULL" */
if (pval->size != 0 ) {
pname = (char *)gs_alloc_bytes((gs_memory_t *)mem, namelen,
"set_icc_directory");
if (pname == NULL)
return gs_rethrow(-1, "cannot allocate directory name");
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
gs_lib_ctx_set_icc_directory(mem, (const char*) pname, namelen);
gs_free_object((gs_memory_t *)mem, pname, "set_icc_directory");
}
return 0;
}
| Exec Code | 0 | gs_seticcdirectory(const gs_gstate * pgs, gs_param_string * pval)
{
char *pname;
int namelen = (pval->size)+1;
const gs_memory_t *mem = pgs->memory;
/* Check if it was "NULL" */
if (pval->size != 0 ) {
pname = (char *)gs_alloc_bytes((gs_memory_t *)mem, namelen,
"set_icc_directory");
if (pname == NULL)
return gs_rethrow(-1, "cannot allocate directory name");
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
gs_lib_ctx_set_icc_directory(mem, (const char*) pname, namelen);
gs_free_object((gs_memory_t *)mem, pname, "set_icc_directory");
}
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,177 | gs_setnamedprofileicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char* pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
/* Check if it was "NULL" */
if (pval->size != 0) {
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_named_profile_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_profile(pgs->icc_manager,
(const char*) pname, namelen, NAMED_TYPE);
gs_free_object(mem, pname,
"set_named_profile_icc");
if (code < 0)
return gs_rethrow(code, "cannot find named color icc profile");
return code;
}
return 0;
}
| Exec Code | 0 | gs_setnamedprofileicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char* pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
/* Check if it was "NULL" */
if (pval->size != 0) {
pname = (char *)gs_alloc_bytes(mem, namelen,
"set_named_profile_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_profile(pgs->icc_manager,
(const char*) pname, namelen, NAMED_TYPE);
gs_free_object(mem, pname,
"set_named_profile_icc");
if (code < 0)
return gs_rethrow(code, "cannot find named color icc profile");
return code;
}
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,178 | gs_setoverrideicc(gs_gstate *pgs, bool value)
{
if (pgs->icc_manager != NULL) {
pgs->icc_manager->override_internal = value;
}
}
| Exec Code | 0 | gs_setoverrideicc(gs_gstate *pgs, bool value)
{
if (pgs->icc_manager != NULL) {
pgs->icc_manager->override_internal = value;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,179 | gs_setsrcgtagicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char *pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
if (pval->size == 0) return 0;
pname = (char *)gs_alloc_bytes(mem, namelen, "set_srcgtag_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_srcgtag_struct(pgs->icc_manager, (const char*) pname,
namelen);
gs_free_object(mem, pname, "set_srcgtag_icc");
if (code < 0)
return gs_rethrow(code, "cannot find srctag file");
return code;
}
| Exec Code | 0 | gs_setsrcgtagicc(const gs_gstate * pgs, gs_param_string * pval)
{
int code;
char *pname;
int namelen = (pval->size)+1;
gs_memory_t *mem = pgs->memory;
if (pval->size == 0) return 0;
pname = (char *)gs_alloc_bytes(mem, namelen, "set_srcgtag_icc");
if (pname == NULL)
return_error(gs_error_VMerror);
memcpy(pname,pval->data,namelen-1);
pname[namelen-1] = 0;
code = gsicc_set_srcgtag_struct(pgs->icc_manager, (const char*) pname,
namelen);
gs_free_object(mem, pname, "set_srcgtag_icc");
if (code < 0)
return gs_rethrow(code, "cannot find srctag file");
return code;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,180 | void gscms_set_icc_range(cmm_profile_t **icc_profile)
{
int num_comp = (*icc_profile)->num_comps;
int k;
for ( k = 0; k < num_comp; k++) {
(*icc_profile)->Range.ranges[k].rmin = 0.0;
(*icc_profile)->Range.ranges[k].rmax = 1.0;
}
}
| Exec Code | 0 | void gscms_set_icc_range(cmm_profile_t **icc_profile)
{
int num_comp = (*icc_profile)->num_comps;
int k;
for ( k = 0; k < num_comp; k++) {
(*icc_profile)->Range.ranges[k].rmin = 0.0;
(*icc_profile)->Range.ranges[k].rmax = 1.0;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,181 | gsicc_check_device_link(cmm_profile_t *icc_profile)
{
bool value;
value = gscms_is_device_link(icc_profile->profile_handle);
icc_profile->isdevlink = value;
return value;
}
| Exec Code | 0 | gsicc_check_device_link(cmm_profile_t *icc_profile)
{
bool value;
value = gscms_is_device_link(icc_profile->profile_handle);
icc_profile->isdevlink = value;
return value;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,182 | gsicc_clone_profile(cmm_profile_t *source, cmm_profile_t **destination,
gs_memory_t *memory)
{
cmm_profile_t *des = gsicc_profile_new(NULL, memory, source->name,
source->name_length);
if (des == NULL)
return gs_throw(gs_error_VMerror, "Profile clone failed");
des->buffer = gs_alloc_bytes(memory, source->buffer_size, "gsicc_clone_profile");
if (des->buffer == NULL) {
rc_decrement(des, "gsicc_clone_profile");
return gs_throw(gs_error_VMerror, "Profile clone failed");
}
memcpy(des->buffer, source->buffer, source->buffer_size);
des->buffer_size = source->buffer_size;
gsicc_init_profile_info(des);
*destination = des;
return 0;
}
| Exec Code | 0 | gsicc_clone_profile(cmm_profile_t *source, cmm_profile_t **destination,
gs_memory_t *memory)
{
cmm_profile_t *des = gsicc_profile_new(NULL, memory, source->name,
source->name_length);
if (des == NULL)
return gs_throw(gs_error_VMerror, "Profile clone failed");
des->buffer = gs_alloc_bytes(memory, source->buffer_size, "gsicc_clone_profile");
if (des->buffer == NULL) {
rc_decrement(des, "gsicc_clone_profile");
return gs_throw(gs_error_VMerror, "Profile clone failed");
}
memcpy(des->buffer, source->buffer, source->buffer_size);
des->buffer_size = source->buffer_size;
gsicc_init_profile_info(des);
*destination = des;
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,183 | gsicc_extract_profile(gs_graphics_type_tag_t graphics_type_tag,
cmm_dev_profile_t *profile_struct,
cmm_profile_t **profile, gsicc_rendering_param_t *render_cond)
{
switch (graphics_type_tag & ~GS_DEVICE_ENCODES_TAGS) {
case GS_UNKNOWN_TAG:
case GS_UNTOUCHED_TAG:
default:
(*profile) = profile_struct->device_profile[0];
*render_cond = profile_struct->rendercond[0];
break;
case GS_PATH_TAG:
*render_cond = profile_struct->rendercond[1];
if (profile_struct->device_profile[1] != NULL) {
(*profile) = profile_struct->device_profile[1];
} else {
(*profile) = profile_struct->device_profile[0];
}
break;
case GS_IMAGE_TAG:
*render_cond = profile_struct->rendercond[2];
if (profile_struct->device_profile[2] != NULL) {
(*profile) = profile_struct->device_profile[2];
} else {
(*profile) = profile_struct->device_profile[0];
}
break;
case GS_TEXT_TAG:
*render_cond = profile_struct->rendercond[3];
if (profile_struct->device_profile[3] != NULL) {
(*profile) = profile_struct->device_profile[3];
} else {
(*profile) = profile_struct->device_profile[0];
}
break;
}
}
| Exec Code | 0 | gsicc_extract_profile(gs_graphics_type_tag_t graphics_type_tag,
cmm_dev_profile_t *profile_struct,
cmm_profile_t **profile, gsicc_rendering_param_t *render_cond)
{
switch (graphics_type_tag & ~GS_DEVICE_ENCODES_TAGS) {
case GS_UNKNOWN_TAG:
case GS_UNTOUCHED_TAG:
default:
(*profile) = profile_struct->device_profile[0];
*render_cond = profile_struct->rendercond[0];
break;
case GS_PATH_TAG:
*render_cond = profile_struct->rendercond[1];
if (profile_struct->device_profile[1] != NULL) {
(*profile) = profile_struct->device_profile[1];
} else {
(*profile) = profile_struct->device_profile[0];
}
break;
case GS_IMAGE_TAG:
*render_cond = profile_struct->rendercond[2];
if (profile_struct->device_profile[2] != NULL) {
(*profile) = profile_struct->device_profile[2];
} else {
(*profile) = profile_struct->device_profile[0];
}
break;
case GS_TEXT_TAG:
*render_cond = profile_struct->rendercond[3];
if (profile_struct->device_profile[3] != NULL) {
(*profile) = profile_struct->device_profile[3];
} else {
(*profile) = profile_struct->device_profile[0];
}
break;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,184 | gsicc_fill_srcgtag_item(gsicc_rendering_param_t *r_params, char **pstrlast, bool cmyk)
{
char *curr_ptr;
int blackptcomp;
int or_icc, preserve_k;
int ri;
/* Get the intent */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &ri) != 1)
return_error(gs_error_unknownerror);
r_params->rendering_intent = ri | gsRI_OVERRIDE;
/* Get the black point compensation setting */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &blackptcomp) != 1)
return_error(gs_error_unknownerror);
r_params->black_point_comp = blackptcomp | gsBP_OVERRIDE;
/* Get the over-ride embedded ICC boolean */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &or_icc) != 1)
return_error(gs_error_unknownerror);
r_params->override_icc = or_icc;
if (cmyk) {
/* Get the preserve K control */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &preserve_k) < 1)
return_error(gs_error_unknownerror);
r_params->preserve_black = preserve_k | gsKP_OVERRIDE;
} else {
r_params->preserve_black = gsBKPRESNOTSPECIFIED;
}
return 0;
}
| Exec Code | 0 | gsicc_fill_srcgtag_item(gsicc_rendering_param_t *r_params, char **pstrlast, bool cmyk)
{
char *curr_ptr;
int blackptcomp;
int or_icc, preserve_k;
int ri;
/* Get the intent */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &ri) != 1)
return_error(gs_error_unknownerror);
r_params->rendering_intent = ri | gsRI_OVERRIDE;
/* Get the black point compensation setting */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &blackptcomp) != 1)
return_error(gs_error_unknownerror);
r_params->black_point_comp = blackptcomp | gsBP_OVERRIDE;
/* Get the over-ride embedded ICC boolean */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &or_icc) != 1)
return_error(gs_error_unknownerror);
r_params->override_icc = or_icc;
if (cmyk) {
/* Get the preserve K control */
curr_ptr = gs_strtok(NULL, "\t,\32\n\r", pstrlast);
if (sscanf(curr_ptr, "%d", &preserve_k) < 1)
return_error(gs_error_unknownerror);
r_params->preserve_black = preserve_k | gsKP_OVERRIDE;
} else {
r_params->preserve_black = gsBKPRESNOTSPECIFIED;
}
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,185 | gsicc_finddevicen(const gs_color_space *pcs, gsicc_manager_t *icc_manager)
{
int k,j,i;
gsicc_devicen_entry_t *curr_entry;
int num_comps;
const gs_separation_name *names = pcs->params.device_n.names;
unsigned char *pname;
unsigned int name_size;
gsicc_devicen_t *devicen_profiles = icc_manager->device_n;
gsicc_colorname_t *icc_spot_entry;
int match_count = 0;
bool permute_needed = false;
num_comps = gs_color_space_num_components(pcs);
/* Go through the list looking for a match */
curr_entry = devicen_profiles->head;
for ( k = 0; k < devicen_profiles->count; k++ ) {
if (curr_entry->iccprofile->num_comps == num_comps ) {
/* Now check the names. The order is important
since this is supposed to be the laydown order.
If the order is off, the ICC profile will likely
not be accurate. The ICC profile drives the laydown
order here. A permutation vector is used to
reorganize the data prior to the transform application */
for ( j = 0; j < num_comps; j++) {
/* Get the character string and length for the component name. */
pcs->params.device_n.get_colorname_string(icc_manager->memory,
names[j], &pname, &name_size);
/* Compare to the jth entry in the ICC profile */
icc_spot_entry = curr_entry->iccprofile->spotnames->head;
for ( i = 0; i < num_comps; i++) {
if( strncmp((const char *) pname,
icc_spot_entry->name, name_size) == 0 ) {
/* Found a match */
match_count++;
curr_entry->iccprofile->devicen_permute[j] = i;
if ( j != i) {
/* Document ink order does not match ICC
profile ink order */
permute_needed = true;
}
break;
} else
icc_spot_entry = icc_spot_entry->next;
}
if (match_count < j+1)
return(NULL);
}
if ( match_count == num_comps) {
/* We have a match. Order of components does not match laydown
order specified by the ICC profile. Set a flag. This may
be an issue if we are using 2 DeviceN color spaces with the
same colorants but with different component orders. The problem
comes about since we would be sharing the profile in the
DeviceN entry of the icc manager. */
curr_entry->iccprofile->devicen_permute_needed = permute_needed;
return(curr_entry->iccprofile);
}
match_count = 0;
}
}
return NULL;
}
| Exec Code | 0 | gsicc_finddevicen(const gs_color_space *pcs, gsicc_manager_t *icc_manager)
{
int k,j,i;
gsicc_devicen_entry_t *curr_entry;
int num_comps;
const gs_separation_name *names = pcs->params.device_n.names;
unsigned char *pname;
unsigned int name_size;
gsicc_devicen_t *devicen_profiles = icc_manager->device_n;
gsicc_colorname_t *icc_spot_entry;
int match_count = 0;
bool permute_needed = false;
num_comps = gs_color_space_num_components(pcs);
/* Go through the list looking for a match */
curr_entry = devicen_profiles->head;
for ( k = 0; k < devicen_profiles->count; k++ ) {
if (curr_entry->iccprofile->num_comps == num_comps ) {
/* Now check the names. The order is important
since this is supposed to be the laydown order.
If the order is off, the ICC profile will likely
not be accurate. The ICC profile drives the laydown
order here. A permutation vector is used to
reorganize the data prior to the transform application */
for ( j = 0; j < num_comps; j++) {
/* Get the character string and length for the component name. */
pcs->params.device_n.get_colorname_string(icc_manager->memory,
names[j], &pname, &name_size);
/* Compare to the jth entry in the ICC profile */
icc_spot_entry = curr_entry->iccprofile->spotnames->head;
for ( i = 0; i < num_comps; i++) {
if( strncmp((const char *) pname,
icc_spot_entry->name, name_size) == 0 ) {
/* Found a match */
match_count++;
curr_entry->iccprofile->devicen_permute[j] = i;
if ( j != i) {
/* Document ink order does not match ICC
profile ink order */
permute_needed = true;
}
break;
} else
icc_spot_entry = icc_spot_entry->next;
}
if (match_count < j+1)
return(NULL);
}
if ( match_count == num_comps) {
/* We have a match. Order of components does not match laydown
order specified by the ICC profile. Set a flag. This may
be an issue if we are using 2 DeviceN color spaces with the
same colorants but with different component orders. The problem
comes about since we would be sharing the profile in the
DeviceN entry of the icc manager. */
curr_entry->iccprofile->devicen_permute_needed = permute_needed;
return(curr_entry->iccprofile);
}
match_count = 0;
}
}
return NULL;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,186 | gsicc_get_default_type(cmm_profile_t *profile_data)
{
switch (profile_data->default_match) {
case DEFAULT_GRAY:
return gs_color_space_index_DeviceGray;
case DEFAULT_RGB:
return gs_color_space_index_DeviceRGB;
case DEFAULT_CMYK:
return gs_color_space_index_DeviceCMYK;
case CIE_A:
return gs_color_space_index_CIEA;
case CIE_ABC:
return gs_color_space_index_CIEABC;
case CIE_DEF:
return gs_color_space_index_CIEDEF;
case CIE_DEFG:
return gs_color_space_index_CIEDEFG;
default:
return gs_color_space_index_ICC;
}
}
| Exec Code | 0 | gsicc_get_default_type(cmm_profile_t *profile_data)
{
switch (profile_data->default_match) {
case DEFAULT_GRAY:
return gs_color_space_index_DeviceGray;
case DEFAULT_RGB:
return gs_color_space_index_DeviceRGB;
case DEFAULT_CMYK:
return gs_color_space_index_DeviceCMYK;
case CIE_A:
return gs_color_space_index_CIEA;
case CIE_ABC:
return gs_color_space_index_CIEABC;
case CIE_DEF:
return gs_color_space_index_CIEDEF;
case CIE_DEFG:
return gs_color_space_index_CIEDEFG;
default:
return gs_color_space_index_ICC;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,187 | char* gsicc_get_dev_icccolorants(cmm_dev_profile_t *dev_profile)
{
if (dev_profile == NULL || dev_profile->spotnames == NULL ||
dev_profile->spotnames->name_str == NULL)
return 0;
else
return dev_profile->spotnames->name_str;
}
| Exec Code | 0 | char* gsicc_get_dev_icccolorants(cmm_dev_profile_t *dev_profile)
{
if (dev_profile == NULL || dev_profile->spotnames == NULL ||
dev_profile->spotnames->name_str == NULL)
return 0;
else
return dev_profile->spotnames->name_str;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,188 | gsicc_get_device_class(cmm_profile_t *icc_profile)
{
return gscms_get_device_class(icc_profile->profile_handle);
}
| Exec Code | 0 | gsicc_get_device_class(cmm_profile_t *icc_profile)
{
return gscms_get_device_class(icc_profile->profile_handle);
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,189 | gsicc_get_devicen_names(cmm_profile_t *icc_profile, gs_memory_t *memory)
{
/* The names are contained in the
named color tag. We use the
CMM to extract the data from the
profile */
if (icc_profile->profile_handle == NULL) {
if (icc_profile->buffer != NULL) {
icc_profile->profile_handle =
gsicc_get_profile_handle_buffer(icc_profile->buffer,
icc_profile->buffer_size,
memory);
} else
return;
}
icc_profile->spotnames =
gsicc_get_spotnames(icc_profile->profile_handle, memory->non_gc_memory);
return;
}
| Exec Code | 0 | gsicc_get_devicen_names(cmm_profile_t *icc_profile, gs_memory_t *memory)
{
/* The names are contained in the
named color tag. We use the
CMM to extract the data from the
profile */
if (icc_profile->profile_handle == NULL) {
if (icc_profile->buffer != NULL) {
icc_profile->profile_handle =
gsicc_get_profile_handle_buffer(icc_profile->buffer,
icc_profile->buffer_size,
memory);
} else
return;
}
icc_profile->spotnames =
gsicc_get_spotnames(icc_profile->profile_handle, memory->non_gc_memory);
return;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,190 | gsicc_get_profile_handle_buffer(unsigned char *buffer, int profile_size, gs_memory_t *memory)
{
gcmmhprofile_t profile_handle = NULL;
if( buffer != NULL) {
if (profile_size < ICC_HEADER_SIZE) {
return 0;
}
profile_handle = gscms_get_profile_handle_mem(memory->non_gc_memory, buffer, profile_size);
return profile_handle;
}
return 0;
}
| Exec Code | 0 | gsicc_get_profile_handle_buffer(unsigned char *buffer, int profile_size, gs_memory_t *memory)
{
gcmmhprofile_t profile_handle = NULL;
if( buffer != NULL) {
if (profile_size < ICC_HEADER_SIZE) {
return 0;
}
profile_handle = gscms_get_profile_handle_mem(memory->non_gc_memory, buffer, profile_size);
return profile_handle;
}
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,191 | gsicc_get_profile_handle_file(const char* pname, int namelen, gs_memory_t *mem)
{
cmm_profile_t *result;
stream* str;
int code;
/* First see if we can get the stream. NOTE icc directory not used! */
code = gsicc_open_search(pname, namelen, mem, NULL, 0, &str);
if (code < 0 || str == NULL) {
gs_throw(gs_error_VMerror, "Creation of ICC profile failed");
return NULL;
}
result = gsicc_profile_new(str, mem, pname, namelen);
code = sfclose(str);
if (result == NULL) {
gs_throw(gs_error_VMerror, "Creation of ICC profile failed");
return NULL;
}
code = gsicc_init_profile_info(result);
if (code < 0) {
gs_throw(gs_error_VMerror, "Creation of ICC profile failed");
return NULL;
}
return result;
}
| Exec Code | 0 | gsicc_get_profile_handle_file(const char* pname, int namelen, gs_memory_t *mem)
{
cmm_profile_t *result;
stream* str;
int code;
/* First see if we can get the stream. NOTE icc directory not used! */
code = gsicc_open_search(pname, namelen, mem, NULL, 0, &str);
if (code < 0 || str == NULL) {
gs_throw(gs_error_VMerror, "Creation of ICC profile failed");
return NULL;
}
result = gsicc_profile_new(str, mem, pname, namelen);
code = sfclose(str);
if (result == NULL) {
gs_throw(gs_error_VMerror, "Creation of ICC profile failed");
return NULL;
}
code = gsicc_init_profile_info(result);
if (code < 0) {
gs_throw(gs_error_VMerror, "Creation of ICC profile failed");
return NULL;
}
return result;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,192 | gsicc_get_srcprofile(gsicc_colorbuffer_t data_cs,
gs_graphics_type_tag_t graphics_type_tag,
cmm_srcgtag_profile_t *srcgtag_profile,
cmm_profile_t **profile, gsicc_rendering_param_t *render_cond)
{
(*profile) = NULL;
(*render_cond).rendering_intent = gsPERCEPTUAL;
switch (graphics_type_tag & ~GS_DEVICE_ENCODES_TAGS) {
case GS_UNKNOWN_TAG:
case GS_UNTOUCHED_TAG:
default:
break;
case GS_PATH_TAG:
if (data_cs == gsRGB) {
(*profile) = srcgtag_profile->rgb_profiles[gsSRC_GRAPPRO];
*render_cond = srcgtag_profile->rgb_rend_cond[gsSRC_GRAPPRO];
} else if (data_cs == gsCMYK) {
(*profile) = srcgtag_profile->cmyk_profiles[gsSRC_GRAPPRO];
*render_cond = srcgtag_profile->cmyk_rend_cond[gsSRC_GRAPPRO];
} else if (data_cs == gsGRAY) {
(*profile) = srcgtag_profile->gray_profiles[gsSRC_GRAPPRO];
*render_cond = srcgtag_profile->gray_rend_cond[gsSRC_GRAPPRO];
}
break;
case GS_IMAGE_TAG:
if (data_cs == gsRGB) {
(*profile) = srcgtag_profile->rgb_profiles[gsSRC_IMAGPRO];
*render_cond = srcgtag_profile->rgb_rend_cond[gsSRC_IMAGPRO];
} else if (data_cs == gsCMYK) {
(*profile) = srcgtag_profile->cmyk_profiles[gsSRC_IMAGPRO];
*render_cond = srcgtag_profile->cmyk_rend_cond[gsSRC_IMAGPRO];
} else if (data_cs == gsGRAY) {
(*profile) = srcgtag_profile->gray_profiles[gsSRC_IMAGPRO];
*render_cond = srcgtag_profile->gray_rend_cond[gsSRC_IMAGPRO];
}
break;
case GS_TEXT_TAG:
if (data_cs == gsRGB) {
(*profile) = srcgtag_profile->rgb_profiles[gsSRC_TEXTPRO];
*render_cond = srcgtag_profile->rgb_rend_cond[gsSRC_TEXTPRO];
} else if (data_cs == gsCMYK) {
(*profile) = srcgtag_profile->cmyk_profiles[gsSRC_TEXTPRO];
*render_cond = srcgtag_profile->cmyk_rend_cond[gsSRC_TEXTPRO];
} else if (data_cs == gsGRAY) {
(*profile) = srcgtag_profile->gray_profiles[gsSRC_TEXTPRO];
*render_cond = srcgtag_profile->gray_rend_cond[gsSRC_TEXTPRO];
}
break;
}
}
| Exec Code | 0 | gsicc_get_srcprofile(gsicc_colorbuffer_t data_cs,
gs_graphics_type_tag_t graphics_type_tag,
cmm_srcgtag_profile_t *srcgtag_profile,
cmm_profile_t **profile, gsicc_rendering_param_t *render_cond)
{
(*profile) = NULL;
(*render_cond).rendering_intent = gsPERCEPTUAL;
switch (graphics_type_tag & ~GS_DEVICE_ENCODES_TAGS) {
case GS_UNKNOWN_TAG:
case GS_UNTOUCHED_TAG:
default:
break;
case GS_PATH_TAG:
if (data_cs == gsRGB) {
(*profile) = srcgtag_profile->rgb_profiles[gsSRC_GRAPPRO];
*render_cond = srcgtag_profile->rgb_rend_cond[gsSRC_GRAPPRO];
} else if (data_cs == gsCMYK) {
(*profile) = srcgtag_profile->cmyk_profiles[gsSRC_GRAPPRO];
*render_cond = srcgtag_profile->cmyk_rend_cond[gsSRC_GRAPPRO];
} else if (data_cs == gsGRAY) {
(*profile) = srcgtag_profile->gray_profiles[gsSRC_GRAPPRO];
*render_cond = srcgtag_profile->gray_rend_cond[gsSRC_GRAPPRO];
}
break;
case GS_IMAGE_TAG:
if (data_cs == gsRGB) {
(*profile) = srcgtag_profile->rgb_profiles[gsSRC_IMAGPRO];
*render_cond = srcgtag_profile->rgb_rend_cond[gsSRC_IMAGPRO];
} else if (data_cs == gsCMYK) {
(*profile) = srcgtag_profile->cmyk_profiles[gsSRC_IMAGPRO];
*render_cond = srcgtag_profile->cmyk_rend_cond[gsSRC_IMAGPRO];
} else if (data_cs == gsGRAY) {
(*profile) = srcgtag_profile->gray_profiles[gsSRC_IMAGPRO];
*render_cond = srcgtag_profile->gray_rend_cond[gsSRC_IMAGPRO];
}
break;
case GS_TEXT_TAG:
if (data_cs == gsRGB) {
(*profile) = srcgtag_profile->rgb_profiles[gsSRC_TEXTPRO];
*render_cond = srcgtag_profile->rgb_rend_cond[gsSRC_TEXTPRO];
} else if (data_cs == gsCMYK) {
(*profile) = srcgtag_profile->cmyk_profiles[gsSRC_TEXTPRO];
*render_cond = srcgtag_profile->cmyk_rend_cond[gsSRC_TEXTPRO];
} else if (data_cs == gsGRAY) {
(*profile) = srcgtag_profile->gray_profiles[gsSRC_TEXTPRO];
*render_cond = srcgtag_profile->gray_rend_cond[gsSRC_TEXTPRO];
}
break;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,193 | unsigned int gsicc_getprofilesize(unsigned char *buffer)
{
return ( (buffer[0] << 24) + (buffer[1] << 16) +
(buffer[2] << 8) + buffer[3] );
}
| Exec Code | 0 | unsigned int gsicc_getprofilesize(unsigned char *buffer)
{
return ( (buffer[0] << 24) + (buffer[1] << 16) +
(buffer[2] << 8) + buffer[3] );
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,194 | gsicc_getsrc_channel_count(cmm_profile_t *icc_profile)
{
return gscms_get_input_channel_count(icc_profile->profile_handle);
}
| Exec Code | 0 | gsicc_getsrc_channel_count(cmm_profile_t *icc_profile)
{
return gscms_get_input_channel_count(icc_profile->profile_handle);
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,195 | gsicc_init_device_profile_struct(gx_device * dev,
char *profile_name,
gsicc_profile_types_t profile_type)
{
int code;
cmm_profile_t *curr_profile;
cmm_dev_profile_t *profile_struct;
/* See if the device has a profile structure. If it does, then do a
check to see if the profile that we are trying to set is already
set and the same. If it is not, then we need to free it and then
reset. */
profile_struct = dev->icc_struct;
if (profile_struct != NULL) {
/* Get the profile of interest */
if (profile_type < gsPROOFPROFILE) {
curr_profile = profile_struct->device_profile[profile_type];
} else {
/* The proof, link profile or post render */
if (profile_type == gsPROOFPROFILE) {
curr_profile = profile_struct->proof_profile;
} else if (profile_type == gsLINKPROFILE) {
curr_profile = profile_struct->link_profile;
} else {
curr_profile = profile_struct->postren_profile;
}
}
/* See if we have the same profile in this location */
if (curr_profile != NULL) {
/* There is something there now. See if what we have coming in
is different and it is not the output intent. In this */
if (profile_name != NULL) {
if (strncmp(curr_profile->name, profile_name,
strlen(profile_name)) != 0 &&
strncmp(curr_profile->name, OI_PROFILE,
strlen(curr_profile->name)) != 0) {
/* A change in the profile. rc decrement this one as it
will be replaced */
rc_decrement(curr_profile, "gsicc_init_device_profile_struct");
} else {
/* Nothing to change. It was either the same or is the
output intent */
return 0;
}
}
}
} else {
/* We have no profile structure at all. Allocate the structure in
non-GC memory. */
dev->icc_struct = gsicc_new_device_profile_array(dev->memory);
profile_struct = dev->icc_struct;
if (profile_struct == NULL)
return_error(gs_error_VMerror);
}
/* Either use the incoming or a default */
if (profile_name == NULL) {
profile_name =
(char *) gs_alloc_bytes(dev->memory,
MAX_DEFAULT_ICC_LENGTH,
"gsicc_init_device_profile_struct");
if (profile_name == NULL)
return_error(gs_error_VMerror);
switch(dev->color_info.num_components) {
case 1:
strncpy(profile_name, DEFAULT_GRAY_ICC, strlen(DEFAULT_GRAY_ICC));
profile_name[strlen(DEFAULT_GRAY_ICC)] = 0;
break;
case 3:
strncpy(profile_name, DEFAULT_RGB_ICC, strlen(DEFAULT_RGB_ICC));
profile_name[strlen(DEFAULT_RGB_ICC)] = 0;
break;
case 4:
strncpy(profile_name, DEFAULT_CMYK_ICC, strlen(DEFAULT_CMYK_ICC));
profile_name[strlen(DEFAULT_CMYK_ICC)] = 0;
break;
default:
strncpy(profile_name, DEFAULT_CMYK_ICC, strlen(DEFAULT_CMYK_ICC));
profile_name[strlen(DEFAULT_CMYK_ICC)] = 0;
break;
}
/* Go ahead and set the profile */
code = gsicc_set_device_profile(dev, dev->memory, profile_name,
profile_type);
gs_free_object(dev->memory, profile_name,
"gsicc_init_device_profile_struct");
return code;
} else {
/* Go ahead and set the profile */
code = gsicc_set_device_profile(dev, dev->memory, profile_name,
profile_type);
return code;
}
}
| Exec Code | 0 | gsicc_init_device_profile_struct(gx_device * dev,
char *profile_name,
gsicc_profile_types_t profile_type)
{
int code;
cmm_profile_t *curr_profile;
cmm_dev_profile_t *profile_struct;
/* See if the device has a profile structure. If it does, then do a
check to see if the profile that we are trying to set is already
set and the same. If it is not, then we need to free it and then
reset. */
profile_struct = dev->icc_struct;
if (profile_struct != NULL) {
/* Get the profile of interest */
if (profile_type < gsPROOFPROFILE) {
curr_profile = profile_struct->device_profile[profile_type];
} else {
/* The proof, link profile or post render */
if (profile_type == gsPROOFPROFILE) {
curr_profile = profile_struct->proof_profile;
} else if (profile_type == gsLINKPROFILE) {
curr_profile = profile_struct->link_profile;
} else {
curr_profile = profile_struct->postren_profile;
}
}
/* See if we have the same profile in this location */
if (curr_profile != NULL) {
/* There is something there now. See if what we have coming in
is different and it is not the output intent. In this */
if (profile_name != NULL) {
if (strncmp(curr_profile->name, profile_name,
strlen(profile_name)) != 0 &&
strncmp(curr_profile->name, OI_PROFILE,
strlen(curr_profile->name)) != 0) {
/* A change in the profile. rc decrement this one as it
will be replaced */
rc_decrement(curr_profile, "gsicc_init_device_profile_struct");
} else {
/* Nothing to change. It was either the same or is the
output intent */
return 0;
}
}
}
} else {
/* We have no profile structure at all. Allocate the structure in
non-GC memory. */
dev->icc_struct = gsicc_new_device_profile_array(dev->memory);
profile_struct = dev->icc_struct;
if (profile_struct == NULL)
return_error(gs_error_VMerror);
}
/* Either use the incoming or a default */
if (profile_name == NULL) {
profile_name =
(char *) gs_alloc_bytes(dev->memory,
MAX_DEFAULT_ICC_LENGTH,
"gsicc_init_device_profile_struct");
if (profile_name == NULL)
return_error(gs_error_VMerror);
switch(dev->color_info.num_components) {
case 1:
strncpy(profile_name, DEFAULT_GRAY_ICC, strlen(DEFAULT_GRAY_ICC));
profile_name[strlen(DEFAULT_GRAY_ICC)] = 0;
break;
case 3:
strncpy(profile_name, DEFAULT_RGB_ICC, strlen(DEFAULT_RGB_ICC));
profile_name[strlen(DEFAULT_RGB_ICC)] = 0;
break;
case 4:
strncpy(profile_name, DEFAULT_CMYK_ICC, strlen(DEFAULT_CMYK_ICC));
profile_name[strlen(DEFAULT_CMYK_ICC)] = 0;
break;
default:
strncpy(profile_name, DEFAULT_CMYK_ICC, strlen(DEFAULT_CMYK_ICC));
profile_name[strlen(DEFAULT_CMYK_ICC)] = 0;
break;
}
/* Go ahead and set the profile */
code = gsicc_set_device_profile(dev, dev->memory, profile_name,
profile_type);
gs_free_object(dev->memory, profile_name,
"gsicc_init_device_profile_struct");
return code;
} else {
/* Go ahead and set the profile */
code = gsicc_set_device_profile(dev, dev->memory, profile_name,
profile_type);
return code;
}
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,196 | gsicc_init_gs_colors(gs_gstate *pgs)
{
int code = 0;
gs_color_space *cs_old;
gs_color_space *cs_new;
int k;
if (pgs->in_cachedevice)
return_error(gs_error_undefined);
for (k = 0; k < 2; k++) {
/* First do color space 0 */
cs_old = pgs->color[k].color_space;
cs_new = gs_cspace_new_DeviceGray(pgs->memory);
rc_increment_cs(cs_new);
pgs->color[k].color_space = cs_new;
if ( (code = cs_new->type->install_cspace(cs_new, pgs)) < 0 ) {
pgs->color[k].color_space = cs_old;
rc_decrement_only_cs(cs_new, "gsicc_init_gs_colors");
return code;
} else {
rc_decrement_only_cs(cs_old, "gsicc_init_gs_colors");
}
}
return code;
}
| Exec Code | 0 | gsicc_init_gs_colors(gs_gstate *pgs)
{
int code = 0;
gs_color_space *cs_old;
gs_color_space *cs_new;
int k;
if (pgs->in_cachedevice)
return_error(gs_error_undefined);
for (k = 0; k < 2; k++) {
/* First do color space 0 */
cs_old = pgs->color[k].color_space;
cs_new = gs_cspace_new_DeviceGray(pgs->memory);
rc_increment_cs(cs_new);
pgs->color[k].color_space = cs_new;
if ( (code = cs_new->type->install_cspace(cs_new, pgs)) < 0 ) {
pgs->color[k].color_space = cs_old;
rc_decrement_only_cs(cs_new, "gsicc_init_gs_colors");
return code;
} else {
rc_decrement_only_cs(cs_old, "gsicc_init_gs_colors");
}
}
return code;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,197 | gsicc_init_profile_info(cmm_profile_t *profile)
{
int k;
/* Get the profile handle */
profile->profile_handle =
gsicc_get_profile_handle_buffer(profile->buffer,
profile->buffer_size,
profile->memory);
if (profile->profile_handle == NULL)
return -1;
/* Compute the hash code of the profile. */
gsicc_get_icc_buff_hash(profile->buffer, &(profile->hashcode),
profile->buffer_size);
profile->hash_is_valid = true;
profile->default_match = DEFAULT_NONE;
profile->num_comps = gscms_get_input_channel_count(profile->profile_handle);
profile->num_comps_out = gscms_get_output_channel_count(profile->profile_handle);
profile->data_cs = gscms_get_profile_data_space(profile->profile_handle);
/* Initialize the range to default values */
for ( k = 0; k < profile->num_comps; k++) {
profile->Range.ranges[k].rmin = 0.0;
profile->Range.ranges[k].rmax = 1.0;
}
return 0;
}
| Exec Code | 0 | gsicc_init_profile_info(cmm_profile_t *profile)
{
int k;
/* Get the profile handle */
profile->profile_handle =
gsicc_get_profile_handle_buffer(profile->buffer,
profile->buffer_size,
profile->memory);
if (profile->profile_handle == NULL)
return -1;
/* Compute the hash code of the profile. */
gsicc_get_icc_buff_hash(profile->buffer, &(profile->hashcode),
profile->buffer_size);
profile->hash_is_valid = true;
profile->default_match = DEFAULT_NONE;
profile->num_comps = gscms_get_input_channel_count(profile->profile_handle);
profile->num_comps_out = gscms_get_output_channel_count(profile->profile_handle);
profile->data_cs = gscms_get_profile_data_space(profile->profile_handle);
/* Initialize the range to default values */
for ( k = 0; k < profile->num_comps; k++) {
profile->Range.ranges[k].rmin = 0.0;
profile->Range.ranges[k].rmax = 1.0;
}
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,198 | gsicc_initialize_default_profile(cmm_profile_t *icc_profile)
{
gsicc_profile_t defaulttype = icc_profile->default_match;
gsicc_colorbuffer_t default_space = gsUNDEFINED;
int num_comps, num_comps_out;
gs_memory_t *mem = icc_profile->memory;
/* Get the profile handle if it is not already set */
if (icc_profile->profile_handle == NULL) {
icc_profile->profile_handle =
gsicc_get_profile_handle_buffer(icc_profile->buffer,
icc_profile->buffer_size,
mem);
if (icc_profile->profile_handle == NULL) {
return gs_rethrow1(gs_error_VMerror, "allocation of profile %s handle failed",
icc_profile->name);
}
}
if (icc_profile->buffer != NULL && icc_profile->hash_is_valid == false) {
/* Compute the hash code of the profile. */
gsicc_get_icc_buff_hash(icc_profile->buffer, &(icc_profile->hashcode),
icc_profile->buffer_size);
icc_profile->hash_is_valid = true;
}
num_comps = icc_profile->num_comps;
icc_profile->num_comps =
gscms_get_input_channel_count(icc_profile->profile_handle);
num_comps_out = icc_profile->num_comps_out;
icc_profile->num_comps_out =
gscms_get_output_channel_count(icc_profile->profile_handle);
icc_profile->data_cs =
gscms_get_profile_data_space(icc_profile->profile_handle);
if_debug0m(gs_debug_flag_icc,mem,"[icc] Setting ICC profile in Manager\n");
switch(defaulttype) {
case DEFAULT_GRAY:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Default Gray\n");
default_space = gsGRAY;
break;
case DEFAULT_RGB:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Default RGB\n");
default_space = gsRGB;
break;
case DEFAULT_CMYK:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Default CMYK\n");
default_space = gsCMYK;
break;
case NAMED_TYPE:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Named Color\n");
break;
case LAB_TYPE:
if_debug0m(gs_debug_flag_icc,mem,"[icc] CIELAB Profile\n");
break;
case DEVICEN_TYPE:
if_debug0m(gs_debug_flag_icc,mem,"[icc] DeviceN Profile\n");
break;
case DEFAULT_NONE:
default:
return 0;
break;
}
if_debug1m(gs_debug_flag_icc,mem,"[icc] name = %s\n", icc_profile->name);
if_debug1m(gs_debug_flag_icc,mem,"[icc] num_comps = %d\n", icc_profile->num_comps);
/* Check that we have the proper color space for the ICC
profiles that can be externally set */
if (default_space != gsUNDEFINED ||
num_comps != icc_profile->num_comps ||
num_comps_out != icc_profile->num_comps_out) {
if (icc_profile->data_cs != default_space) {
return gs_rethrow(-1, "A default profile has an incorrect color space");
}
}
return 0;
}
| Exec Code | 0 | gsicc_initialize_default_profile(cmm_profile_t *icc_profile)
{
gsicc_profile_t defaulttype = icc_profile->default_match;
gsicc_colorbuffer_t default_space = gsUNDEFINED;
int num_comps, num_comps_out;
gs_memory_t *mem = icc_profile->memory;
/* Get the profile handle if it is not already set */
if (icc_profile->profile_handle == NULL) {
icc_profile->profile_handle =
gsicc_get_profile_handle_buffer(icc_profile->buffer,
icc_profile->buffer_size,
mem);
if (icc_profile->profile_handle == NULL) {
return gs_rethrow1(gs_error_VMerror, "allocation of profile %s handle failed",
icc_profile->name);
}
}
if (icc_profile->buffer != NULL && icc_profile->hash_is_valid == false) {
/* Compute the hash code of the profile. */
gsicc_get_icc_buff_hash(icc_profile->buffer, &(icc_profile->hashcode),
icc_profile->buffer_size);
icc_profile->hash_is_valid = true;
}
num_comps = icc_profile->num_comps;
icc_profile->num_comps =
gscms_get_input_channel_count(icc_profile->profile_handle);
num_comps_out = icc_profile->num_comps_out;
icc_profile->num_comps_out =
gscms_get_output_channel_count(icc_profile->profile_handle);
icc_profile->data_cs =
gscms_get_profile_data_space(icc_profile->profile_handle);
if_debug0m(gs_debug_flag_icc,mem,"[icc] Setting ICC profile in Manager\n");
switch(defaulttype) {
case DEFAULT_GRAY:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Default Gray\n");
default_space = gsGRAY;
break;
case DEFAULT_RGB:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Default RGB\n");
default_space = gsRGB;
break;
case DEFAULT_CMYK:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Default CMYK\n");
default_space = gsCMYK;
break;
case NAMED_TYPE:
if_debug0m(gs_debug_flag_icc,mem,"[icc] Named Color\n");
break;
case LAB_TYPE:
if_debug0m(gs_debug_flag_icc,mem,"[icc] CIELAB Profile\n");
break;
case DEVICEN_TYPE:
if_debug0m(gs_debug_flag_icc,mem,"[icc] DeviceN Profile\n");
break;
case DEFAULT_NONE:
default:
return 0;
break;
}
if_debug1m(gs_debug_flag_icc,mem,"[icc] name = %s\n", icc_profile->name);
if_debug1m(gs_debug_flag_icc,mem,"[icc] num_comps = %d\n", icc_profile->num_comps);
/* Check that we have the proper color space for the ICC
profiles that can be externally set */
if (default_space != gsUNDEFINED ||
num_comps != icc_profile->num_comps ||
num_comps_out != icc_profile->num_comps_out) {
if (icc_profile->data_cs != default_space) {
return gs_rethrow(-1, "A default profile has an incorrect color space");
}
}
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
11,199 | gsicc_initialize_iccsmask(gsicc_manager_t *icc_manager)
{
gs_memory_t *stable_mem = icc_manager->memory->stable_memory;
/* Allocations need to be done in stable memory. We want to maintain
the smask_profiles object */
icc_manager->smask_profiles = gsicc_new_iccsmask(stable_mem);
if (icc_manager->smask_profiles == NULL)
return gs_throw(gs_error_VMerror, "insufficient memory to allocate smask profiles");
/* Load the gray, rgb, and cmyk profiles */
if ((icc_manager->smask_profiles->smask_gray =
gsicc_set_iccsmaskprofile(SMASK_GRAY_ICC, strlen(SMASK_GRAY_ICC),
icc_manager, stable_mem) ) == NULL) {
return gs_throw(-1, "failed to load gray smask profile");
}
if ((icc_manager->smask_profiles->smask_rgb =
gsicc_set_iccsmaskprofile(SMASK_RGB_ICC, strlen(SMASK_RGB_ICC),
icc_manager, stable_mem)) == NULL) {
return gs_throw(-1, "failed to load rgb smask profile");
}
if ((icc_manager->smask_profiles->smask_cmyk =
gsicc_set_iccsmaskprofile(SMASK_CMYK_ICC, strlen(SMASK_CMYK_ICC),
icc_manager, stable_mem)) == NULL) {
return gs_throw(-1, "failed to load cmyk smask profile");
}
/* Set these as "default" so that pdfwrite or other high level devices
will know that these are manufactured profiles, and default spaces
should be used */
icc_manager->smask_profiles->smask_gray->default_match = DEFAULT_GRAY;
icc_manager->smask_profiles->smask_rgb->default_match = DEFAULT_RGB;
icc_manager->smask_profiles->smask_cmyk->default_match = DEFAULT_CMYK;
return 0;
}
| Exec Code | 0 | gsicc_initialize_iccsmask(gsicc_manager_t *icc_manager)
{
gs_memory_t *stable_mem = icc_manager->memory->stable_memory;
/* Allocations need to be done in stable memory. We want to maintain
the smask_profiles object */
icc_manager->smask_profiles = gsicc_new_iccsmask(stable_mem);
if (icc_manager->smask_profiles == NULL)
return gs_throw(gs_error_VMerror, "insufficient memory to allocate smask profiles");
/* Load the gray, rgb, and cmyk profiles */
if ((icc_manager->smask_profiles->smask_gray =
gsicc_set_iccsmaskprofile(SMASK_GRAY_ICC, strlen(SMASK_GRAY_ICC),
icc_manager, stable_mem) ) == NULL) {
return gs_throw(-1, "failed to load gray smask profile");
}
if ((icc_manager->smask_profiles->smask_rgb =
gsicc_set_iccsmaskprofile(SMASK_RGB_ICC, strlen(SMASK_RGB_ICC),
icc_manager, stable_mem)) == NULL) {
return gs_throw(-1, "failed to load rgb smask profile");
}
if ((icc_manager->smask_profiles->smask_cmyk =
gsicc_set_iccsmaskprofile(SMASK_CMYK_ICC, strlen(SMASK_CMYK_ICC),
icc_manager, stable_mem)) == NULL) {
return gs_throw(-1, "failed to load cmyk smask profile");
}
/* Set these as "default" so that pdfwrite or other high level devices
will know that these are manufactured profiles, and default spaces
should be used */
icc_manager->smask_profiles->smask_gray->default_match = DEFAULT_GRAY;
icc_manager->smask_profiles->smask_rgb->default_match = DEFAULT_RGB;
icc_manager->smask_profiles->smask_cmyk->default_match = DEFAULT_CMYK;
return 0;
}
| @@ -1124,10 +1124,12 @@ gsicc_open_search(const char* pname, int namelen, gs_memory_t *mem_gc,
}
/* First just try it like it is */
- str = sfopen(pname, "r", mem_gc);
- if (str != NULL) {
- *strp = str;
- return 0;
+ if (gs_check_file_permission(mem_gc, pname, namelen, "r") >= 0) {
+ str = sfopen(pname, "r", mem_gc);
+ if (str != NULL) {
+ *strp = str;
+ return 0;
+ }
}
/* If that fails, try %rom% */ /* FIXME: Not sure this is needed or correct */ | CWE-20 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.