idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
2,200
check_mandatory_fields (DBusHeader *header) { #define REQUIRE_FIELD(name) do { if (header->fields[DBUS_HEADER_FIELD_##name].value_pos < 0) return DBUS_INVALID_MISSING_##name; } while (0) switch (_dbus_header_get_message_type (header)) { case DBUS_MESSAGE_TYPE_SIGNAL: REQUIRE_FIELD (INTERFACE); /* FALL THRU - signals also require the path and member */ case DBUS_MESSAGE_TYPE_METHOD_CALL: REQUIRE_FIELD (PATH); REQUIRE_FIELD (MEMBER); break; case DBUS_MESSAGE_TYPE_ERROR: REQUIRE_FIELD (ERROR_NAME); REQUIRE_FIELD (REPLY_SERIAL); break; case DBUS_MESSAGE_TYPE_METHOD_RETURN: REQUIRE_FIELD (REPLY_SERIAL); break; default: /* other message types allowed but ignored */ break; } return DBUS_VALID; }
DoS +Info
0
check_mandatory_fields (DBusHeader *header) { #define REQUIRE_FIELD(name) do { if (header->fields[DBUS_HEADER_FIELD_##name].value_pos < 0) return DBUS_INVALID_MISSING_##name; } while (0) switch (_dbus_header_get_message_type (header)) { case DBUS_MESSAGE_TYPE_SIGNAL: REQUIRE_FIELD (INTERFACE); /* FALL THRU - signals also require the path and member */ case DBUS_MESSAGE_TYPE_METHOD_CALL: REQUIRE_FIELD (PATH); REQUIRE_FIELD (MEMBER); break; case DBUS_MESSAGE_TYPE_ERROR: REQUIRE_FIELD (ERROR_NAME); REQUIRE_FIELD (REPLY_SERIAL); break; case DBUS_MESSAGE_TYPE_METHOD_RETURN: REQUIRE_FIELD (REPLY_SERIAL); break; default: /* other message types allowed but ignored */ break; } return DBUS_VALID; }
@@ -1468,14 +1468,20 @@ void _dbus_header_byteswap (DBusHeader *header, int new_order) { + unsigned char byte_order; + if (header->byte_order == new_order) return; + byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET); + _dbus_assert (header->byte_order == byte_order); + _dbus_marshal_byteswap (&_dbus_header_signature_str, 0, header->byte_order, new_order, &header->data, 0); + _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order); header->byte_order = new_order; }
CWE-20
null
null
2,201
correct_header_padding (DBusHeader *header) { int unpadded_len; _dbus_assert (header->padding == 7); _dbus_string_shorten (&header->data, header->padding); unpadded_len = _dbus_string_get_length (&header->data); if (!_dbus_string_align_length (&header->data, 8)) _dbus_assert_not_reached ("couldn't pad header though enough padding was preallocated"); header->padding = _dbus_string_get_length (&header->data) - unpadded_len; }
DoS +Info
0
correct_header_padding (DBusHeader *header) { int unpadded_len; _dbus_assert (header->padding == 7); _dbus_string_shorten (&header->data, header->padding); unpadded_len = _dbus_string_get_length (&header->data); if (!_dbus_string_align_length (&header->data, 8)) _dbus_assert_not_reached ("couldn't pad header though enough padding was preallocated"); header->padding = _dbus_string_get_length (&header->data) - unpadded_len; }
@@ -1468,14 +1468,20 @@ void _dbus_header_byteswap (DBusHeader *header, int new_order) { + unsigned char byte_order; + if (header->byte_order == new_order) return; + byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET); + _dbus_assert (header->byte_order == byte_order); + _dbus_marshal_byteswap (&_dbus_header_signature_str, 0, header->byte_order, new_order, &header->data, 0); + _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order); header->byte_order = new_order; }
CWE-20
null
null
2,202
find_field_for_modification (DBusHeader *header, int field, DBusTypeReader *reader, DBusTypeReader *realign_root) { dbus_bool_t retval; retval = FALSE; _dbus_type_reader_init (realign_root, header->byte_order, &_dbus_header_signature_str, FIELDS_ARRAY_SIGNATURE_OFFSET, &header->data, FIELDS_ARRAY_LENGTH_OFFSET); _dbus_type_reader_recurse (realign_root, reader); while (_dbus_type_reader_get_current_type (reader) != DBUS_TYPE_INVALID) { DBusTypeReader sub; unsigned char field_code; _dbus_type_reader_recurse (reader, &sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE); _dbus_type_reader_read_basic (&sub, &field_code); if (field_code == (unsigned) field) { _dbus_assert (_dbus_type_reader_get_current_type (reader) == DBUS_TYPE_STRUCT); retval = TRUE; goto done; } _dbus_type_reader_next (reader); } done: return retval; }
DoS +Info
0
find_field_for_modification (DBusHeader *header, int field, DBusTypeReader *reader, DBusTypeReader *realign_root) { dbus_bool_t retval; retval = FALSE; _dbus_type_reader_init (realign_root, header->byte_order, &_dbus_header_signature_str, FIELDS_ARRAY_SIGNATURE_OFFSET, &header->data, FIELDS_ARRAY_LENGTH_OFFSET); _dbus_type_reader_recurse (realign_root, reader); while (_dbus_type_reader_get_current_type (reader) != DBUS_TYPE_INVALID) { DBusTypeReader sub; unsigned char field_code; _dbus_type_reader_recurse (reader, &sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE); _dbus_type_reader_read_basic (&sub, &field_code); if (field_code == (unsigned) field) { _dbus_assert (_dbus_type_reader_get_current_type (reader) == DBUS_TYPE_STRUCT); retval = TRUE; goto done; } _dbus_type_reader_next (reader); } done: return retval; }
@@ -1468,14 +1468,20 @@ void _dbus_header_byteswap (DBusHeader *header, int new_order) { + unsigned char byte_order; + if (header->byte_order == new_order) return; + byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET); + _dbus_assert (header->byte_order == byte_order); + _dbus_marshal_byteswap (&_dbus_header_signature_str, 0, header->byte_order, new_order, &header->data, 0); + _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order); header->byte_order = new_order; }
CWE-20
null
null
2,203
set_basic_field (DBusTypeReader *reader, int field, int type, const void *value, const DBusTypeReader *realign_root) { DBusTypeReader sub; DBusTypeReader variant; _dbus_type_reader_recurse (reader, &sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE); #ifndef DBUS_DISABLE_ASSERT { unsigned char v_BYTE; _dbus_type_reader_read_basic (&sub, &v_BYTE); _dbus_assert (((int) v_BYTE) == field); } #endif if (!_dbus_type_reader_next (&sub)) _dbus_assert_not_reached ("no variant field?"); _dbus_type_reader_recurse (&sub, &variant); _dbus_assert (_dbus_type_reader_get_current_type (&variant) == type); if (!_dbus_type_reader_set_basic (&variant, value, realign_root)) return FALSE; return TRUE; }
DoS +Info
0
set_basic_field (DBusTypeReader *reader, int field, int type, const void *value, const DBusTypeReader *realign_root) { DBusTypeReader sub; DBusTypeReader variant; _dbus_type_reader_recurse (reader, &sub); _dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE); #ifndef DBUS_DISABLE_ASSERT { unsigned char v_BYTE; _dbus_type_reader_read_basic (&sub, &v_BYTE); _dbus_assert (((int) v_BYTE) == field); } #endif if (!_dbus_type_reader_next (&sub)) _dbus_assert_not_reached ("no variant field?"); _dbus_type_reader_recurse (&sub, &variant); _dbus_assert (_dbus_type_reader_get_current_type (&variant) == type); if (!_dbus_type_reader_set_basic (&variant, value, realign_root)) return FALSE; return TRUE; }
@@ -1468,14 +1468,20 @@ void _dbus_header_byteswap (DBusHeader *header, int new_order) { + unsigned char byte_order; + if (header->byte_order == new_order) return; + byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET); + _dbus_assert (header->byte_order == byte_order); + _dbus_marshal_byteswap (&_dbus_header_signature_str, 0, header->byte_order, new_order, &header->data, 0); + _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order); header->byte_order = new_order; }
CWE-20
null
null
2,204
load_and_validate_field (DBusHeader *header, int field, DBusTypeReader *variant_reader) { int type; int expected_type; const DBusString *value_str; int value_pos; int str_data_pos; dbus_uint32_t v_UINT32; int bad_string_code; dbus_bool_t (* string_validation_func) (const DBusString *str, int start, int len); /* Supposed to have been checked already */ _dbus_assert (field <= DBUS_HEADER_FIELD_LAST); _dbus_assert (field != DBUS_HEADER_FIELD_INVALID); /* Before we can cache a field, we need to know it has the right type */ type = _dbus_type_reader_get_current_type (variant_reader); _dbus_assert (_dbus_header_field_types[field].code == field); expected_type = EXPECTED_TYPE_OF_FIELD (field); if (type != expected_type) { _dbus_verbose ("Field %d should have type %d but has %d\n", field, expected_type, type); return DBUS_INVALID_HEADER_FIELD_HAS_WRONG_TYPE; } /* If the field was provided twice, we aren't happy */ if (header->fields[field].value_pos >= 0) { _dbus_verbose ("Header field %d seen a second time\n", field); return DBUS_INVALID_HEADER_FIELD_APPEARS_TWICE; } /* Now we can cache and look at the field content */ _dbus_verbose ("initially caching field %d\n", field); _dbus_header_cache_one (header, field, variant_reader); string_validation_func = NULL; /* make compiler happy that all this is initialized */ v_UINT32 = 0; value_str = NULL; value_pos = -1; str_data_pos = -1; bad_string_code = DBUS_VALID; if (expected_type == DBUS_TYPE_UINT32) { _dbus_header_get_field_basic (header, field, expected_type, &v_UINT32); } else if (expected_type == DBUS_TYPE_STRING || expected_type == DBUS_TYPE_OBJECT_PATH || expected_type == DBUS_TYPE_SIGNATURE) { _dbus_header_get_field_raw (header, field, &value_str, &value_pos); str_data_pos = _DBUS_ALIGN_VALUE (value_pos, 4) + 4; } else { _dbus_assert_not_reached ("none of the known fields should have this type"); } switch (field) { case DBUS_HEADER_FIELD_DESTINATION: string_validation_func = _dbus_validate_bus_name; bad_string_code = DBUS_INVALID_BAD_DESTINATION; break; case DBUS_HEADER_FIELD_INTERFACE: string_validation_func = _dbus_validate_interface; bad_string_code = DBUS_INVALID_BAD_INTERFACE; if (_dbus_string_equal_substring (&_dbus_local_interface_str, 0, _dbus_string_get_length (&_dbus_local_interface_str), value_str, str_data_pos)) { _dbus_verbose ("Message is on the local interface\n"); return DBUS_INVALID_USES_LOCAL_INTERFACE; } break; case DBUS_HEADER_FIELD_MEMBER: string_validation_func = _dbus_validate_member; bad_string_code = DBUS_INVALID_BAD_MEMBER; break; case DBUS_HEADER_FIELD_ERROR_NAME: string_validation_func = _dbus_validate_error_name; bad_string_code = DBUS_INVALID_BAD_ERROR_NAME; break; case DBUS_HEADER_FIELD_SENDER: string_validation_func = _dbus_validate_bus_name; bad_string_code = DBUS_INVALID_BAD_SENDER; break; case DBUS_HEADER_FIELD_PATH: /* OBJECT_PATH was validated generically due to its type */ string_validation_func = NULL; if (_dbus_string_equal_substring (&_dbus_local_path_str, 0, _dbus_string_get_length (&_dbus_local_path_str), value_str, str_data_pos)) { _dbus_verbose ("Message is from the local path\n"); return DBUS_INVALID_USES_LOCAL_PATH; } break; case DBUS_HEADER_FIELD_REPLY_SERIAL: /* Can't be 0 */ if (v_UINT32 == 0) { return DBUS_INVALID_BAD_SERIAL; } break; case DBUS_HEADER_FIELD_SIGNATURE: /* SIGNATURE validated generically due to its type */ string_validation_func = NULL; break; default: _dbus_assert_not_reached ("unknown field shouldn't be seen here"); break; } if (string_validation_func) { dbus_uint32_t len; _dbus_assert (bad_string_code != DBUS_VALID); len = _dbus_marshal_read_uint32 (value_str, value_pos, header->byte_order, NULL); #if 0 _dbus_verbose ("Validating string header field; code %d if fails\n", bad_string_code); #endif if (!(*string_validation_func) (value_str, str_data_pos, len)) return bad_string_code; } return DBUS_VALID; }
DoS +Info
0
load_and_validate_field (DBusHeader *header, int field, DBusTypeReader *variant_reader) { int type; int expected_type; const DBusString *value_str; int value_pos; int str_data_pos; dbus_uint32_t v_UINT32; int bad_string_code; dbus_bool_t (* string_validation_func) (const DBusString *str, int start, int len); /* Supposed to have been checked already */ _dbus_assert (field <= DBUS_HEADER_FIELD_LAST); _dbus_assert (field != DBUS_HEADER_FIELD_INVALID); /* Before we can cache a field, we need to know it has the right type */ type = _dbus_type_reader_get_current_type (variant_reader); _dbus_assert (_dbus_header_field_types[field].code == field); expected_type = EXPECTED_TYPE_OF_FIELD (field); if (type != expected_type) { _dbus_verbose ("Field %d should have type %d but has %d\n", field, expected_type, type); return DBUS_INVALID_HEADER_FIELD_HAS_WRONG_TYPE; } /* If the field was provided twice, we aren't happy */ if (header->fields[field].value_pos >= 0) { _dbus_verbose ("Header field %d seen a second time\n", field); return DBUS_INVALID_HEADER_FIELD_APPEARS_TWICE; } /* Now we can cache and look at the field content */ _dbus_verbose ("initially caching field %d\n", field); _dbus_header_cache_one (header, field, variant_reader); string_validation_func = NULL; /* make compiler happy that all this is initialized */ v_UINT32 = 0; value_str = NULL; value_pos = -1; str_data_pos = -1; bad_string_code = DBUS_VALID; if (expected_type == DBUS_TYPE_UINT32) { _dbus_header_get_field_basic (header, field, expected_type, &v_UINT32); } else if (expected_type == DBUS_TYPE_STRING || expected_type == DBUS_TYPE_OBJECT_PATH || expected_type == DBUS_TYPE_SIGNATURE) { _dbus_header_get_field_raw (header, field, &value_str, &value_pos); str_data_pos = _DBUS_ALIGN_VALUE (value_pos, 4) + 4; } else { _dbus_assert_not_reached ("none of the known fields should have this type"); } switch (field) { case DBUS_HEADER_FIELD_DESTINATION: string_validation_func = _dbus_validate_bus_name; bad_string_code = DBUS_INVALID_BAD_DESTINATION; break; case DBUS_HEADER_FIELD_INTERFACE: string_validation_func = _dbus_validate_interface; bad_string_code = DBUS_INVALID_BAD_INTERFACE; if (_dbus_string_equal_substring (&_dbus_local_interface_str, 0, _dbus_string_get_length (&_dbus_local_interface_str), value_str, str_data_pos)) { _dbus_verbose ("Message is on the local interface\n"); return DBUS_INVALID_USES_LOCAL_INTERFACE; } break; case DBUS_HEADER_FIELD_MEMBER: string_validation_func = _dbus_validate_member; bad_string_code = DBUS_INVALID_BAD_MEMBER; break; case DBUS_HEADER_FIELD_ERROR_NAME: string_validation_func = _dbus_validate_error_name; bad_string_code = DBUS_INVALID_BAD_ERROR_NAME; break; case DBUS_HEADER_FIELD_SENDER: string_validation_func = _dbus_validate_bus_name; bad_string_code = DBUS_INVALID_BAD_SENDER; break; case DBUS_HEADER_FIELD_PATH: /* OBJECT_PATH was validated generically due to its type */ string_validation_func = NULL; if (_dbus_string_equal_substring (&_dbus_local_path_str, 0, _dbus_string_get_length (&_dbus_local_path_str), value_str, str_data_pos)) { _dbus_verbose ("Message is from the local path\n"); return DBUS_INVALID_USES_LOCAL_PATH; } break; case DBUS_HEADER_FIELD_REPLY_SERIAL: /* Can't be 0 */ if (v_UINT32 == 0) { return DBUS_INVALID_BAD_SERIAL; } break; case DBUS_HEADER_FIELD_SIGNATURE: /* SIGNATURE validated generically due to its type */ string_validation_func = NULL; break; default: _dbus_assert_not_reached ("unknown field shouldn't be seen here"); break; } if (string_validation_func) { dbus_uint32_t len; _dbus_assert (bad_string_code != DBUS_VALID); len = _dbus_marshal_read_uint32 (value_str, value_pos, header->byte_order, NULL); #if 0 _dbus_verbose ("Validating string header field; code %d if fails\n", bad_string_code); #endif if (!(*string_validation_func) (value_str, str_data_pos, len)) return bad_string_code; } return DBUS_VALID; }
@@ -1462,14 +1462,20 @@ void _dbus_header_byteswap (DBusHeader *header, int new_order) { + unsigned char byte_order; + if (header->byte_order == new_order) return; + byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET); + _dbus_assert (header->byte_order == byte_order); + _dbus_marshal_byteswap (&_dbus_header_signature_str, 0, header->byte_order, new_order, &header->data, 0); + _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order); header->byte_order = new_order; }
CWE-20
null
null
2,205
errorexec_cleanup(i_ctx_t *i_ctx_p) { return 0; }
null
0
errorexec_cleanup(i_ctx_t *i_ctx_p) { return 0; }
@@ -661,16 +661,28 @@ again: return code; if (gs_errorname(i_ctx_p, code, &error_name) < 0) return code; /* out-of-range error code! */ - /* - * For greater Adobe compatibility, only the standard PostScript errors - * are defined in errordict; the rest are in gserrordict. + + /* If LockFilePermissions is true, we only refer to gserrordict, which + * is not accessible to Postcript jobs */ - if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || - (dict_find(perrordict, &error_name, &epref) <= 0 && - (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || - dict_find(perrordict, &error_name, &epref) <= 0)) - ) - return code; /* error name not in errordict??? */ + if (i_ctx_p->LockFilePermissions) { + if (((dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || + dict_find(perrordict, &error_name, &epref) <= 0)) + ) + return code; /* error name not in errordict??? */ + } + else { + /* + * For greater Adobe compatibility, only the standard PostScript errors + * are defined in errordict; the rest are in gserrordict. + */ + if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || + (dict_find(perrordict, &error_name, &epref) <= 0 && + (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || + dict_find(perrordict, &error_name, &epref) <= 0)) + ) + return code; /* error name not in errordict??? */ + } doref = *epref; epref = &doref; /* Push the error object on the operand stack if appropriate. */
CWE-20
null
null
2,206
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object) { long i; const ref *ep; for (i = 0; (ep = ref_stack_index(&e_stack, i)) != 0; ++i) { if (r_is_estack_mark(ep)) { if (ep->value.opproc == oparray_cleanup) { /* See oppr: above. */ uint opindex = (uint)ep[1].value.intval; if (opindex == 0) /* internal operator, ignore */ continue; op_index_ref(imemory, opindex, perror_object); return 1; } if (ep->value.opproc == oparray_no_cleanup) return 0; /* protection disabled */ if (ep->value.opproc == errorexec_cleanup) { if (r_has_type(ep + 1, t_null)) return 0; *perror_object = ep[1]; /* see .errorexec above */ return 1; } } } return 0; }
null
0
errorexec_find(i_ctx_t *i_ctx_p, ref *perror_object) { long i; const ref *ep; for (i = 0; (ep = ref_stack_index(&e_stack, i)) != 0; ++i) { if (r_is_estack_mark(ep)) { if (ep->value.opproc == oparray_cleanup) { /* See oppr: above. */ uint opindex = (uint)ep[1].value.intval; if (opindex == 0) /* internal operator, ignore */ continue; op_index_ref(imemory, opindex, perror_object); return 1; } if (ep->value.opproc == oparray_no_cleanup) return 0; /* protection disabled */ if (ep->value.opproc == errorexec_cleanup) { if (r_has_type(ep + 1, t_null)) return 0; *perror_object = ep[1]; /* see .errorexec above */ return 1; } } } return 0; }
@@ -661,16 +661,28 @@ again: return code; if (gs_errorname(i_ctx_p, code, &error_name) < 0) return code; /* out-of-range error code! */ - /* - * For greater Adobe compatibility, only the standard PostScript errors - * are defined in errordict; the rest are in gserrordict. + + /* If LockFilePermissions is true, we only refer to gserrordict, which + * is not accessible to Postcript jobs */ - if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || - (dict_find(perrordict, &error_name, &epref) <= 0 && - (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || - dict_find(perrordict, &error_name, &epref) <= 0)) - ) - return code; /* error name not in errordict??? */ + if (i_ctx_p->LockFilePermissions) { + if (((dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || + dict_find(perrordict, &error_name, &epref) <= 0)) + ) + return code; /* error name not in errordict??? */ + } + else { + /* + * For greater Adobe compatibility, only the standard PostScript errors + * are defined in errordict; the rest are in gserrordict. + */ + if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || + (dict_find(perrordict, &error_name, &epref) <= 0 && + (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || + dict_find(perrordict, &error_name, &epref) <= 0)) + ) + return code; /* error name not in errordict??? */ + } doref = *epref; epref = &doref; /* Push the error object on the operand stack if appropriate. */
CWE-20
null
null
2,207
errorexec_pop(i_ctx_t *i_ctx_p) { esp -= 2; return o_pop_estack; }
null
0
errorexec_pop(i_ctx_t *i_ctx_p) { esp -= 2; return o_pop_estack; }
@@ -661,16 +661,28 @@ again: return code; if (gs_errorname(i_ctx_p, code, &error_name) < 0) return code; /* out-of-range error code! */ - /* - * For greater Adobe compatibility, only the standard PostScript errors - * are defined in errordict; the rest are in gserrordict. + + /* If LockFilePermissions is true, we only refer to gserrordict, which + * is not accessible to Postcript jobs */ - if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || - (dict_find(perrordict, &error_name, &epref) <= 0 && - (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || - dict_find(perrordict, &error_name, &epref) <= 0)) - ) - return code; /* error name not in errordict??? */ + if (i_ctx_p->LockFilePermissions) { + if (((dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || + dict_find(perrordict, &error_name, &epref) <= 0)) + ) + return code; /* error name not in errordict??? */ + } + else { + /* + * For greater Adobe compatibility, only the standard PostScript errors + * are defined in errordict; the rest are in gserrordict. + */ + if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || + (dict_find(perrordict, &error_name, &epref) <= 0 && + (dict_find_string(systemdict, "gserrordict", &perrordict) <= 0 || + dict_find(perrordict, &error_name, &epref) <= 0)) + ) + return code; /* error name not in errordict??? */ + } doref = *epref; epref = &doref; /* Push the error object on the operand stack if appropriate. */
CWE-20
null
null
2,208
Class2Modem::Class2Modem(FaxServer& s, const ModemConfig& c) : FaxModem(s,c) { hangupCode[0] = '\0'; serviceType = 0; // must be set in derived class useExtendedDF = false; // T.32 Amendment 1 extension for data format is detectable useJP = false; // JP +FCC option support is detectable imagefd = 0; }
Exec Code
0
Class2Modem::Class2Modem(FaxServer& s, const ModemConfig& c) : FaxModem(s,c) { hangupCode[0] = '\0'; serviceType = 0; // must be set in derived class useExtendedDF = false; // T.32 Amendment 1 extension for data format is detectable useJP = false; // JP +FCC option support is detectable imagefd = 0; }
@@ -485,6 +485,15 @@ Class2Modem::parseClass2Capabilities(const char* cap, Class2Params& params, bool } else { if (jpscan == 0x1) params.jp = JP_GREY; else if (jpscan & 0x2) params.jp = JP_COLOR; + /* + * ITU T.30 does not specify that bits 16 (MR) or 31 (MMR) must be set to zero if color fax is used; + * and ITU T.32 Table 21 provides a data field, "JP", for JPEG support separate from "DF" for data + * format and does not specify that DF is meaningless in DCS when JP is used; but because T.4/T.6 + * (MH/MR/MMR), JBIG, and JPEG are distinct formats from each other, we must conclude that any + * indication of JPEG in DCS must, therefore, invalidate any indication in DCS of MH/MR/MMR/JBIG. + * Otherwise, having both df and jp be non-zero will be confusing and possibly cause problems. + */ + if (params.jp != JP_NONE) params.df = 0; // Yes, this is DF_1DMH, but there is no "DF_NONE". } return (true); } else {
CWE-20
null
null
2,209
FaxModem::initializeDecoder(const Class2Params& params) { setupDecoder(recvFillOrder, params.is2D(), (params.df == DF_2DMMR)); u_int rowpixels = params.pageWidth(); // NB: assume rowpixels <= 4864 tiff_runlen_t runs[2*4864]; // run arrays for cur+ref rows setRuns(runs, runs+4864, rowpixels); setIsECM(false); resetLineCounts(); }
Exec Code
0
FaxModem::initializeDecoder(const Class2Params& params) { setupDecoder(recvFillOrder, params.is2D(), (params.df == DF_2DMMR)); u_int rowpixels = params.pageWidth(); // NB: assume rowpixels <= 4864 tiff_runlen_t runs[2*4864]; // run arrays for cur+ref rows setRuns(runs, runs+4864, rowpixels); setIsECM(false); resetLineCounts(); }
@@ -38,6 +38,7 @@ #include <ctype.h> #define RCVBUFSIZ (32*1024) // XXX +#define COLORBUFSIZ (2000*1024) // 1MB is not big enough static void setupCompression(TIFF*, u_int, u_int, uint32); @@ -356,7 +357,7 @@ FaxModem::recvPageDLEData(TIFF* tif, bool checkQuality, * rather fax-specific. */ recvEOLCount = 0; - recvRow = (u_char*) malloc(1024*1000); // 1M should do it? + recvRow = (u_char*) malloc(COLORBUFSIZ); fxAssert(recvRow != NULL, "page buffering error (JPEG page)."); recvPageStart = recvRow; } @@ -408,8 +409,12 @@ FaxModem::recvPageDLEData(TIFF* tif, bool checkQuality, if (params.df == DF_JBIG) { flushRawData(tif, 0, (const u_char*) buf, cc); } else { - memcpy(recvRow, (const char*) buf, cc); - recvRow += cc; + /* We don't support reception of a JPEG page bigger than COLORBUFSIZ. */ + if (recvRow + cc - recvPageStart > COLORBUFSIZ) cc = recvPageStart + COLORBUFSIZ - recvRow; + if (cc > 0) { + memcpy(recvRow, (const char*) buf, cc); + recvRow += cc; + } } } while (!fin); if (params.df == DF_JBIG) clearSDNORMCount(); @@ -987,7 +992,7 @@ FaxModem::writeECMData(TIFF* tif, u_char* buf, u_int cc, const Class2Params& par case JP_GREY+4: case JP_COLOR+4: recvEOLCount = 0; - recvRow = (u_char*) malloc(1024*1000); // 1M should do it? + recvRow = (u_char*) malloc(COLORBUFSIZ); fxAssert(recvRow != NULL, "page buffering error (JPEG page)."); recvPageStart = recvRow; setupStartPage(tif, params); @@ -1039,14 +1044,20 @@ FaxModem::writeECMData(TIFF* tif, u_char* buf, u_int cc, const Class2Params& par } break; } - if (params.jp != JP_GREY && params.jp != JP_COLOR) { - flushRawData(tif, 0, (const u_char*) buf, cc); - } else { - memcpy(recvRow, (const char*) buf, cc); - recvRow += cc; - } - if (seq & 2 && (params.jp == JP_GREY || params.jp == JP_COLOR)) { - fixupJPEG(tif); + switch (dataform) { + case JP_GREY+4: + case JP_COLOR+4: + /* We don't support reception of a JPEG page bigger than COLORBUFSIZ. */ + if (recvRow + cc - recvPageStart > COLORBUFSIZ) cc = recvPageStart + COLORBUFSIZ - recvRow; + if (cc > 0) { + memcpy(recvRow, (const char*) buf, cc); + recvRow += cc; + } + if (seq & 2) fixupJPEG(tif); + break; + default: + flushRawData(tif, 0, (const u_char*) buf, cc); + break; } }
CWE-20
null
null
2,210
FaxModem::recvEndPage(TIFF* tif, const Class2Params& params) { /* * FAXRECVPARAMS is limited to a 32-bit value, and as that is quite * limited in comparison to all possible fax parameters, FAXDCS is * intended to be used to discern most fax parameters. The DCS * signal, however, does not contain bitrate information when V.34-Fax * is used, so tiffinfo, for example, will use FAXDCS for all fax * parameters except for bitrate which comes from FAXRECVPARAMS. * * As FAXDCS is more recent in libtiff than is FAXRECVPARAMS some * installations may not be able to use FAXDCS, in which case those * installations will be limited to the 32-bit restraints. */ #ifdef TIFFTAG_FAXRECVPARAMS TIFFSetField(tif, TIFFTAG_FAXRECVPARAMS, (uint32) params.encode()); #endif #ifdef TIFFTAG_FAXDCS FaxParams pageparams = FaxParams(params); fxStr faxdcs = ""; pageparams.asciiEncode(faxdcs); TIFFSetField(tif, TIFFTAG_FAXDCS, (const char*) faxdcs); #endif #ifdef TIFFTAG_FAXSUBADDRESS if (sub != "") TIFFSetField(tif, TIFFTAG_FAXSUBADDRESS, (const char*) sub); #endif #ifdef TIFFTAG_FAXRECVTIME TIFFSetField(tif, TIFFTAG_FAXRECVTIME, (uint32) server.setPageTransferTime()); #endif }
Exec Code
0
FaxModem::recvEndPage(TIFF* tif, const Class2Params& params) { /* * FAXRECVPARAMS is limited to a 32-bit value, and as that is quite * limited in comparison to all possible fax parameters, FAXDCS is * intended to be used to discern most fax parameters. The DCS * signal, however, does not contain bitrate information when V.34-Fax * is used, so tiffinfo, for example, will use FAXDCS for all fax * parameters except for bitrate which comes from FAXRECVPARAMS. * * As FAXDCS is more recent in libtiff than is FAXRECVPARAMS some * installations may not be able to use FAXDCS, in which case those * installations will be limited to the 32-bit restraints. */ #ifdef TIFFTAG_FAXRECVPARAMS TIFFSetField(tif, TIFFTAG_FAXRECVPARAMS, (uint32) params.encode()); #endif #ifdef TIFFTAG_FAXDCS FaxParams pageparams = FaxParams(params); fxStr faxdcs = ""; pageparams.asciiEncode(faxdcs); TIFFSetField(tif, TIFFTAG_FAXDCS, (const char*) faxdcs); #endif #ifdef TIFFTAG_FAXSUBADDRESS if (sub != "") TIFFSetField(tif, TIFFTAG_FAXSUBADDRESS, (const char*) sub); #endif #ifdef TIFFTAG_FAXRECVTIME TIFFSetField(tif, TIFFTAG_FAXRECVTIME, (uint32) server.setPageTransferTime()); #endif }
@@ -38,6 +38,7 @@ #include <ctype.h> #define RCVBUFSIZ (32*1024) // XXX +#define COLORBUFSIZ (2000*1024) // 1MB is not big enough static void setupCompression(TIFF*, u_int, u_int, uint32); @@ -356,7 +357,7 @@ FaxModem::recvPageDLEData(TIFF* tif, bool checkQuality, * rather fax-specific. */ recvEOLCount = 0; - recvRow = (u_char*) malloc(1024*1000); // 1M should do it? + recvRow = (u_char*) malloc(COLORBUFSIZ); fxAssert(recvRow != NULL, "page buffering error (JPEG page)."); recvPageStart = recvRow; } @@ -408,8 +409,12 @@ FaxModem::recvPageDLEData(TIFF* tif, bool checkQuality, if (params.df == DF_JBIG) { flushRawData(tif, 0, (const u_char*) buf, cc); } else { - memcpy(recvRow, (const char*) buf, cc); - recvRow += cc; + /* We don't support reception of a JPEG page bigger than COLORBUFSIZ. */ + if (recvRow + cc - recvPageStart > COLORBUFSIZ) cc = recvPageStart + COLORBUFSIZ - recvRow; + if (cc > 0) { + memcpy(recvRow, (const char*) buf, cc); + recvRow += cc; + } } } while (!fin); if (params.df == DF_JBIG) clearSDNORMCount(); @@ -987,7 +992,7 @@ FaxModem::writeECMData(TIFF* tif, u_char* buf, u_int cc, const Class2Params& par case JP_GREY+4: case JP_COLOR+4: recvEOLCount = 0; - recvRow = (u_char*) malloc(1024*1000); // 1M should do it? + recvRow = (u_char*) malloc(COLORBUFSIZ); fxAssert(recvRow != NULL, "page buffering error (JPEG page)."); recvPageStart = recvRow; setupStartPage(tif, params); @@ -1039,14 +1044,20 @@ FaxModem::writeECMData(TIFF* tif, u_char* buf, u_int cc, const Class2Params& par } break; } - if (params.jp != JP_GREY && params.jp != JP_COLOR) { - flushRawData(tif, 0, (const u_char*) buf, cc); - } else { - memcpy(recvRow, (const char*) buf, cc); - recvRow += cc; - } - if (seq & 2 && (params.jp == JP_GREY || params.jp == JP_COLOR)) { - fixupJPEG(tif); + switch (dataform) { + case JP_GREY+4: + case JP_COLOR+4: + /* We don't support reception of a JPEG page bigger than COLORBUFSIZ. */ + if (recvRow + cc - recvPageStart > COLORBUFSIZ) cc = recvPageStart + COLORBUFSIZ - recvRow; + if (cc > 0) { + memcpy(recvRow, (const char*) buf, cc); + recvRow += cc; + } + if (seq & 2) fixupJPEG(tif); + break; + default: + flushRawData(tif, 0, (const u_char*) buf, cc); + break; } }
CWE-20
null
null
2,211
z2grestoreall(i_ctx_t *i_ctx_p) { for (;;) { if (!restore_page_device(igs, gs_gstate_saved(igs))) { bool done = !gs_gstate_saved(gs_gstate_saved(igs)); gs_grestore(igs); if (done) break; } else return push_callout(i_ctx_p, "%grestoreallpagedevice"); } return 0; }
Exec Code Bypass
0
z2grestoreall(i_ctx_t *i_ctx_p) { for (;;) { if (!restore_page_device(igs, gs_gstate_saved(igs))) { bool done = !gs_gstate_saved(gs_gstate_saved(igs)); gs_grestore(igs); if (done) break; } else return push_callout(i_ctx_p, "%grestoreallpagedevice"); } return 0; }
@@ -312,6 +312,9 @@ z2grestoreall(i_ctx_t *i_ctx_p) static int z2restore(i_ctx_t *i_ctx_p) { + os_ptr op = osp; + check_type(*op, t_save); + while (gs_gstate_saved(gs_gstate_saved(igs))) { if (restore_page_device(igs, gs_gstate_saved(igs))) return push_callout(i_ctx_p, "%restore1pagedevice");
CWE-78
null
null
2,212
static RELOC_PTRS_WITH(device_forward_reloc_ptrs, gx_device_forward *fdev) { fdev->target = gx_device_reloc_ptr(fdev->target, gcst); }
Exec Code Bypass
0
static RELOC_PTRS_WITH(device_forward_reloc_ptrs, gx_device_forward *fdev) { fdev->target = gx_device_reloc_ptr(fdev->target, gcst); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,213
gs_closedevice(gx_device * dev) { int code = 0; if (dev->is_open) { code = (*dev_proc(dev, close_device))(dev); dev->is_open = false; if (code < 0) return_error(code); } return code; }
Exec Code Bypass
0
gs_closedevice(gx_device * dev) { int code = 0; if (dev->is_open) { code = (*dev_proc(dev, close_device))(dev); dev->is_open = false; if (code < 0) return_error(code); } return code; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,214
gs_copydevice(gx_device ** pnew_dev, const gx_device * dev, gs_memory_t * mem) { return gs_copydevice2(pnew_dev, dev, false, mem); }
Exec Code Bypass
0
gs_copydevice(gx_device ** pnew_dev, const gx_device * dev, gs_memory_t * mem) { return gs_copydevice2(pnew_dev, dev, false, mem); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,215
gs_copydevice2(gx_device ** pnew_dev, const gx_device * dev, bool keep_open, gs_memory_t * mem) { gx_device *new_dev; const gs_memory_struct_type_t *std = dev->stype; const gs_memory_struct_type_t *new_std; gs_memory_struct_type_t *a_std = 0; int code; if (dev->stype_is_dynamic) { /* * We allocated the stype for this device previously. * Just allocate a new stype and copy the old one into it. */ a_std = (gs_memory_struct_type_t *) gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); *a_std = *std; new_std = a_std; } else if (std != 0 && std->ssize == dev->params_size) { /* Use the static stype. */ new_std = std; } else { /* We need to figure out or adjust the stype. */ a_std = (gs_memory_struct_type_t *) gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); gx_device_make_struct_type(a_std, dev); new_std = a_std; } /* * Because command list devices have complicated internal pointer * structures, we allocate all device instances as immovable. */ new_dev = gs_alloc_struct_immovable(mem, gx_device, new_std, "gs_copydevice(device)"); if (new_dev == 0) { gs_free_object(mem->non_gc_memory, a_std, "gs_copydevice(stype)"); return_error(gs_error_VMerror); } gx_device_init(new_dev, dev, mem, false); gx_device_set_procs(new_dev); new_dev->stype = new_std; new_dev->stype_is_dynamic = new_std != std; /* * keep_open is very dangerous. On the other hand, so is copydevice in * general, since it just copies the bits without any regard to pointers * (including self-pointers) that they may contain. We handle this by * making the default finish_copydevice forbid copying of anything other * than the device prototype. */ new_dev->is_open = dev->is_open && keep_open; fill_dev_proc(new_dev, finish_copydevice, gx_default_finish_copydevice); code = dev_proc(new_dev, finish_copydevice)(new_dev, dev); if (code < 0) { gs_free_object(mem, new_dev, "gs_copydevice(device)"); #if 0 /* gs_free_object above calls gx_device_finalize, which closes the device and releaszes its stype, i.e. a_std. */ if (a_std) gs_free_object(dev->memory->non_gc_memory, a_std, "gs_copydevice(stype)"); #endif return code; } *pnew_dev = new_dev; return 0; }
Exec Code Bypass
0
gs_copydevice2(gx_device ** pnew_dev, const gx_device * dev, bool keep_open, gs_memory_t * mem) { gx_device *new_dev; const gs_memory_struct_type_t *std = dev->stype; const gs_memory_struct_type_t *new_std; gs_memory_struct_type_t *a_std = 0; int code; if (dev->stype_is_dynamic) { /* * We allocated the stype for this device previously. * Just allocate a new stype and copy the old one into it. */ a_std = (gs_memory_struct_type_t *) gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); *a_std = *std; new_std = a_std; } else if (std != 0 && std->ssize == dev->params_size) { /* Use the static stype. */ new_std = std; } else { /* We need to figure out or adjust the stype. */ a_std = (gs_memory_struct_type_t *) gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); gx_device_make_struct_type(a_std, dev); new_std = a_std; } /* * Because command list devices have complicated internal pointer * structures, we allocate all device instances as immovable. */ new_dev = gs_alloc_struct_immovable(mem, gx_device, new_std, "gs_copydevice(device)"); if (new_dev == 0) { gs_free_object(mem->non_gc_memory, a_std, "gs_copydevice(stype)"); return_error(gs_error_VMerror); } gx_device_init(new_dev, dev, mem, false); gx_device_set_procs(new_dev); new_dev->stype = new_std; new_dev->stype_is_dynamic = new_std != std; /* * keep_open is very dangerous. On the other hand, so is copydevice in * general, since it just copies the bits without any regard to pointers * (including self-pointers) that they may contain. We handle this by * making the default finish_copydevice forbid copying of anything other * than the device prototype. */ new_dev->is_open = dev->is_open && keep_open; fill_dev_proc(new_dev, finish_copydevice, gx_default_finish_copydevice); code = dev_proc(new_dev, finish_copydevice)(new_dev, dev); if (code < 0) { gs_free_object(mem, new_dev, "gs_copydevice(device)"); #if 0 /* gs_free_object above calls gx_device_finalize, which closes the device and releaszes its stype, i.e. a_std. */ if (a_std) gs_free_object(dev->memory->non_gc_memory, a_std, "gs_copydevice(stype)"); #endif return code; } *pnew_dev = new_dev; return 0; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,216
gs_copyscanlines(gx_device * dev, int start_y, byte * data, uint size, int *plines_copied, uint * pbytes_copied) { uint line_size = gx_device_raster(dev, 0); uint count = size / line_size; uint i; byte *dest = data; for (i = 0; i < count; i++, dest += line_size) { int code = (*dev_proc(dev, get_bits)) (dev, start_y + i, dest, NULL); if (code < 0) { /* Might just be an overrun. */ if (start_y + i == dev->height) break; return_error(code); } } if (plines_copied != NULL) *plines_copied = i; if (pbytes_copied != NULL) *pbytes_copied = i * line_size; return 0; }
Exec Code Bypass
0
gs_copyscanlines(gx_device * dev, int start_y, byte * data, uint size, int *plines_copied, uint * pbytes_copied) { uint line_size = gx_device_raster(dev, 0); uint count = size / line_size; uint i; byte *dest = data; for (i = 0; i < count; i++, dest += line_size) { int code = (*dev_proc(dev, get_bits)) (dev, start_y + i, dest, NULL); if (code < 0) { /* Might just be an overrun. */ if (start_y + i == dev->height) break; return_error(code); } } if (plines_copied != NULL) *plines_copied = i; if (pbytes_copied != NULL) *pbytes_copied = i * line_size; return 0; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,217
gs_currentdevice(const gs_gstate * pgs) { return pgs->device; }
Exec Code Bypass
0
gs_currentdevice(const gs_gstate * pgs) { return pgs->device; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,218
gs_deviceinitialmatrix(gx_device * dev, gs_matrix * pmat) { fill_dev_proc(dev, get_initial_matrix, gx_default_get_initial_matrix); (*dev_proc(dev, get_initial_matrix)) (dev, pmat); }
Exec Code Bypass
0
gs_deviceinitialmatrix(gx_device * dev, gs_matrix * pmat) { fill_dev_proc(dev, get_initial_matrix, gx_default_get_initial_matrix); (*dev_proc(dev, get_initial_matrix)) (dev, pmat); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,219
gs_devicename(const gx_device * dev) { return dev->dname; }
Exec Code Bypass
0
gs_devicename(const gx_device * dev) { return dev->dname; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,220
gs_flushpage(gs_gstate * pgs) { gx_device *dev = gs_currentdevice(pgs); return (*dev_proc(dev, sync_output)) (dev); }
Exec Code Bypass
0
gs_flushpage(gs_gstate * pgs) { gx_device *dev = gs_currentdevice(pgs); return (*dev_proc(dev, sync_output)) (dev); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,221
gs_getdefaultdevice(void) { return gs_getdefaultlibdevice(NULL); }
Exec Code Bypass
0
gs_getdefaultdevice(void) { return gs_getdefaultlibdevice(NULL); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,222
gs_getdefaultlibdevice(gs_memory_t *mem) { const gx_device *const *list; int count = gs_lib_device_list(&list, NULL); const char *name, *end, *fin; int i; /* Search the compiled in device list for a known device name */ /* In the case the lib ctx hasn't been initialised */ if (mem && mem->gs_lib_ctx && mem->gs_lib_ctx->default_device_list) { name = mem->gs_lib_ctx->default_device_list; fin = name + strlen(name); } else { name = gs_dev_defaults; fin = name + strlen(name); } /* iterate through each name in the string */ while (name < fin) { /* split a name from any whitespace */ while ((name < fin) && (*name == ' ' || *name == '\t')) name++; end = name; while ((end < fin) && (*end != ' ') && (*end != '\t')) end++; /* return any matches */ for (i = 0; i < count; i++) if ((end - name) == strlen(list[i]->dname)) if (!memcmp(name, list[i]->dname, end - name)) return gs_getdevice(i); /* otherwise, try the next device name */ name = end; } /* Fall back to the first device in the list. */ return gs_getdevice(0); }
Exec Code Bypass
0
gs_getdefaultlibdevice(gs_memory_t *mem) { const gx_device *const *list; int count = gs_lib_device_list(&list, NULL); const char *name, *end, *fin; int i; /* Search the compiled in device list for a known device name */ /* In the case the lib ctx hasn't been initialised */ if (mem && mem->gs_lib_ctx && mem->gs_lib_ctx->default_device_list) { name = mem->gs_lib_ctx->default_device_list; fin = name + strlen(name); } else { name = gs_dev_defaults; fin = name + strlen(name); } /* iterate through each name in the string */ while (name < fin) { /* split a name from any whitespace */ while ((name < fin) && (*name == ' ' || *name == '\t')) name++; end = name; while ((end < fin) && (*end != ' ') && (*end != '\t')) end++; /* return any matches */ for (i = 0; i < count; i++) if ((end - name) == strlen(list[i]->dname)) if (!memcmp(name, list[i]->dname, end - name)) return gs_getdevice(i); /* otherwise, try the next device name */ name = end; } /* Fall back to the first device in the list. */ return gs_getdevice(0); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,223
gs_getdevice(int index) { const gx_device *const *list; int count = gs_lib_device_list(&list, NULL); if (index < 0 || index >= count) return 0; /* index out of range */ return list[index]; }
Exec Code Bypass
0
gs_getdevice(int index) { const gx_device *const *list; int count = gs_lib_device_list(&list, NULL); if (index < 0 || index >= count) return 0; /* index out of range */ return list[index]; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,224
gs_gstate_putdeviceparams(gs_gstate *pgs, gx_device *dev, gs_param_list *plist) { int code; gx_device *dev2; if (dev) dev2 = dev; else dev2 = pgs->device; code = gs_putdeviceparams(dev2, plist); if (code >= 0) gs_gstate_update_device(pgs, dev2); return code; }
Exec Code Bypass
0
gs_gstate_putdeviceparams(gs_gstate *pgs, gx_device *dev, gs_param_list *plist) { int code; gx_device *dev2; if (dev) dev2 = dev; else dev2 = pgs->device; code = gs_putdeviceparams(dev2, plist); if (code >= 0) gs_gstate_update_device(pgs, dev2); return code; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,225
gs_gstate_update_device(gs_gstate *pgs, gx_device *dev) { gx_set_cmap_procs(pgs, dev); gx_unset_both_dev_colors(pgs); }
Exec Code Bypass
0
gs_gstate_update_device(gs_gstate *pgs, gx_device *dev) { gx_set_cmap_procs(pgs, dev); gx_unset_both_dev_colors(pgs); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,226
bool gs_is_null_device(gx_device *dev) { /* Assuming null_fill_path isn't used elswhere. */ return dev->procs.fill_path == gs_null_device.procs.fill_path; }
Exec Code Bypass
0
bool gs_is_null_device(gx_device *dev) { /* Assuming null_fill_path isn't used elswhere. */ return dev->procs.fill_path == gs_null_device.procs.fill_path; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,227
gs_make_null_device(gx_device_null *dev_null, gx_device *dev, gs_memory_t * mem) { gx_device_init((gx_device *)dev_null, (const gx_device *)&gs_null_device, mem, true); gx_device_set_target((gx_device_forward *)dev_null, dev); if (dev) { /* The gx_device_copy_color_params() call below should probably copy over these new-style color mapping procs, as well as the old-style (map_rgb_color and friends). However, the change was made here instead, to minimize the potential impact of the patch. */ gx_device *dn = (gx_device *)dev_null; set_dev_proc(dn, get_color_mapping_procs, gx_forward_get_color_mapping_procs); set_dev_proc(dn, get_color_comp_index, gx_forward_get_color_comp_index); set_dev_proc(dn, encode_color, gx_forward_encode_color); set_dev_proc(dn, decode_color, gx_forward_decode_color); set_dev_proc(dn, get_profile, gx_forward_get_profile); set_dev_proc(dn, set_graphics_type_tag, gx_forward_set_graphics_type_tag); set_dev_proc(dn, begin_transparency_group, gx_default_begin_transparency_group); set_dev_proc(dn, end_transparency_group, gx_default_end_transparency_group); set_dev_proc(dn, begin_transparency_mask, gx_default_begin_transparency_mask); set_dev_proc(dn, end_transparency_mask, gx_default_end_transparency_mask); set_dev_proc(dn, discard_transparency_layer, gx_default_discard_transparency_layer); set_dev_proc(dn, pattern_manage, gx_default_pattern_manage); set_dev_proc(dn, push_transparency_state, gx_default_push_transparency_state); set_dev_proc(dn, pop_transparency_state, gx_default_pop_transparency_state); set_dev_proc(dn, put_image, gx_default_put_image); set_dev_proc(dn, copy_planes, gx_default_copy_planes); set_dev_proc(dn, copy_alpha_hl_color, gx_default_no_copy_alpha_hl_color); dn->graphics_type_tag = dev->graphics_type_tag; /* initialize to same as target */ gx_device_copy_color_params(dn, dev); } }
Exec Code Bypass
0
gs_make_null_device(gx_device_null *dev_null, gx_device *dev, gs_memory_t * mem) { gx_device_init((gx_device *)dev_null, (const gx_device *)&gs_null_device, mem, true); gx_device_set_target((gx_device_forward *)dev_null, dev); if (dev) { /* The gx_device_copy_color_params() call below should probably copy over these new-style color mapping procs, as well as the old-style (map_rgb_color and friends). However, the change was made here instead, to minimize the potential impact of the patch. */ gx_device *dn = (gx_device *)dev_null; set_dev_proc(dn, get_color_mapping_procs, gx_forward_get_color_mapping_procs); set_dev_proc(dn, get_color_comp_index, gx_forward_get_color_comp_index); set_dev_proc(dn, encode_color, gx_forward_encode_color); set_dev_proc(dn, decode_color, gx_forward_decode_color); set_dev_proc(dn, get_profile, gx_forward_get_profile); set_dev_proc(dn, set_graphics_type_tag, gx_forward_set_graphics_type_tag); set_dev_proc(dn, begin_transparency_group, gx_default_begin_transparency_group); set_dev_proc(dn, end_transparency_group, gx_default_end_transparency_group); set_dev_proc(dn, begin_transparency_mask, gx_default_begin_transparency_mask); set_dev_proc(dn, end_transparency_mask, gx_default_end_transparency_mask); set_dev_proc(dn, discard_transparency_layer, gx_default_discard_transparency_layer); set_dev_proc(dn, pattern_manage, gx_default_pattern_manage); set_dev_proc(dn, push_transparency_state, gx_default_push_transparency_state); set_dev_proc(dn, pop_transparency_state, gx_default_pop_transparency_state); set_dev_proc(dn, put_image, gx_default_put_image); set_dev_proc(dn, copy_planes, gx_default_copy_planes); set_dev_proc(dn, copy_alpha_hl_color, gx_default_no_copy_alpha_hl_color); dn->graphics_type_tag = dev->graphics_type_tag; /* initialize to same as target */ gx_device_copy_color_params(dn, dev); } }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,228
gs_opendevice(gx_device *dev) { if (dev->is_open) return 0; check_device_separable(dev); gx_device_fill_in_procs(dev); { int code = (*dev_proc(dev, open_device))(dev); if (code < 0) return_error(code); dev->is_open = true; return 1; } }
Exec Code Bypass
0
gs_opendevice(gx_device *dev) { if (dev->is_open) return 0; check_device_separable(dev); gx_device_fill_in_procs(dev); { int code = (*dev_proc(dev, open_device))(dev); if (code < 0) return_error(code); dev->is_open = true; return 1; } }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,229
gs_output_page(gs_gstate * pgs, int num_copies, int flush) { gx_device *dev = gs_currentdevice(pgs); cmm_dev_profile_t *dev_profile; int code; /* for devices that hook 'fill_path' in order to pick up gs_gstate */ /* values such as dev_ht (such as tiffsep1), make a dummy call here */ /* to make sure that it has been called at least once */ code = gs_gsave(pgs); if (code < 0) return code; if (((code = gs_newpath(pgs)) < 0) || ((code = gs_moveto(pgs, 0.0, 0.0)) < 0) || ((code = gs_setgray(pgs, 0.0)) < 0) || ((code = gs_fill(pgs)) < 0)) { gs_grestore(pgs); return code; } code = gs_grestore(pgs); if (code < 0) return code; if (dev->IgnoreNumCopies) num_copies = 1; if ((code = (*dev_proc(dev, output_page)) (dev, num_copies, flush)) < 0) return code; code = dev_proc(dev, get_profile)(dev, &(dev_profile)); if (code < 0) return code; if (dev_profile->graydetection && !dev_profile->pageneutralcolor) { dev_profile->pageneutralcolor = true; /* start detecting again */ code = gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev); } return code; }
Exec Code Bypass
0
gs_output_page(gs_gstate * pgs, int num_copies, int flush) { gx_device *dev = gs_currentdevice(pgs); cmm_dev_profile_t *dev_profile; int code; /* for devices that hook 'fill_path' in order to pick up gs_gstate */ /* values such as dev_ht (such as tiffsep1), make a dummy call here */ /* to make sure that it has been called at least once */ code = gs_gsave(pgs); if (code < 0) return code; if (((code = gs_newpath(pgs)) < 0) || ((code = gs_moveto(pgs, 0.0, 0.0)) < 0) || ((code = gs_setgray(pgs, 0.0)) < 0) || ((code = gs_fill(pgs)) < 0)) { gs_grestore(pgs); return code; } code = gs_grestore(pgs); if (code < 0) return code; if (dev->IgnoreNumCopies) num_copies = 1; if ((code = (*dev_proc(dev, output_page)) (dev, num_copies, flush)) < 0) return code; code = dev_proc(dev, get_profile)(dev, &(dev_profile)); if (code < 0) return code; if (dev_profile->graydetection && !dev_profile->pageneutralcolor) { dev_profile->pageneutralcolor = true; /* start detecting again */ code = gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev); } return code; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,230
gs_setdevice_no_init(gs_gstate * pgs, gx_device * dev) { /* * Just set the device, possibly changing color space but no other * device parameters. * * Make sure we don't close the device if dev == pgs->device * This could be done by allowing the rc_assign to close the * old 'dev' if the rc goes to 0 (via the device structure's * finalization procedure), but then the 'code' from the dev * closedevice would not be propagated up. We want to allow * the code to be handled, particularly for the pdfwrite * device. */ if (pgs->device != NULL && pgs->device->rc.ref_count == 1 && pgs->device != dev) { int code = gs_closedevice(pgs->device); if (code < 0) return code; } rc_assign(pgs->device, dev, "gs_setdevice_no_init"); gs_gstate_update_device(pgs, dev); return pgs->overprint ? gs_do_set_overprint(pgs) : 0; }
Exec Code Bypass
0
gs_setdevice_no_init(gs_gstate * pgs, gx_device * dev) { /* * Just set the device, possibly changing color space but no other * device parameters. * * Make sure we don't close the device if dev == pgs->device * This could be done by allowing the rc_assign to close the * old 'dev' if the rc goes to 0 (via the device structure's * finalization procedure), but then the 'code' from the dev * closedevice would not be propagated up. We want to allow * the code to be handled, particularly for the pdfwrite * device. */ if (pgs->device != NULL && pgs->device->rc.ref_count == 1 && pgs->device != dev) { int code = gs_closedevice(pgs->device); if (code < 0) return code; } rc_assign(pgs->device, dev, "gs_setdevice_no_init"); gs_gstate_update_device(pgs, dev); return pgs->overprint ? gs_do_set_overprint(pgs) : 0; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,231
bool gx_color_info_equal(const gx_device_color_info * p1, const gx_device_color_info * p2) { if (p1->anti_alias.graphics_bits != p2->anti_alias.graphics_bits) return false; if (p1->anti_alias.text_bits != p2->anti_alias.text_bits) return false; if (p1->black_component != p2->black_component) return false; if (strcmp(p1->cm_name, p2->cm_name) != 0) return false; if (p1->depth != p2->depth) return false; if (p1->dither_colors != p2->dither_colors) return false; if (p1->dither_grays != p2->dither_grays) return false; if (p1->gray_index != p2->gray_index) return false; if (p1->max_color != p2->max_color) return false; if (p1->max_components != p2->max_components) return false; if (p1->opmode != p2->opmode) return false; if (p1->polarity != p2->polarity) return false; if (p1->process_comps != p2->process_comps) return false; if (p1->separable_and_linear != p2->separable_and_linear) return false; if (p1->use_antidropout_downscaler != p2->use_antidropout_downscaler) return false; return true; }
Exec Code Bypass
0
bool gx_color_info_equal(const gx_device_color_info * p1, const gx_device_color_info * p2) { if (p1->anti_alias.graphics_bits != p2->anti_alias.graphics_bits) return false; if (p1->anti_alias.text_bits != p2->anti_alias.text_bits) return false; if (p1->black_component != p2->black_component) return false; if (strcmp(p1->cm_name, p2->cm_name) != 0) return false; if (p1->depth != p2->depth) return false; if (p1->dither_colors != p2->dither_colors) return false; if (p1->dither_grays != p2->dither_grays) return false; if (p1->gray_index != p2->gray_index) return false; if (p1->max_color != p2->max_color) return false; if (p1->max_components != p2->max_components) return false; if (p1->opmode != p2->opmode) return false; if (p1->polarity != p2->polarity) return false; if (p1->process_comps != p2->process_comps) return false; if (p1->separable_and_linear != p2->separable_and_linear) return false; if (p1->use_antidropout_downscaler != p2->use_antidropout_downscaler) return false; return true; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,232
gx_device_adjust_resolution(gx_device * dev, int actual_width, int actual_height, int fit) { double width_ratio = (double)actual_width / dev->width; double height_ratio = (double)actual_height / dev->height; double ratio = (fit ? min(width_ratio, height_ratio) : max(width_ratio, height_ratio)); dev->HWResolution[0] *= ratio; dev->HWResolution[1] *= ratio; gx_device_set_width_height(dev, actual_width, actual_height); return 0; }
Exec Code Bypass
0
gx_device_adjust_resolution(gx_device * dev, int actual_width, int actual_height, int fit) { double width_ratio = (double)actual_width / dev->width; double height_ratio = (double)actual_height / dev->height; double ratio = (fit ? min(width_ratio, height_ratio) : max(width_ratio, height_ratio)); dev->HWResolution[0] *= ratio; dev->HWResolution[1] *= ratio; gx_device_set_width_height(dev, actual_width, actual_height); return 0; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,233
gx_device_close_output_file(const gx_device * dev, const char *fname, FILE *file) { gs_parsed_file_name_t parsed; const char *fmt; int code = gx_parse_output_file_name(&parsed, &fmt, fname, strlen(fname), dev->memory); if (code < 0) return code; if (parsed.iodev) { if (!strcmp(parsed.iodev->dname, "%stdout%")) return 0; /* NOTE: fname is unsubstituted if the name has any %nnd formats. */ if (parsed.iodev != iodev_default(dev->memory)) return parsed.iodev->procs.fclose(parsed.iodev, file); } gp_close_printer(dev->memory, file, (parsed.fname ? parsed.fname : fname)); return 0; }
Exec Code Bypass
0
gx_device_close_output_file(const gx_device * dev, const char *fname, FILE *file) { gs_parsed_file_name_t parsed; const char *fmt; int code = gx_parse_output_file_name(&parsed, &fmt, fname, strlen(fname), dev->memory); if (code < 0) return code; if (parsed.iodev) { if (!strcmp(parsed.iodev->dname, "%stdout%")) return 0; /* NOTE: fname is unsubstituted if the name has any %nnd formats. */ if (parsed.iodev != iodev_default(dev->memory)) return parsed.iodev->procs.fclose(parsed.iodev, file); } gp_close_printer(dev->memory, file, (parsed.fname ? parsed.fname : fname)); return 0; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,234
gx_device_copy_color_params(gx_device *dev, const gx_device *target) { COPY_PARAM(color_info); COPY_PARAM(cached_colors); gx_device_copy_color_procs(dev, target); }
Exec Code Bypass
0
gx_device_copy_color_params(gx_device *dev, const gx_device *target) { COPY_PARAM(color_info); COPY_PARAM(cached_colors); gx_device_copy_color_procs(dev, target); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,235
int gx_device_delete_output_file(const gx_device * dev, const char *fname) { gs_parsed_file_name_t parsed; const char *fmt; char *pfname = (char *)gs_alloc_bytes(dev->memory, gp_file_name_sizeof, "gx_device_delete_output_file(pfname)"); int code; if (pfname == NULL) { code = gs_note_error(gs_error_VMerror); goto done; } code = gx_parse_output_file_name(&parsed, &fmt, fname, strlen(fname), dev->memory); if (code < 0) { goto done; } if (parsed.iodev && !strcmp(parsed.iodev->dname, "%stdout%")) goto done; if (fmt) { /* filename includes "%nnd" */ long count1 = dev->PageCount + 1; while (*fmt != 'l' && *fmt != '%') --fmt; if (*fmt == 'l') gs_sprintf(pfname, parsed.fname, count1); else gs_sprintf(pfname, parsed.fname, (int)count1); } else if (parsed.len && strchr(parsed.fname, '%')) /* filename with "%%" but no "%nnd" */ gs_sprintf(pfname, parsed.fname); else pfname[0] = 0; /* 0 to use "fname", not "pfname" */ if (pfname[0]) { parsed.fname = pfname; parsed.len = strlen(parsed.fname); } if (parsed.iodev) code = parsed.iodev->procs.delete_file((gx_io_device *)(&parsed.iodev), (const char *)parsed.fname); else code = gs_note_error(gs_error_invalidfileaccess); done: if (pfname != NULL) gs_free_object(dev->memory, pfname, "gx_device_delete_output_file(pfname)"); return(code); }
Exec Code Bypass
0
int gx_device_delete_output_file(const gx_device * dev, const char *fname) { gs_parsed_file_name_t parsed; const char *fmt; char *pfname = (char *)gs_alloc_bytes(dev->memory, gp_file_name_sizeof, "gx_device_delete_output_file(pfname)"); int code; if (pfname == NULL) { code = gs_note_error(gs_error_VMerror); goto done; } code = gx_parse_output_file_name(&parsed, &fmt, fname, strlen(fname), dev->memory); if (code < 0) { goto done; } if (parsed.iodev && !strcmp(parsed.iodev->dname, "%stdout%")) goto done; if (fmt) { /* filename includes "%nnd" */ long count1 = dev->PageCount + 1; while (*fmt != 'l' && *fmt != '%') --fmt; if (*fmt == 'l') gs_sprintf(pfname, parsed.fname, count1); else gs_sprintf(pfname, parsed.fname, (int)count1); } else if (parsed.len && strchr(parsed.fname, '%')) /* filename with "%%" but no "%nnd" */ gs_sprintf(pfname, parsed.fname); else pfname[0] = 0; /* 0 to use "fname", not "pfname" */ if (pfname[0]) { parsed.fname = pfname; parsed.len = strlen(parsed.fname); } if (parsed.iodev) code = parsed.iodev->procs.delete_file((gx_io_device *)(&parsed.iodev), (const char *)parsed.fname); else code = gs_note_error(gs_error_invalidfileaccess); done: if (pfname != NULL) gs_free_object(dev->memory, pfname, "gx_device_delete_output_file(pfname)"); return(code); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,236
gx_device_enum_ptr(gx_device * dev) { if (dev == 0 || dev->memory == 0) return 0; return dev; }
Exec Code Bypass
0
gx_device_enum_ptr(gx_device * dev) { if (dev == 0 || dev->memory == 0) return 0; return dev; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,237
gx_device_finalize(const gs_memory_t *cmem, void *vptr) { gx_device * const dev = (gx_device *)vptr; (void)cmem; /* unused */ if (dev->icc_struct != NULL) { rc_decrement(dev->icc_struct, "gx_device_finalize(icc_profile)"); } if (dev->finalize) dev->finalize(dev); /* Deal with subclassed devices. Ordinarily these should not be a problem, we * will never see them, but if ths is a end of job restore we can end up * with the 'child' device(s) being freed before their parents. We need to make * sure we don't leave any dangling pointers in that case. */ if (dev->child) dev->child->parent = dev->parent; if (dev->parent) dev->parent->child = dev->child; if (dev->PageList) { rc_decrement(dev->PageList, "gx_device_finalize(PageList)"); dev->PageList = 0; } discard(gs_closedevice(dev)); if (dev->stype_is_dynamic) gs_free_const_object(dev->memory->non_gc_memory, dev->stype, "gx_device_finalize"); #ifdef DEBUG /* Slightly ugly hack: because the garbage collector makes no promises * about the order objects can be garbage collected, it is possible for * a forwarding device to remain in existence (awaiting garbage collection * itself) after it's target marked as free memory by the garbage collector. * In such a case, the normal reference counting is fine (since the garbage * collector leaves the object contents alone until is has completed its * sweep), but the reference counting debugging attempts to access the * memory header to output type information - and the header has been * overwritten by the garbage collector, causing a crash. * Setting the rc memory to NULL here should be safe, since the memory * is now in the hands of the garbage collector, and means we can check in * debugging code to ensure we don't try to use values that not longer exist * in the memmory header. * In the non-gc case, finalize is the very last thing to happen before the * memory is actually freed, so the rc.memory pointer is moot. * See rc_object_type_name() */ if (gs_debug_c('^')) dev->rc.memory = NULL; #endif }
Exec Code Bypass
0
gx_device_finalize(const gs_memory_t *cmem, void *vptr) { gx_device * const dev = (gx_device *)vptr; (void)cmem; /* unused */ if (dev->icc_struct != NULL) { rc_decrement(dev->icc_struct, "gx_device_finalize(icc_profile)"); } if (dev->finalize) dev->finalize(dev); /* Deal with subclassed devices. Ordinarily these should not be a problem, we * will never see them, but if ths is a end of job restore we can end up * with the 'child' device(s) being freed before their parents. We need to make * sure we don't leave any dangling pointers in that case. */ if (dev->child) dev->child->parent = dev->parent; if (dev->parent) dev->parent->child = dev->child; if (dev->PageList) { rc_decrement(dev->PageList, "gx_device_finalize(PageList)"); dev->PageList = 0; } discard(gs_closedevice(dev)); if (dev->stype_is_dynamic) gs_free_const_object(dev->memory->non_gc_memory, dev->stype, "gx_device_finalize"); #ifdef DEBUG /* Slightly ugly hack: because the garbage collector makes no promises * about the order objects can be garbage collected, it is possible for * a forwarding device to remain in existence (awaiting garbage collection * itself) after it's target marked as free memory by the garbage collector. * In such a case, the normal reference counting is fine (since the garbage * collector leaves the object contents alone until is has completed its * sweep), but the reference counting debugging attempts to access the * memory header to output type information - and the header has been * overwritten by the garbage collector, causing a crash. * Setting the rc memory to NULL here should be safe, since the memory * is now in the hands of the garbage collector, and means we can check in * debugging code to ensure we don't try to use values that not longer exist * in the memmory header. * In the non-gc case, finalize is the very last thing to happen before the * memory is actually freed, so the rc.memory pointer is moot. * See rc_object_type_name() */ if (gs_debug_c('^')) dev->rc.memory = NULL; #endif }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,238
gx_device_free_local(gx_device *dev) { gx_device_finalize(dev->memory, dev); }
Exec Code Bypass
0
gx_device_free_local(gx_device *dev) { gx_device_finalize(dev->memory, dev); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,239
gx_device_init(gx_device * dev, const gx_device * proto, gs_memory_t * mem, bool internal) { memcpy(dev, proto, proto->params_size); dev->memory = mem; dev->retained = !internal; rc_init(dev, mem, (internal ? 0 : 1)); rc_increment(dev->icc_struct); }
Exec Code Bypass
0
gx_device_init(gx_device * dev, const gx_device * proto, gs_memory_t * mem, bool internal) { memcpy(dev, proto, proto->params_size); dev->memory = mem; dev->retained = !internal; rc_init(dev, mem, (internal ? 0 : 1)); rc_increment(dev->icc_struct); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,240
gx_device_init_on_stack(gx_device * dev, const gx_device * proto, gs_memory_t * mem) { memcpy(dev, proto, proto->params_size); dev->memory = mem; dev->retained = 0; dev->pad = proto->pad; dev->log2_align_mod = proto->log2_align_mod; dev->is_planar = proto->is_planar; rc_init(dev, NULL, 0); }
Exec Code Bypass
0
gx_device_init_on_stack(gx_device * dev, const gx_device * proto, gs_memory_t * mem) { memcpy(dev, proto, proto->params_size); dev->memory = mem; dev->retained = 0; dev->pad = proto->pad; dev->log2_align_mod = proto->log2_align_mod; dev->is_planar = proto->is_planar; rc_init(dev, NULL, 0); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,241
gx_device_make_struct_type(gs_memory_struct_type_t *st, const gx_device *dev) { if (dev->stype) *st = *dev->stype; else if (dev_proc(dev, get_xfont_procs) == gx_forward_get_xfont_procs) *st = st_device_forward; else *st = st_device; st->ssize = dev->params_size; }
Exec Code Bypass
0
gx_device_make_struct_type(gs_memory_struct_type_t *st, const gx_device *dev) { if (dev->stype) *st = *dev->stype; else if (dev_proc(dev, get_xfont_procs) == gx_forward_get_xfont_procs) *st = st_device_forward; else *st = st_device; st->ssize = dev->params_size; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,242
gx_device_raster(const gx_device * dev, bool pad) { ulong bits = (ulong) dev->width * dev->color_info.depth; ulong raster; int l2align; if (dev->is_planar) bits /= dev->color_info.num_components; raster = (uint)((bits + 7) >> 3); if (!pad) return raster; l2align = dev->log2_align_mod; if (l2align < log2_align_bitmap_mod) l2align = log2_align_bitmap_mod; return (uint)(((bits + (8 << l2align) - 1) >> (l2align + 3)) << l2align); }
Exec Code Bypass
0
gx_device_raster(const gx_device * dev, bool pad) { ulong bits = (ulong) dev->width * dev->color_info.depth; ulong raster; int l2align; if (dev->is_planar) bits /= dev->color_info.num_components; raster = (uint)((bits + 7) >> 3); if (!pad) return raster; l2align = dev->log2_align_mod; if (l2align < log2_align_bitmap_mod) l2align = log2_align_bitmap_mod; return (uint)(((bits + (8 << l2align) - 1) >> (l2align + 3)) << l2align); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,243
gx_device_raster_chunky(const gx_device * dev, bool pad) { ulong bits = (ulong) dev->width * dev->color_info.depth; ulong raster; int l2align; raster = (uint)((bits + 7) >> 3); if (!pad) return raster; l2align = dev->log2_align_mod; if (l2align < log2_align_bitmap_mod) l2align = log2_align_bitmap_mod; return (uint)(((bits + (8 << l2align) - 1) >> (l2align + 3)) << l2align); }
Exec Code Bypass
0
gx_device_raster_chunky(const gx_device * dev, bool pad) { ulong bits = (ulong) dev->width * dev->color_info.depth; ulong raster; int l2align; raster = (uint)((bits + 7) >> 3); if (!pad) return raster; l2align = dev->log2_align_mod; if (l2align < log2_align_bitmap_mod) l2align = log2_align_bitmap_mod; return (uint)(((bits + (8 << l2align) - 1) >> (l2align + 3)) << l2align); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,244
gx_device_raster_plane(const gx_device * dev, const gx_render_plane_t *render_plane) { ulong bpc = (render_plane && render_plane->index >= 0 ? render_plane->depth : dev->color_info.depth/(dev->is_planar ? dev->color_info.num_components : 1)); ulong bits = (ulong) dev->width * bpc; int l2align; l2align = dev->log2_align_mod; if (l2align < log2_align_bitmap_mod) l2align = log2_align_bitmap_mod; return (uint)(((bits + (8 << l2align) - 1) >> (l2align + 3)) << l2align); }
Exec Code Bypass
0
gx_device_raster_plane(const gx_device * dev, const gx_render_plane_t *render_plane) { ulong bpc = (render_plane && render_plane->index >= 0 ? render_plane->depth : dev->color_info.depth/(dev->is_planar ? dev->color_info.num_components : 1)); ulong bits = (ulong) dev->width * bpc; int l2align; l2align = dev->log2_align_mod; if (l2align < log2_align_bitmap_mod) l2align = log2_align_bitmap_mod; return (uint)(((bits + (8 << l2align) - 1) >> (l2align + 3)) << l2align); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,245
gx_device_reloc_ptr(gx_device * dev, gc_state_t * gcst) { if (dev == 0 || dev->memory == 0) return dev; return RELOC_OBJ(dev); /* gcst implicit */ }
Exec Code Bypass
0
gx_device_reloc_ptr(gx_device * dev, gc_state_t * gcst) { if (dev == 0 || dev->memory == 0) return dev; return RELOC_OBJ(dev); /* gcst implicit */ }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,246
gx_device_retain(gx_device *dev, bool retained) { int delta = (int)retained - (int)dev->retained; if (delta) { dev->retained = retained; /* do first in case dev is freed */ rc_adjust_only(dev, delta, "gx_device_retain"); } }
Exec Code Bypass
0
gx_device_retain(gx_device *dev, bool retained) { int delta = (int)retained - (int)dev->retained; if (delta) { dev->retained = retained; /* do first in case dev is freed */ rc_adjust_only(dev, delta, "gx_device_retain"); } }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,247
gx_device_set_hwsize_from_media(gx_device *dev) { int rot = (dev->LeadingEdge & 1); double rot_media_x = rot ? dev->MediaSize[1] : dev->MediaSize[0]; double rot_media_y = rot ? dev->MediaSize[0] : dev->MediaSize[1]; dev->width = (int)(rot_media_x * dev->HWResolution[0] / 72.0 + 0.5); dev->height = (int)(rot_media_y * dev->HWResolution[1] / 72.0 + 0.5); }
Exec Code Bypass
0
gx_device_set_hwsize_from_media(gx_device *dev) { int rot = (dev->LeadingEdge & 1); double rot_media_x = rot ? dev->MediaSize[1] : dev->MediaSize[0]; double rot_media_y = rot ? dev->MediaSize[0] : dev->MediaSize[1]; dev->width = (int)(rot_media_x * dev->HWResolution[0] / 72.0 + 0.5); dev->height = (int)(rot_media_y * dev->HWResolution[1] / 72.0 + 0.5); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,248
gx_device_set_margins(gx_device * dev, const float *margins /*[4] */ , bool move_origin) { int i; for (i = 0; i < 4; ++i) dev->HWMargins[i] = margins[i] * 72.0; if (move_origin) { dev->Margins[0] = -margins[0] * dev->HWResolution[0]; dev->Margins[1] = -margins[3] * dev->HWResolution[1]; } }
Exec Code Bypass
0
gx_device_set_margins(gx_device * dev, const float *margins /*[4] */ , bool move_origin) { int i; for (i = 0; i < 4; ++i) dev->HWMargins[i] = margins[i] * 72.0; if (move_origin) { dev->Margins[0] = -margins[0] * dev->HWResolution[0]; dev->Margins[1] = -margins[3] * dev->HWResolution[1]; } }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,249
gx_device_set_media_size(gx_device * dev, double media_width, double media_height) { dev->MediaSize[0] = media_width; dev->MediaSize[1] = media_height; gx_device_set_hwsize_from_media(dev); }
Exec Code Bypass
0
gx_device_set_media_size(gx_device * dev, double media_width, double media_height) { dev->MediaSize[0] = media_width; dev->MediaSize[1] = media_height; gx_device_set_hwsize_from_media(dev); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,250
gx_device_set_procs(gx_device * dev) { if (dev->static_procs != 0) { /* 0 if already populated */ dev->procs = *dev->static_procs; dev->static_procs = 0; } }
Exec Code Bypass
0
gx_device_set_procs(gx_device * dev) { if (dev->static_procs != 0) { /* 0 if already populated */ dev->procs = *dev->static_procs; dev->static_procs = 0; } }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,251
gx_device_set_width_height(gx_device * dev, int width, int height) { dev->width = width; dev->height = height; gx_device_set_media_from_hwsize(dev); }
Exec Code Bypass
0
gx_device_set_width_height(gx_device * dev, int width, int height) { dev->width = width; dev->height = height; gx_device_set_media_from_hwsize(dev); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,252
gx_finish_output_page(gx_device *dev, int num_copies, int flush) { dev->PageCount += num_copies; return 0; }
Exec Code Bypass
0
gx_finish_output_page(gx_device *dev, int num_copies, int flush) { dev->PageCount += num_copies; return 0; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,253
gx_outputfile_is_separate_pages(const char *fname, gs_memory_t *memory) { const char *fmt; gs_parsed_file_name_t parsed; int code = gx_parse_output_file_name(&parsed, &fmt, fname, strlen(fname), memory); return (code >= 0 && fmt != 0); }
Exec Code Bypass
0
gx_outputfile_is_separate_pages(const char *fname, gs_memory_t *memory) { const char *fmt; gs_parsed_file_name_t parsed; int code = gx_parse_output_file_name(&parsed, &fmt, fname, strlen(fname), memory); return (code >= 0 && fmt != 0); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,254
gx_parse_output_file_name(gs_parsed_file_name_t *pfn, const char **pfmt, const char *fname, uint fnlen, gs_memory_t *memory) { int code; *pfmt = 0; pfn->memory = 0; pfn->iodev = NULL; pfn->fname = NULL; /* irrelevant since length = 0 */ pfn->len = 0; if (fnlen == 0) /* allow null name */ return 0; /* * If the file name begins with a %, it might be either an IODevice * or a %nnd format. Check (carefully) for this case. */ code = gs_parse_file_name(pfn, fname, fnlen, memory); if (code < 0) { if (fname[0] == '%') { /* not a recognized iodev -- may be a leading format descriptor */ pfn->len = fnlen; pfn->fname = fname; code = gx_parse_output_format(pfn, pfmt); } if (code < 0) return code; } if (!pfn->iodev) { if ( (pfn->len == 1) && (pfn->fname[0] == '-') ) { pfn->iodev = gs_findiodevice(memory, (const byte *)"%stdout", 7); pfn->fname = NULL; } else if (pfn->fname[0] == '|') { pfn->iodev = gs_findiodevice(memory, (const byte *)"%pipe", 5); pfn->fname++, pfn->len--; } else pfn->iodev = iodev_default(memory); if (!pfn->iodev) return_error(gs_error_undefinedfilename); } if (!pfn->fname) return 0; code = gx_parse_output_format(pfn, pfmt); if (code < 0) return code; if (strlen(pfn->iodev->dname) + pfn->len + code >= gp_file_name_sizeof) return_error(gs_error_undefinedfilename); return 0; }
Exec Code Bypass
0
gx_parse_output_file_name(gs_parsed_file_name_t *pfn, const char **pfmt, const char *fname, uint fnlen, gs_memory_t *memory) { int code; *pfmt = 0; pfn->memory = 0; pfn->iodev = NULL; pfn->fname = NULL; /* irrelevant since length = 0 */ pfn->len = 0; if (fnlen == 0) /* allow null name */ return 0; /* * If the file name begins with a %, it might be either an IODevice * or a %nnd format. Check (carefully) for this case. */ code = gs_parse_file_name(pfn, fname, fnlen, memory); if (code < 0) { if (fname[0] == '%') { /* not a recognized iodev -- may be a leading format descriptor */ pfn->len = fnlen; pfn->fname = fname; code = gx_parse_output_format(pfn, pfmt); } if (code < 0) return code; } if (!pfn->iodev) { if ( (pfn->len == 1) && (pfn->fname[0] == '-') ) { pfn->iodev = gs_findiodevice(memory, (const byte *)"%stdout", 7); pfn->fname = NULL; } else if (pfn->fname[0] == '|') { pfn->iodev = gs_findiodevice(memory, (const byte *)"%pipe", 5); pfn->fname++, pfn->len--; } else pfn->iodev = iodev_default(memory); if (!pfn->iodev) return_error(gs_error_undefinedfilename); } if (!pfn->fname) return 0; code = gx_parse_output_format(pfn, pfmt); if (code < 0) return code; if (strlen(pfn->iodev->dname) + pfn->len + code >= gp_file_name_sizeof) return_error(gs_error_undefinedfilename); return 0; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,255
gx_parse_output_format(gs_parsed_file_name_t *pfn, const char **pfmt) { bool have_format = false, field; int width[2], int_width = sizeof(int) * 3, w = 0; uint i; /* Scan the file name for a format string, and validate it if present. */ width[0] = width[1] = 0; for (i = 0; i < pfn->len; ++i) if (pfn->fname[i] == '%') { if (i + 1 < pfn->len && pfn->fname[i + 1] == '%') { i++; continue; } if (have_format) /* more than one % */ return_error(gs_error_undefinedfilename); have_format = true; field = -1; /* -1..3 for the 5 components of "%[flags][width][.precision][l]type" */ for (;;) if (++i == pfn->len) return_error(gs_error_undefinedfilename); else { switch (field) { case -1: /* flags */ if (strchr(" #+-", pfn->fname[i])) continue; else field++; /* falls through */ default: /* width (field = 0) and precision (field = 1) */ if (strchr("0123456789", pfn->fname[i])) { width[field] = width[field] * 10 + pfn->fname[i] - '0'; continue; } else if (0 == field && '.' == pfn->fname[i]) { field++; continue; } else field = 2; /* falls through */ case 2: /* "long" indicator */ field++; if ('l' == pfn->fname[i]) { int_width = sizeof(long) * 3; continue; } /* falls through */ case 3: /* type */ if (strchr("diuoxX", pfn->fname[i])) { *pfmt = &pfn->fname[i]; break; } else return_error(gs_error_undefinedfilename); } break; } } if (have_format) { /* Calculate a conservative maximum width. */ w = max(width[0], width[1]); w = max(w, int_width) + 5; } return w; }
Exec Code Bypass
0
gx_parse_output_format(gs_parsed_file_name_t *pfn, const char **pfmt) { bool have_format = false, field; int width[2], int_width = sizeof(int) * 3, w = 0; uint i; /* Scan the file name for a format string, and validate it if present. */ width[0] = width[1] = 0; for (i = 0; i < pfn->len; ++i) if (pfn->fname[i] == '%') { if (i + 1 < pfn->len && pfn->fname[i + 1] == '%') { i++; continue; } if (have_format) /* more than one % */ return_error(gs_error_undefinedfilename); have_format = true; field = -1; /* -1..3 for the 5 components of "%[flags][width][.precision][l]type" */ for (;;) if (++i == pfn->len) return_error(gs_error_undefinedfilename); else { switch (field) { case -1: /* flags */ if (strchr(" #+-", pfn->fname[i])) continue; else field++; /* falls through */ default: /* width (field = 0) and precision (field = 1) */ if (strchr("0123456789", pfn->fname[i])) { width[field] = width[field] * 10 + pfn->fname[i] - '0'; continue; } else if (0 == field && '.' == pfn->fname[i]) { field++; continue; } else field = 2; /* falls through */ case 2: /* "long" indicator */ field++; if ('l' == pfn->fname[i]) { int_width = sizeof(long) * 3; continue; } /* falls through */ case 3: /* type */ if (strchr("diuoxX", pfn->fname[i])) { *pfmt = &pfn->fname[i]; break; } else return_error(gs_error_undefinedfilename); } break; } } if (have_format) { /* Calculate a conservative maximum width. */ w = max(width[0], width[1]); w = max(w, int_width) + 5; } return w; }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,256
gx_set_device_only(gs_gstate * pgs, gx_device * dev) { rc_assign(pgs->device, dev, "gx_set_device_only"); }
Exec Code Bypass
0
gx_set_device_only(gs_gstate * pgs, gx_device * dev) { rc_assign(pgs->device, dev, "gx_set_device_only"); }
@@ -691,7 +691,7 @@ int gs_nulldevice(gs_gstate * pgs) { int code = 0; - + bool saveLockSafety = false; if (pgs->device == 0 || !gx_device_is_null(pgs->device)) { gx_device *ndev; code = gs_copydevice(&ndev, (const gx_device *)&gs_null_device, @@ -699,6 +699,8 @@ gs_nulldevice(gs_gstate * pgs) if (code < 0) return code; + if (gs_currentdevice_inline(pgs) != NULL) + saveLockSafety = gs_currentdevice_inline(pgs)->LockSafetyParams; /* * Internal devices have a reference count of 0, not 1, * aside from references from graphics states. @@ -718,6 +720,7 @@ gs_nulldevice(gs_gstate * pgs) if ((code = gs_setdevice_no_erase(pgs, ndev)) < 0) gs_free_object(pgs->memory, ndev, "gs_copydevice(device)"); + gs_currentdevice_inline(pgs)->LockSafetyParams = saveLockSafety; } return code; }
CWE-78
null
null
2,257
z2grestoreall(i_ctx_t *i_ctx_p) { for (;;) { if (!restore_page_device(igs, gs_gstate_saved(igs))) { bool done = !gs_gstate_saved(gs_gstate_saved(igs)); gs_grestore(igs); if (done) break; } else return push_callout(i_ctx_p, "%grestoreallpagedevice"); } }
Exec Code Bypass
0
z2grestoreall(i_ctx_t *i_ctx_p) { for (;;) { if (!restore_page_device(igs, gs_gstate_saved(igs))) { bool done = !gs_gstate_saved(gs_gstate_saved(igs)); gs_grestore(igs); if (done) break; } else return push_callout(i_ctx_p, "%grestoreallpagedevice"); } }
@@ -26,6 +26,7 @@ #include "igstate.h" #include "iname.h" #include "iutil.h" +#include "isave.h" #include "store.h" #include "gxdevice.h" #include "gsstate.h" @@ -307,13 +308,24 @@ z2grestoreall(i_ctx_t *i_ctx_p) } return 0; } - +/* This is the Level 2+ variant of restore - which adds restoring + of the page device to the Level 1 variant in zvmem.c. + Previous this restored the device state before calling zrestore.c + which validated operands etc, meaning a restore could error out + partially complete. + The operand checking, and actual VM restore are now in two functions + so they can called separately thus, here, we can do as much + checking as possible, before embarking on actual changes + */ /* <save> restore - */ static int z2restore(i_ctx_t *i_ctx_p) { - os_ptr op = osp; - check_type(*op, t_save); + alloc_save_t *asave; + bool saveLockSafety = gs_currentdevice_inline(igs)->LockSafetyParams; + int code = restore_check_save(i_ctx_p, &asave); + + if (code < 0) return code; while (gs_gstate_saved(gs_gstate_saved(igs))) { if (restore_page_device(igs, gs_gstate_saved(igs))) @@ -322,7 +334,20 @@ z2restore(i_ctx_t *i_ctx_p) } if (restore_page_device(igs, gs_gstate_saved(igs))) return push_callout(i_ctx_p, "%restorepagedevice"); - return zrestore(i_ctx_p); + + code = dorestore(i_ctx_p, asave); + + if (code < 0) { + /* An error here is basically fatal, but.... + restore_page_device() has to set LockSafetyParams false so it can + configure the restored device correctly - in normal operation, that + gets reset by that configuration. If we hit an error, though, that + may not happen - at least ensure we keep the setting through the + error. + */ + gs_currentdevice_inline(igs)->LockSafetyParams = saveLockSafety; + } + return code; } /* <gstate> setgstate - */
CWE-78
null
null
2,258
ivalidate_clean_spaces(i_ctx_t *i_ctx_p) { if (gs_debug_c('?')) { ref_stack_cleanup(&d_stack); ref_stack_cleanup(&e_stack); ref_stack_cleanup(&o_stack); ivalidate_spaces(); } }
Exec Code Bypass
0
ivalidate_clean_spaces(i_ctx_t *i_ctx_p) { if (gs_debug_c('?')) { ref_stack_cleanup(&d_stack); ref_stack_cleanup(&e_stack); ref_stack_cleanup(&o_stack); ivalidate_spaces(); } }
@@ -99,19 +99,18 @@ zsave(i_ctx_t *i_ctx_p) static int restore_check_operand(os_ptr, alloc_save_t **, gs_dual_memory_t *); static int restore_check_stack(const i_ctx_t *i_ctx_p, const ref_stack_t *, const alloc_save_t *, bool); static void restore_fix_stack(i_ctx_t *i_ctx_p, ref_stack_t *, const alloc_save_t *, bool); + +/* Do as many up front checks of the save object as we reasonably can */ int -zrestore(i_ctx_t *i_ctx_p) +restore_check_save(i_ctx_t *i_ctx_p, alloc_save_t **asave) { os_ptr op = osp; - alloc_save_t *asave; - bool last; - vm_save_t *vmsave; - int code = restore_check_operand(op, &asave, idmemory); + int code = restore_check_operand(op, asave, idmemory); if (code < 0) return code; if_debug2m('u', imemory, "[u]vmrestore 0x%lx, id = %lu\n", - (ulong) alloc_save_client_data(asave), + (ulong) alloc_save_client_data(*asave), (ulong) op->value.saveid); if (I_VALIDATE_BEFORE_RESTORE) ivalidate_clean_spaces(i_ctx_p); @@ -120,14 +119,37 @@ zrestore(i_ctx_t *i_ctx_p) { int code; - if ((code = restore_check_stack(i_ctx_p, &o_stack, asave, false)) < 0 || - (code = restore_check_stack(i_ctx_p, &e_stack, asave, true)) < 0 || - (code = restore_check_stack(i_ctx_p, &d_stack, asave, false)) < 0 + if ((code = restore_check_stack(i_ctx_p, &o_stack, *asave, false)) < 0 || + (code = restore_check_stack(i_ctx_p, &e_stack, *asave, true)) < 0 || + (code = restore_check_stack(i_ctx_p, &d_stack, *asave, false)) < 0 ) { osp++; return code; } } + osp++; + return 0; +} + +/* the semantics of restore differ slightly between Level 1 and + Level 2 and later - the latter includes restoring the device + state (whilst Level 1 didn't have "page devices" as such). + Hence we have two restore operators - one here (Level 1) + and one in zdevice2.c (Level 2+). For that reason, the + operand checking and guts of the restore operation are + separated so both implementations can use them to best + effect. + */ +int +dorestore(i_ctx_t *i_ctx_p, alloc_save_t *asave) +{ + os_ptr op = osp; + bool last; + vm_save_t *vmsave; + int code; + + osp--; + /* Reset l_new in all stack entries if the new save level is zero. */ /* Also do some special fixing on the e-stack. */ restore_fix_stack(i_ctx_p, &o_stack, asave, false); @@ -170,9 +192,24 @@ zrestore(i_ctx_t *i_ctx_p) /* cause an 'invalidaccess' in setuserparams. Temporarily set */ /* LockFilePermissions false until the gs_lev2.ps can do a */ /* setuserparams from the restored userparam dictionary. */ + /* NOTE: This is safe to do here, since the restore has */ + /* successfully completed - this should never come before any */ + /* operation that can trigger an error */ i_ctx_p->LockFilePermissions = false; return 0; } + +int +zrestore(i_ctx_t *i_ctx_p) +{ + alloc_save_t *asave; + int code = restore_check_save(i_ctx_p, &asave); + if (code < 0) + return code; + + return dorestore(i_ctx_p, asave); +} + /* Check the operand of a restore. */ static int restore_check_operand(os_ptr op, alloc_save_t ** pasave, @@ -193,6 +230,7 @@ restore_check_operand(os_ptr op, alloc_save_t ** pasave, *pasave = asave; return 0; } + /* Check a stack to make sure all its elements are older than a save. */ static int restore_check_stack(const i_ctx_t *i_ctx_p, const ref_stack_t * pstack,
CWE-78
null
null
2,259
zsave(i_ctx_t *i_ctx_p) { os_ptr op = osp; uint space = icurrent_space; vm_save_t *vmsave; ulong sid; int code; gs_gstate *prev; if (I_VALIDATE_BEFORE_SAVE) ivalidate_clean_spaces(i_ctx_p); ialloc_set_space(idmemory, avm_local); vmsave = ialloc_struct(vm_save_t, &st_vm_save, "zsave"); ialloc_set_space(idmemory, space); if (vmsave == 0) return_error(gs_error_VMerror); vmsave->gsave = NULL; /* Ensure constructed enough to destroy safely */ code = alloc_save_state(idmemory, vmsave, &sid); if (code < 0) return code; if (sid == 0) { ifree_object(vmsave, "zsave"); return_error(gs_error_VMerror); } if_debug2m('u', imemory, "[u]vmsave 0x%lx, id = %lu\n", (ulong) vmsave, (ulong) sid); code = gs_gsave_for_save(igs, &prev); if (code < 0) return code; code = gs_gsave(igs); if (code < 0) return code; vmsave->gsave = prev; push(1); make_tav(op, t_save, 0, saveid, sid); if (I_VALIDATE_AFTER_SAVE) ivalidate_clean_spaces(i_ctx_p); return 0; }
Exec Code Bypass
0
zsave(i_ctx_t *i_ctx_p) { os_ptr op = osp; uint space = icurrent_space; vm_save_t *vmsave; ulong sid; int code; gs_gstate *prev; if (I_VALIDATE_BEFORE_SAVE) ivalidate_clean_spaces(i_ctx_p); ialloc_set_space(idmemory, avm_local); vmsave = ialloc_struct(vm_save_t, &st_vm_save, "zsave"); ialloc_set_space(idmemory, space); if (vmsave == 0) return_error(gs_error_VMerror); vmsave->gsave = NULL; /* Ensure constructed enough to destroy safely */ code = alloc_save_state(idmemory, vmsave, &sid); if (code < 0) return code; if (sid == 0) { ifree_object(vmsave, "zsave"); return_error(gs_error_VMerror); } if_debug2m('u', imemory, "[u]vmsave 0x%lx, id = %lu\n", (ulong) vmsave, (ulong) sid); code = gs_gsave_for_save(igs, &prev); if (code < 0) return code; code = gs_gsave(igs); if (code < 0) return code; vmsave->gsave = prev; push(1); make_tav(op, t_save, 0, saveid, sid); if (I_VALIDATE_AFTER_SAVE) ivalidate_clean_spaces(i_ctx_p); return 0; }
@@ -99,19 +99,18 @@ zsave(i_ctx_t *i_ctx_p) static int restore_check_operand(os_ptr, alloc_save_t **, gs_dual_memory_t *); static int restore_check_stack(const i_ctx_t *i_ctx_p, const ref_stack_t *, const alloc_save_t *, bool); static void restore_fix_stack(i_ctx_t *i_ctx_p, ref_stack_t *, const alloc_save_t *, bool); + +/* Do as many up front checks of the save object as we reasonably can */ int -zrestore(i_ctx_t *i_ctx_p) +restore_check_save(i_ctx_t *i_ctx_p, alloc_save_t **asave) { os_ptr op = osp; - alloc_save_t *asave; - bool last; - vm_save_t *vmsave; - int code = restore_check_operand(op, &asave, idmemory); + int code = restore_check_operand(op, asave, idmemory); if (code < 0) return code; if_debug2m('u', imemory, "[u]vmrestore 0x%lx, id = %lu\n", - (ulong) alloc_save_client_data(asave), + (ulong) alloc_save_client_data(*asave), (ulong) op->value.saveid); if (I_VALIDATE_BEFORE_RESTORE) ivalidate_clean_spaces(i_ctx_p); @@ -120,14 +119,37 @@ zrestore(i_ctx_t *i_ctx_p) { int code; - if ((code = restore_check_stack(i_ctx_p, &o_stack, asave, false)) < 0 || - (code = restore_check_stack(i_ctx_p, &e_stack, asave, true)) < 0 || - (code = restore_check_stack(i_ctx_p, &d_stack, asave, false)) < 0 + if ((code = restore_check_stack(i_ctx_p, &o_stack, *asave, false)) < 0 || + (code = restore_check_stack(i_ctx_p, &e_stack, *asave, true)) < 0 || + (code = restore_check_stack(i_ctx_p, &d_stack, *asave, false)) < 0 ) { osp++; return code; } } + osp++; + return 0; +} + +/* the semantics of restore differ slightly between Level 1 and + Level 2 and later - the latter includes restoring the device + state (whilst Level 1 didn't have "page devices" as such). + Hence we have two restore operators - one here (Level 1) + and one in zdevice2.c (Level 2+). For that reason, the + operand checking and guts of the restore operation are + separated so both implementations can use them to best + effect. + */ +int +dorestore(i_ctx_t *i_ctx_p, alloc_save_t *asave) +{ + os_ptr op = osp; + bool last; + vm_save_t *vmsave; + int code; + + osp--; + /* Reset l_new in all stack entries if the new save level is zero. */ /* Also do some special fixing on the e-stack. */ restore_fix_stack(i_ctx_p, &o_stack, asave, false); @@ -170,9 +192,24 @@ zrestore(i_ctx_t *i_ctx_p) /* cause an 'invalidaccess' in setuserparams. Temporarily set */ /* LockFilePermissions false until the gs_lev2.ps can do a */ /* setuserparams from the restored userparam dictionary. */ + /* NOTE: This is safe to do here, since the restore has */ + /* successfully completed - this should never come before any */ + /* operation that can trigger an error */ i_ctx_p->LockFilePermissions = false; return 0; } + +int +zrestore(i_ctx_t *i_ctx_p) +{ + alloc_save_t *asave; + int code = restore_check_save(i_ctx_p, &asave); + if (code < 0) + return code; + + return dorestore(i_ctx_p, asave); +} + /* Check the operand of a restore. */ static int restore_check_operand(os_ptr op, alloc_save_t ** pasave, @@ -193,6 +230,7 @@ restore_check_operand(os_ptr op, alloc_save_t ** pasave, *pasave = asave; return 0; } + /* Check a stack to make sure all its elements are older than a save. */ static int restore_check_stack(const i_ctx_t *i_ctx_p, const ref_stack_t * pstack,
CWE-78
null
null
2,260
foreach_item_helper (GHashTable *hash, NMVPNIterFunc func, gpointer user_data) { GList *keys, *liter; GSList *copied = NULL, *siter; g_return_if_fail (hash != NULL); /* Grab keys and copy them so that the callback func can modify * the hash table items if it wants to. */ keys = g_hash_table_get_keys (hash); for (liter = keys; liter; liter = g_list_next (liter)) copied = g_slist_prepend (copied, g_strdup (liter->data)); copied = g_slist_reverse (copied); g_list_free (keys); for (siter = copied; siter; siter = g_slist_next (siter)) { gpointer value; value = g_hash_table_lookup (hash, siter->data); func (siter->data, value, user_data); } g_slist_foreach (copied, (GFunc) g_free, NULL); g_slist_free (copied); }
+Info
0
foreach_item_helper (GHashTable *hash, NMVPNIterFunc func, gpointer user_data) { GList *keys, *liter; GSList *copied = NULL, *siter; g_return_if_fail (hash != NULL); /* Grab keys and copy them so that the callback func can modify * the hash table items if it wants to. */ keys = g_hash_table_get_keys (hash); for (liter = keys; liter; liter = g_list_next (liter)) copied = g_slist_prepend (copied, g_strdup (liter->data)); copied = g_slist_reverse (copied); g_list_free (keys); for (siter = copied; siter; siter = g_slist_next (siter)) { gpointer value; value = g_hash_table_lookup (hash, siter->data); func (siter->data, value, user_data); } g_slist_foreach (copied, (GFunc) g_free, NULL); g_slist_free (copied); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,261
get_secret_flags (NMSetting *setting, const char *secret_name, gboolean verify_secret, NMSettingSecretFlags *out_flags, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); gboolean success = FALSE; char *flags_key; gpointer val; unsigned long tmp; flags_key = g_strdup_printf ("%s-flags", secret_name); if (g_hash_table_lookup_extended (priv->data, flags_key, NULL, &val)) { errno = 0; tmp = strtoul ((const char *) val, NULL, 10); if ((errno == 0) && (tmp <= NM_SETTING_SECRET_FLAGS_ALL)) { if (out_flags) *out_flags = (guint32) tmp; success = TRUE; } else { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Failed to convert '%s' value '%s' to uint", flags_key, (const char *) val); } } else { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_NOT_FOUND, "Secret flags property '%s' not found", flags_key); } g_free (flags_key); return success; }
+Info
0
get_secret_flags (NMSetting *setting, const char *secret_name, gboolean verify_secret, NMSettingSecretFlags *out_flags, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); gboolean success = FALSE; char *flags_key; gpointer val; unsigned long tmp; flags_key = g_strdup_printf ("%s-flags", secret_name); if (g_hash_table_lookup_extended (priv->data, flags_key, NULL, &val)) { errno = 0; tmp = strtoul ((const char *) val, NULL, 10); if ((errno == 0) && (tmp <= NM_SETTING_SECRET_FLAGS_ALL)) { if (out_flags) *out_flags = (guint32) tmp; success = TRUE; } else { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Failed to convert '%s' value '%s' to uint", flags_key, (const char *) val); } } else { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_NOT_FOUND, "Secret flags property '%s' not found", flags_key); } g_free (flags_key); return success; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,262
need_secrets (NMSetting *setting) { /* Assume that VPN connections need secrets since they almost always will */ return g_ptr_array_sized_new (1); }
+Info
0
need_secrets (NMSetting *setting) { /* Assume that VPN connections need secrets since they almost always will */ return g_ptr_array_sized_new (1); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,263
nm_setting_vpn_add_data_item (NMSettingVPN *setting, const char *key, const char *item) { g_return_if_fail (NM_IS_SETTING_VPN (setting)); g_return_if_fail (key != NULL); g_return_if_fail (strlen (key) > 0); g_return_if_fail (item != NULL); g_return_if_fail (strlen (item) > 0); g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data, g_strdup (key), g_strdup (item)); }
+Info
0
nm_setting_vpn_add_data_item (NMSettingVPN *setting, const char *key, const char *item) { g_return_if_fail (NM_IS_SETTING_VPN (setting)); g_return_if_fail (key != NULL); g_return_if_fail (strlen (key) > 0); g_return_if_fail (item != NULL); g_return_if_fail (strlen (item) > 0); g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data, g_strdup (key), g_strdup (item)); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,264
nm_setting_vpn_add_secret (NMSettingVPN *setting, const char *key, const char *secret) { g_return_if_fail (NM_IS_SETTING_VPN (setting)); g_return_if_fail (key != NULL); g_return_if_fail (strlen (key) > 0); g_return_if_fail (secret != NULL); g_return_if_fail (strlen (secret) > 0); g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, g_strdup (key), g_strdup (secret)); }
+Info
0
nm_setting_vpn_add_secret (NMSettingVPN *setting, const char *key, const char *secret) { g_return_if_fail (NM_IS_SETTING_VPN (setting)); g_return_if_fail (key != NULL); g_return_if_fail (strlen (key) > 0); g_return_if_fail (secret != NULL); g_return_if_fail (strlen (secret) > 0); g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, g_strdup (key), g_strdup (secret)); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,265
nm_setting_vpn_error_get_type (void) { static GType etype = 0; if (etype == 0) { static const GEnumValue values[] = { /* Unknown error. */ ENUM_ENTRY (NM_SETTING_VPN_ERROR_UNKNOWN, "UnknownError"), /* The specified property was invalid. */ ENUM_ENTRY (NM_SETTING_VPN_ERROR_INVALID_PROPERTY, "InvalidProperty"), /* The specified property was missing and is required. */ ENUM_ENTRY (NM_SETTING_VPN_ERROR_MISSING_PROPERTY, "MissingProperty"), { 0, 0, 0 } }; etype = g_enum_register_static ("NMSettingVpnError", values); } return etype; }
+Info
0
nm_setting_vpn_error_get_type (void) { static GType etype = 0; if (etype == 0) { static const GEnumValue values[] = { /* Unknown error. */ ENUM_ENTRY (NM_SETTING_VPN_ERROR_UNKNOWN, "UnknownError"), /* The specified property was invalid. */ ENUM_ENTRY (NM_SETTING_VPN_ERROR_INVALID_PROPERTY, "InvalidProperty"), /* The specified property was missing and is required. */ ENUM_ENTRY (NM_SETTING_VPN_ERROR_MISSING_PROPERTY, "MissingProperty"), { 0, 0, 0 } }; etype = g_enum_register_static ("NMSettingVpnError", values); } return etype; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,266
nm_setting_vpn_error_quark (void) { static GQuark quark; if (G_UNLIKELY (!quark)) quark = g_quark_from_static_string ("nm-setting-vpn-error-quark"); return quark; }
+Info
0
nm_setting_vpn_error_quark (void) { static GQuark quark; if (G_UNLIKELY (!quark)) quark = g_quark_from_static_string ("nm-setting-vpn-error-quark"); return quark; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,267
nm_setting_vpn_foreach_data_item (NMSettingVPN *setting, NMVPNIterFunc func, gpointer user_data) { g_return_if_fail (setting != NULL); g_return_if_fail (NM_IS_SETTING_VPN (setting)); foreach_item_helper (NM_SETTING_VPN_GET_PRIVATE (setting)->data, func, user_data); }
+Info
0
nm_setting_vpn_foreach_data_item (NMSettingVPN *setting, NMVPNIterFunc func, gpointer user_data) { g_return_if_fail (setting != NULL); g_return_if_fail (NM_IS_SETTING_VPN (setting)); foreach_item_helper (NM_SETTING_VPN_GET_PRIVATE (setting)->data, func, user_data); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,268
nm_setting_vpn_get_data_item (NMSettingVPN *setting, const char *key) { g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL); return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key); }
+Info
0
nm_setting_vpn_get_data_item (NMSettingVPN *setting, const char *key) { g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL); return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,269
nm_setting_vpn_get_service_type (NMSettingVPN *setting) { g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL); return NM_SETTING_VPN_GET_PRIVATE (setting)->service_type; }
+Info
0
nm_setting_vpn_get_service_type (NMSettingVPN *setting) { g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL); return NM_SETTING_VPN_GET_PRIVATE (setting)->service_type; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,270
nm_setting_vpn_new (void) { return (NMSetting *) g_object_new (NM_TYPE_SETTING_VPN, NULL); }
+Info
0
nm_setting_vpn_new (void) { return (NMSetting *) g_object_new (NM_TYPE_SETTING_VPN, NULL); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,271
nm_setting_vpn_remove_data_item (NMSettingVPN *setting, const char *key) { g_return_if_fail (NM_IS_SETTING_VPN (setting)); g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key); }
+Info
0
nm_setting_vpn_remove_data_item (NMSettingVPN *setting, const char *key) { g_return_if_fail (NM_IS_SETTING_VPN (setting)); g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key); }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,272
set_secret_flags (NMSetting *setting, const char *secret_name, gboolean verify_secret, NMSettingSecretFlags flags, GError **error) { g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data, g_strdup_printf ("%s-flags", secret_name), g_strdup_printf ("%u", flags)); return TRUE; }
+Info
0
set_secret_flags (NMSetting *setting, const char *secret_name, gboolean verify_secret, NMSettingSecretFlags flags, GError **error) { g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data, g_strdup_printf ("%s-flags", secret_name), g_strdup_printf ("%u", flags)); return TRUE; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,273
update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error) { gboolean success = FALSE; g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); if (G_VALUE_HOLDS_STRING (value)) { /* Passing the string properties individually isn't correct, and won't * produce the correct result, but for some reason that's how it used * to be done. So even though it's not correct, keep the code around * for compatibility's sake. */ success = update_secret_string (setting, key, g_value_get_string (value), error); } else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_MAP_OF_STRING)) { if (strcmp (key, NM_SETTING_VPN_SECRETS) != 0) { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_NOT_SECRET, "Property %s not a secret property", key); } else success = update_secret_hash (setting, g_value_get_boxed (value), error); } else g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, key); return success; }
+Info
0
update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error) { gboolean success = FALSE; g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); if (G_VALUE_HOLDS_STRING (value)) { /* Passing the string properties individually isn't correct, and won't * produce the correct result, but for some reason that's how it used * to be done. So even though it's not correct, keep the code around * for compatibility's sake. */ success = update_secret_string (setting, key, g_value_get_string (value), error); } else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_MAP_OF_STRING)) { if (strcmp (key, NM_SETTING_VPN_SECRETS) != 0) { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_NOT_SECRET, "Property %s not a secret property", key); } else success = update_secret_hash (setting, g_value_get_boxed (value), error); } else g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, key); return success; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,274
update_secret_hash (NMSetting *setting, GHashTable *secrets, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); GHashTableIter iter; const char *name, *value; g_return_val_if_fail (secrets != NULL, FALSE); /* Make sure the items are valid */ g_hash_table_iter_init (&iter, secrets); while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) { if (!name || !strlen (name)) { g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Secret name was empty"); return FALSE; } if (!value || !strlen (value)) { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Secret %s value was empty", name); return FALSE; } } /* Now add the items to the settings' secrets list */ g_hash_table_iter_init (&iter, secrets); while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) { if (value == NULL) { g_warn_if_fail (value != NULL); continue; } if (strlen (value) == 0) { g_warn_if_fail (strlen (value) > 0); continue; } g_hash_table_insert (priv->secrets, g_strdup (name), g_strdup (value)); } return TRUE; }
+Info
0
update_secret_hash (NMSetting *setting, GHashTable *secrets, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); GHashTableIter iter; const char *name, *value; g_return_val_if_fail (secrets != NULL, FALSE); /* Make sure the items are valid */ g_hash_table_iter_init (&iter, secrets); while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) { if (!name || !strlen (name)) { g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Secret name was empty"); return FALSE; } if (!value || !strlen (value)) { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Secret %s value was empty", name); return FALSE; } } /* Now add the items to the settings' secrets list */ g_hash_table_iter_init (&iter, secrets); while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) { if (value == NULL) { g_warn_if_fail (value != NULL); continue; } if (strlen (value) == 0) { g_warn_if_fail (strlen (value) > 0); continue; } g_hash_table_insert (priv->secrets, g_strdup (name), g_strdup (value)); } return TRUE; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,275
update_secret_string (NMSetting *setting, const char *key, const char *value, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); if (!value || !strlen (value)) { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Secret %s was empty", key); return FALSE; } g_hash_table_insert (priv->secrets, g_strdup (key), g_strdup (value)); return TRUE; }
+Info
0
update_secret_string (NMSetting *setting, const char *key, const char *value, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); if (!value || !strlen (value)) { g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, "Secret %s was empty", key); return FALSE; } g_hash_table_insert (priv->secrets, g_strdup (key), g_strdup (value)); return TRUE; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,276
verify (NMSetting *setting, GSList *all_settings, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); if (!priv->service_type) { g_set_error (error, NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR_MISSING_PROPERTY, NM_SETTING_VPN_SERVICE_TYPE); return FALSE; } if (!strlen (priv->service_type)) { g_set_error (error, NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR_INVALID_PROPERTY, NM_SETTING_VPN_SERVICE_TYPE); return FALSE; } /* default username can be NULL, but can't be zero-length */ if (priv->user_name && !strlen (priv->user_name)) { g_set_error (error, NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR_INVALID_PROPERTY, NM_SETTING_VPN_USER_NAME); return FALSE; } return TRUE; }
+Info
0
verify (NMSetting *setting, GSList *all_settings, GError **error) { NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting); if (!priv->service_type) { g_set_error (error, NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR_MISSING_PROPERTY, NM_SETTING_VPN_SERVICE_TYPE); return FALSE; } if (!strlen (priv->service_type)) { g_set_error (error, NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR_INVALID_PROPERTY, NM_SETTING_VPN_SERVICE_TYPE); return FALSE; } /* default username can be NULL, but can't be zero-length */ if (priv->user_name && !strlen (priv->user_name)) { g_set_error (error, NM_SETTING_VPN_ERROR, NM_SETTING_VPN_ERROR_INVALID_PROPERTY, NM_SETTING_VPN_USER_NAME); return FALSE; } return TRUE; }
@@ -457,7 +457,6 @@ destroy_one_secret (gpointer data) char *secret = (char *) data; /* Don't leave the secret lying around in memory */ -g_message ("%s: destroying %s", __func__, secret); memset (secret, 0, strlen (secret)); g_free (secret); }
CWE-200
null
null
2,277
gst_pngdec_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_pngdec_src_pad_template)); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_pngdec_sink_pad_template)); gst_element_class_set_details (element_class, &gst_pngdec_details); }
DoS Exec Code Overflow
0
gst_pngdec_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_pngdec_src_pad_template)); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_pngdec_sink_pad_template)); gst_element_class_set_details (element_class, &gst_pngdec_details); }
@@ -201,7 +201,14 @@ user_info_callback (png_structp png_ptr, png_infop info) /* Allocate output buffer */ pngdec->rowbytes = png_get_rowbytes (pngdec->png, pngdec->info); - buffer_size = pngdec->height * GST_ROUND_UP_4 (pngdec->rowbytes); + if (pngdec->rowbytes > (G_MAXUINT32 - 3) + || pngdec->height > G_MAXUINT32 / pngdec->rowbytes) { + ret = GST_FLOW_ERROR; + goto beach; + } + pngdec->rowbytes = GST_ROUND_UP_4 (pngdec->rowbytes); + buffer_size = pngdec->height * pngdec->rowbytes; + ret = gst_pad_alloc_buffer_and_set_caps (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer); @@ -228,7 +235,7 @@ user_endrow_callback (png_structp png_ptr, png_bytep new_row, /* If buffer_out doesn't exist, it means buffer_alloc failed, which * will already have set the return code */ if (GST_IS_BUFFER (pngdec->buffer_out)) { - size_t offset = row_num * GST_ROUND_UP_4 (pngdec->rowbytes); + size_t offset = row_num * pngdec->rowbytes; GST_LOG ("got row %u, copying in buffer %p at offset %" G_GSIZE_FORMAT, (guint) row_num, pngdec->buffer_out, offset); @@ -496,7 +503,12 @@ gst_pngdec_task (GstPad * pad) /* Allocate output buffer */ rowbytes = png_get_rowbytes (pngdec->png, pngdec->info); - buffer_size = pngdec->height * GST_ROUND_UP_4 (rowbytes); + if (rowbytes > (G_MAXUINT32 - 3) || pngdec->height > G_MAXUINT32 / rowbytes) { + ret = GST_FLOW_ERROR; + goto pause; + } + rowbytes = GST_ROUND_UP_4 (rowbytes); + buffer_size = pngdec->height * rowbytes; ret = gst_pad_alloc_buffer_and_set_caps (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer); @@ -509,7 +521,7 @@ gst_pngdec_task (GstPad * pad) for (i = 0; i < pngdec->height; i++) { rows[i] = inp; - inp += GST_ROUND_UP_4 (rowbytes); + inp += rowbytes; } /* Read the actual picture */
CWE-189
null
null
2,278
gst_pngdec_get_type (void) { static GType pngdec_type = 0; if (!pngdec_type) { static const GTypeInfo pngdec_info = { sizeof (GstPngDecClass), gst_pngdec_base_init, NULL, (GClassInitFunc) gst_pngdec_class_init, NULL, NULL, sizeof (GstPngDec), 0, (GInstanceInitFunc) gst_pngdec_init, }; pngdec_type = g_type_register_static (GST_TYPE_ELEMENT, "GstPngDec", &pngdec_info, 0); } return pngdec_type; }
DoS Exec Code Overflow
0
gst_pngdec_get_type (void) { static GType pngdec_type = 0; if (!pngdec_type) { static const GTypeInfo pngdec_info = { sizeof (GstPngDecClass), gst_pngdec_base_init, NULL, (GClassInitFunc) gst_pngdec_class_init, NULL, NULL, sizeof (GstPngDec), 0, (GInstanceInitFunc) gst_pngdec_init, }; pngdec_type = g_type_register_static (GST_TYPE_ELEMENT, "GstPngDec", &pngdec_info, 0); } return pngdec_type; }
@@ -201,7 +201,14 @@ user_info_callback (png_structp png_ptr, png_infop info) /* Allocate output buffer */ pngdec->rowbytes = png_get_rowbytes (pngdec->png, pngdec->info); - buffer_size = pngdec->height * GST_ROUND_UP_4 (pngdec->rowbytes); + if (pngdec->rowbytes > (G_MAXUINT32 - 3) + || pngdec->height > G_MAXUINT32 / pngdec->rowbytes) { + ret = GST_FLOW_ERROR; + goto beach; + } + pngdec->rowbytes = GST_ROUND_UP_4 (pngdec->rowbytes); + buffer_size = pngdec->height * pngdec->rowbytes; + ret = gst_pad_alloc_buffer_and_set_caps (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer); @@ -228,7 +235,7 @@ user_endrow_callback (png_structp png_ptr, png_bytep new_row, /* If buffer_out doesn't exist, it means buffer_alloc failed, which * will already have set the return code */ if (GST_IS_BUFFER (pngdec->buffer_out)) { - size_t offset = row_num * GST_ROUND_UP_4 (pngdec->rowbytes); + size_t offset = row_num * pngdec->rowbytes; GST_LOG ("got row %u, copying in buffer %p at offset %" G_GSIZE_FORMAT, (guint) row_num, pngdec->buffer_out, offset); @@ -496,7 +503,12 @@ gst_pngdec_task (GstPad * pad) /* Allocate output buffer */ rowbytes = png_get_rowbytes (pngdec->png, pngdec->info); - buffer_size = pngdec->height * GST_ROUND_UP_4 (rowbytes); + if (rowbytes > (G_MAXUINT32 - 3) || pngdec->height > G_MAXUINT32 / rowbytes) { + ret = GST_FLOW_ERROR; + goto pause; + } + rowbytes = GST_ROUND_UP_4 (rowbytes); + buffer_size = pngdec->height * rowbytes; ret = gst_pad_alloc_buffer_and_set_caps (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer); @@ -509,7 +521,7 @@ gst_pngdec_task (GstPad * pad) for (i = 0; i < pngdec->height; i++) { rows[i] = inp; - inp += GST_ROUND_UP_4 (rowbytes); + inp += rowbytes; } /* Read the actual picture */
CWE-189
null
null
2,279
gst_pngdec_init (GstPngDec * pngdec) { pngdec->sinkpad = gst_pad_new_from_static_template (&gst_pngdec_sink_pad_template, "sink"); gst_pad_set_activate_function (pngdec->sinkpad, gst_pngdec_sink_activate); gst_pad_set_activatepush_function (pngdec->sinkpad, gst_pngdec_sink_activate_push); gst_pad_set_activatepull_function (pngdec->sinkpad, gst_pngdec_sink_activate_pull); gst_pad_set_chain_function (pngdec->sinkpad, gst_pngdec_chain); gst_pad_set_event_function (pngdec->sinkpad, gst_pngdec_sink_event); gst_pad_set_setcaps_function (pngdec->sinkpad, gst_pngdec_sink_setcaps); gst_element_add_pad (GST_ELEMENT (pngdec), pngdec->sinkpad); pngdec->srcpad = gst_pad_new_from_static_template (&gst_pngdec_src_pad_template, "src"); gst_pad_use_fixed_caps (pngdec->srcpad); gst_element_add_pad (GST_ELEMENT (pngdec), pngdec->srcpad); pngdec->buffer_out = NULL; pngdec->png = NULL; pngdec->info = NULL; pngdec->endinfo = NULL; pngdec->setup = FALSE; pngdec->color_type = -1; pngdec->width = -1; pngdec->height = -1; pngdec->bpp = -1; pngdec->fps_n = 0; pngdec->fps_d = 1; pngdec->in_timestamp = GST_CLOCK_TIME_NONE; pngdec->in_duration = GST_CLOCK_TIME_NONE; gst_segment_init (&pngdec->segment, GST_FORMAT_UNDEFINED); pngdec->image_ready = FALSE; }
DoS Exec Code Overflow
0
gst_pngdec_init (GstPngDec * pngdec) { pngdec->sinkpad = gst_pad_new_from_static_template (&gst_pngdec_sink_pad_template, "sink"); gst_pad_set_activate_function (pngdec->sinkpad, gst_pngdec_sink_activate); gst_pad_set_activatepush_function (pngdec->sinkpad, gst_pngdec_sink_activate_push); gst_pad_set_activatepull_function (pngdec->sinkpad, gst_pngdec_sink_activate_pull); gst_pad_set_chain_function (pngdec->sinkpad, gst_pngdec_chain); gst_pad_set_event_function (pngdec->sinkpad, gst_pngdec_sink_event); gst_pad_set_setcaps_function (pngdec->sinkpad, gst_pngdec_sink_setcaps); gst_element_add_pad (GST_ELEMENT (pngdec), pngdec->sinkpad); pngdec->srcpad = gst_pad_new_from_static_template (&gst_pngdec_src_pad_template, "src"); gst_pad_use_fixed_caps (pngdec->srcpad); gst_element_add_pad (GST_ELEMENT (pngdec), pngdec->srcpad); pngdec->buffer_out = NULL; pngdec->png = NULL; pngdec->info = NULL; pngdec->endinfo = NULL; pngdec->setup = FALSE; pngdec->color_type = -1; pngdec->width = -1; pngdec->height = -1; pngdec->bpp = -1; pngdec->fps_n = 0; pngdec->fps_d = 1; pngdec->in_timestamp = GST_CLOCK_TIME_NONE; pngdec->in_duration = GST_CLOCK_TIME_NONE; gst_segment_init (&pngdec->segment, GST_FORMAT_UNDEFINED); pngdec->image_ready = FALSE; }
@@ -201,7 +201,14 @@ user_info_callback (png_structp png_ptr, png_infop info) /* Allocate output buffer */ pngdec->rowbytes = png_get_rowbytes (pngdec->png, pngdec->info); - buffer_size = pngdec->height * GST_ROUND_UP_4 (pngdec->rowbytes); + if (pngdec->rowbytes > (G_MAXUINT32 - 3) + || pngdec->height > G_MAXUINT32 / pngdec->rowbytes) { + ret = GST_FLOW_ERROR; + goto beach; + } + pngdec->rowbytes = GST_ROUND_UP_4 (pngdec->rowbytes); + buffer_size = pngdec->height * pngdec->rowbytes; + ret = gst_pad_alloc_buffer_and_set_caps (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer); @@ -228,7 +235,7 @@ user_endrow_callback (png_structp png_ptr, png_bytep new_row, /* If buffer_out doesn't exist, it means buffer_alloc failed, which * will already have set the return code */ if (GST_IS_BUFFER (pngdec->buffer_out)) { - size_t offset = row_num * GST_ROUND_UP_4 (pngdec->rowbytes); + size_t offset = row_num * pngdec->rowbytes; GST_LOG ("got row %u, copying in buffer %p at offset %" G_GSIZE_FORMAT, (guint) row_num, pngdec->buffer_out, offset); @@ -496,7 +503,12 @@ gst_pngdec_task (GstPad * pad) /* Allocate output buffer */ rowbytes = png_get_rowbytes (pngdec->png, pngdec->info); - buffer_size = pngdec->height * GST_ROUND_UP_4 (rowbytes); + if (rowbytes > (G_MAXUINT32 - 3) || pngdec->height > G_MAXUINT32 / rowbytes) { + ret = GST_FLOW_ERROR; + goto pause; + } + rowbytes = GST_ROUND_UP_4 (rowbytes); + buffer_size = pngdec->height * rowbytes; ret = gst_pad_alloc_buffer_and_set_caps (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, buffer_size, GST_PAD_CAPS (pngdec->srcpad), &buffer); @@ -509,7 +521,7 @@ gst_pngdec_task (GstPad * pad) for (i = 0; i < pngdec->height; i++) { rows[i] = inp; - inp += GST_ROUND_UP_4 (rowbytes); + inp += rowbytes; } /* Read the actual picture */
CWE-189
null
null
2,280
ProcPanoramiXShmCreatePixmap(ClientPtr client) { ScreenPtr pScreen = NULL; PixmapPtr pMap = NULL; DrawablePtr pDraw; DepthPtr pDepth; int i, j, result, rc; ShmDescPtr shmdesc; REQUEST(xShmCreatePixmapReq); unsigned int width, height, depth; unsigned long size; PanoramiXRes *newPix; REQUEST_SIZE_MATCH(xShmCreatePixmapReq); client->errorValue = stuff->pid; if (!sharedPixmaps) return BadImplementation; LEGAL_NEW_RESOURCE(stuff->pid, client); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY, DixGetAttrAccess); if (rc != Success) return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); width = stuff->width; height = stuff->height; depth = stuff->depth; if (!width || !height || !depth) { client->errorValue = 0; return BadValue; } if (width > 32767 || height > 32767) return BadAlloc; if (stuff->depth != 1) { pDepth = pDraw->pScreen->allowedDepths; for (i = 0; i < pDraw->pScreen->numDepths; i++, pDepth++) if (pDepth->depth == stuff->depth) goto CreatePmap; client->errorValue = stuff->depth; return BadValue; } CreatePmap: size = PixmapBytePad(width, depth) * height; if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { if (size < width * height) return BadAlloc; } /* thankfully, offset is unsigned */ if (stuff->offset + size < size) return BadAlloc; VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); if (!(newPix = malloc(sizeof(PanoramiXRes)))) return BadAlloc; newPix->type = XRT_PIXMAP; newPix->u.pix.shared = TRUE; panoramix_setup_ids(newPix, client, stuff->pid); result = Success; FOR_NSCREENS(j) { ShmScrPrivateRec *screen_priv; pScreen = screenInfo.screens[j]; screen_priv = ShmGetScreenPriv(pScreen); pMap = (*screen_priv->shmFuncs->CreatePixmap) (pScreen, stuff->width, stuff->height, stuff->depth, shmdesc->addr + stuff->offset); if (pMap) { result = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP, pMap, RT_NONE, NULL, DixCreateAccess); if (result != Success) { pDraw->pScreen->DestroyPixmap(pMap); break; } dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc); shmdesc->refcnt++; pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; pMap->drawable.id = newPix->info[j].id; if (!AddResource(newPix->info[j].id, RT_PIXMAP, (void *) pMap)) { result = BadAlloc; break; } } else { result = BadAlloc; break; } } if (result != Success) { while (j--) FreeResource(newPix->info[j].id, RT_NONE); free(newPix); } else AddResource(stuff->pid, XRT_PIXMAP, newPix); return result; }
null
0
ProcPanoramiXShmCreatePixmap(ClientPtr client) { ScreenPtr pScreen = NULL; PixmapPtr pMap = NULL; DrawablePtr pDraw; DepthPtr pDepth; int i, j, result, rc; ShmDescPtr shmdesc; REQUEST(xShmCreatePixmapReq); unsigned int width, height, depth; unsigned long size; PanoramiXRes *newPix; REQUEST_SIZE_MATCH(xShmCreatePixmapReq); client->errorValue = stuff->pid; if (!sharedPixmaps) return BadImplementation; LEGAL_NEW_RESOURCE(stuff->pid, client); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY, DixGetAttrAccess); if (rc != Success) return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); width = stuff->width; height = stuff->height; depth = stuff->depth; if (!width || !height || !depth) { client->errorValue = 0; return BadValue; } if (width > 32767 || height > 32767) return BadAlloc; if (stuff->depth != 1) { pDepth = pDraw->pScreen->allowedDepths; for (i = 0; i < pDraw->pScreen->numDepths; i++, pDepth++) if (pDepth->depth == stuff->depth) goto CreatePmap; client->errorValue = stuff->depth; return BadValue; } CreatePmap: size = PixmapBytePad(width, depth) * height; if (sizeof(size) == 4 && BitsPerPixel(depth) > 8) { if (size < width * height) return BadAlloc; } /* thankfully, offset is unsigned */ if (stuff->offset + size < size) return BadAlloc; VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client); if (!(newPix = malloc(sizeof(PanoramiXRes)))) return BadAlloc; newPix->type = XRT_PIXMAP; newPix->u.pix.shared = TRUE; panoramix_setup_ids(newPix, client, stuff->pid); result = Success; FOR_NSCREENS(j) { ShmScrPrivateRec *screen_priv; pScreen = screenInfo.screens[j]; screen_priv = ShmGetScreenPriv(pScreen); pMap = (*screen_priv->shmFuncs->CreatePixmap) (pScreen, stuff->width, stuff->height, stuff->depth, shmdesc->addr + stuff->offset); if (pMap) { result = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP, pMap, RT_NONE, NULL, DixCreateAccess); if (result != Success) { pDraw->pScreen->DestroyPixmap(pMap); break; } dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc); shmdesc->refcnt++; pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER; pMap->drawable.id = newPix->info[j].id; if (!AddResource(newPix->info[j].id, RT_PIXMAP, (void *) pMap)) { result = BadAlloc; break; } } else { result = BadAlloc; break; } } if (result != Success) { while (j--) FreeResource(newPix->info[j].id, RT_NONE); free(newPix); } else AddResource(stuff->pid, XRT_PIXMAP, newPix); return result; }
@@ -1238,6 +1238,7 @@ ProcShmCreateSegment(ClientPtr client) }; REQUEST_SIZE_MATCH(xShmCreateSegmentReq); + LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue;
CWE-269
null
null
2,281
ProcPanoramiXShmGetImage(ClientPtr client) { PanoramiXRes *draw; DrawablePtr *drawables; DrawablePtr pDraw; xShmGetImageReply xgi; ShmDescPtr shmdesc; int i, x, y, w, h, format, rc; Mask plane = 0, planemask; long lenPer = 0, length, widthBytesLine; Bool isRoot; REQUEST(xShmGetImageReq); REQUEST_SIZE_MATCH(xShmGetImageReq); if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { client->errorValue = stuff->format; return BadValue; } rc = dixLookupResourceByClass((void **) &draw, stuff->drawable, XRC_DRAWABLE, client, DixWriteAccess); if (rc != Success) return (rc == BadValue) ? BadDrawable : rc; if (draw->type == XRT_PIXMAP) return ProcShmGetImage(client); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReadAccess); if (rc != Success) return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); x = stuff->x; y = stuff->y; w = stuff->width; h = stuff->height; format = stuff->format; planemask = stuff->planeMask; isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; if (isRoot) { if ( /* check for being onscreen */ x < 0 || x + w > PanoramiXPixWidth || y < 0 || y + h > PanoramiXPixHeight) return BadMatch; } else { if ( /* check for being onscreen */ screenInfo.screens[0]->x + pDraw->x + x < 0 || screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth || screenInfo.screens[0]->y + pDraw->y + y < 0 || screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight || /* check for being inside of border */ x < -wBorderWidth((WindowPtr) pDraw) || x + w > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->width || y < -wBorderWidth((WindowPtr) pDraw) || y + h > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height) return BadMatch; } drawables = calloc(PanoramiXNumScreens, sizeof(DrawablePtr)); if (!drawables) return BadAlloc; drawables[0] = pDraw; FOR_NSCREENS_FORWARD_SKIP(i) { rc = dixLookupDrawable(drawables + i, draw->info[i].id, client, 0, DixReadAccess); if (rc != Success) { free(drawables); return rc; } } xgi = (xShmGetImageReply) { .type = X_Reply, .sequenceNumber = client->sequence, .length = 0, .visual = wVisual(((WindowPtr) pDraw)), .depth = pDraw->depth }; if (format == ZPixmap) { widthBytesLine = PixmapBytePad(w, pDraw->depth); length = widthBytesLine * h; } else { widthBytesLine = PixmapBytePad(w, 1); lenPer = widthBytesLine * h; plane = ((Mask) 1) << (pDraw->depth - 1); length = lenPer * Ones(planemask & (plane | (plane - 1))); } VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); xgi.size = length; if (length == 0) { /* nothing to do */ } else if (format == ZPixmap) { XineramaGetImageData(drawables, x, y, w, h, format, planemask, shmdesc->addr + stuff->offset, widthBytesLine, isRoot); } else { length = stuff->offset; for (; plane; plane >>= 1) { if (planemask & plane) { XineramaGetImageData(drawables, x, y, w, h, format, plane, shmdesc->addr + length, widthBytesLine, isRoot); length += lenPer; } } } free(drawables); if (client->swapped) { swaps(&xgi.sequenceNumber); swapl(&xgi.length); swapl(&xgi.visual); swapl(&xgi.size); } WriteToClient(client, sizeof(xShmGetImageReply), &xgi); return Success; }
null
0
ProcPanoramiXShmGetImage(ClientPtr client) { PanoramiXRes *draw; DrawablePtr *drawables; DrawablePtr pDraw; xShmGetImageReply xgi; ShmDescPtr shmdesc; int i, x, y, w, h, format, rc; Mask plane = 0, planemask; long lenPer = 0, length, widthBytesLine; Bool isRoot; REQUEST(xShmGetImageReq); REQUEST_SIZE_MATCH(xShmGetImageReq); if ((stuff->format != XYPixmap) && (stuff->format != ZPixmap)) { client->errorValue = stuff->format; return BadValue; } rc = dixLookupResourceByClass((void **) &draw, stuff->drawable, XRC_DRAWABLE, client, DixWriteAccess); if (rc != Success) return (rc == BadValue) ? BadDrawable : rc; if (draw->type == XRT_PIXMAP) return ProcShmGetImage(client); rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReadAccess); if (rc != Success) return rc; VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client); x = stuff->x; y = stuff->y; w = stuff->width; h = stuff->height; format = stuff->format; planemask = stuff->planeMask; isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; if (isRoot) { if ( /* check for being onscreen */ x < 0 || x + w > PanoramiXPixWidth || y < 0 || y + h > PanoramiXPixHeight) return BadMatch; } else { if ( /* check for being onscreen */ screenInfo.screens[0]->x + pDraw->x + x < 0 || screenInfo.screens[0]->x + pDraw->x + x + w > PanoramiXPixWidth || screenInfo.screens[0]->y + pDraw->y + y < 0 || screenInfo.screens[0]->y + pDraw->y + y + h > PanoramiXPixHeight || /* check for being inside of border */ x < -wBorderWidth((WindowPtr) pDraw) || x + w > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->width || y < -wBorderWidth((WindowPtr) pDraw) || y + h > wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height) return BadMatch; } drawables = calloc(PanoramiXNumScreens, sizeof(DrawablePtr)); if (!drawables) return BadAlloc; drawables[0] = pDraw; FOR_NSCREENS_FORWARD_SKIP(i) { rc = dixLookupDrawable(drawables + i, draw->info[i].id, client, 0, DixReadAccess); if (rc != Success) { free(drawables); return rc; } } xgi = (xShmGetImageReply) { .type = X_Reply, .sequenceNumber = client->sequence, .length = 0, .visual = wVisual(((WindowPtr) pDraw)), .depth = pDraw->depth }; if (format == ZPixmap) { widthBytesLine = PixmapBytePad(w, pDraw->depth); length = widthBytesLine * h; } else { widthBytesLine = PixmapBytePad(w, 1); lenPer = widthBytesLine * h; plane = ((Mask) 1) << (pDraw->depth - 1); length = lenPer * Ones(planemask & (plane | (plane - 1))); } VERIFY_SHMSIZE(shmdesc, stuff->offset, length, client); xgi.size = length; if (length == 0) { /* nothing to do */ } else if (format == ZPixmap) { XineramaGetImageData(drawables, x, y, w, h, format, planemask, shmdesc->addr + stuff->offset, widthBytesLine, isRoot); } else { length = stuff->offset; for (; plane; plane >>= 1) { if (planemask & plane) { XineramaGetImageData(drawables, x, y, w, h, format, plane, shmdesc->addr + length, widthBytesLine, isRoot); length += lenPer; } } } free(drawables); if (client->swapped) { swaps(&xgi.sequenceNumber); swapl(&xgi.length); swapl(&xgi.visual); swapl(&xgi.size); } WriteToClient(client, sizeof(xShmGetImageReply), &xgi); return Success; }
@@ -1238,6 +1238,7 @@ ProcShmCreateSegment(ClientPtr client) }; REQUEST_SIZE_MATCH(xShmCreateSegmentReq); + LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue;
CWE-269
null
null
2,282
ProcPanoramiXShmPutImage(ClientPtr client) { int j, result, orig_x, orig_y; PanoramiXRes *draw, *gc; Bool sendEvent, isRoot; REQUEST(xShmPutImageReq); REQUEST_SIZE_MATCH(xShmPutImageReq); result = dixLookupResourceByClass((void **) &draw, stuff->drawable, XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) return (result == BadValue) ? BadDrawable : result; result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC, client, DixReadAccess); if (result != Success) return result; isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; orig_x = stuff->dstX; orig_y = stuff->dstY; sendEvent = stuff->sendEvent; stuff->sendEvent = 0; FOR_NSCREENS(j) { if (!j) stuff->sendEvent = sendEvent; stuff->drawable = draw->info[j].id; stuff->gc = gc->info[j].id; if (isRoot) { stuff->dstX = orig_x - screenInfo.screens[j]->x; stuff->dstY = orig_y - screenInfo.screens[j]->y; } result = ProcShmPutImage(client); if (result != Success) break; } return result; }
null
0
ProcPanoramiXShmPutImage(ClientPtr client) { int j, result, orig_x, orig_y; PanoramiXRes *draw, *gc; Bool sendEvent, isRoot; REQUEST(xShmPutImageReq); REQUEST_SIZE_MATCH(xShmPutImageReq); result = dixLookupResourceByClass((void **) &draw, stuff->drawable, XRC_DRAWABLE, client, DixWriteAccess); if (result != Success) return (result == BadValue) ? BadDrawable : result; result = dixLookupResourceByType((void **) &gc, stuff->gc, XRT_GC, client, DixReadAccess); if (result != Success) return result; isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; orig_x = stuff->dstX; orig_y = stuff->dstY; sendEvent = stuff->sendEvent; stuff->sendEvent = 0; FOR_NSCREENS(j) { if (!j) stuff->sendEvent = sendEvent; stuff->drawable = draw->info[j].id; stuff->gc = gc->info[j].id; if (isRoot) { stuff->dstX = orig_x - screenInfo.screens[j]->x; stuff->dstY = orig_y - screenInfo.screens[j]->y; } result = ProcShmPutImage(client); if (result != Success) break; } return result; }
@@ -1238,6 +1238,7 @@ ProcShmCreateSegment(ClientPtr client) }; REQUEST_SIZE_MATCH(xShmCreateSegmentReq); + LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue;
CWE-269
null
null
2,283
ProcShmAttach(ClientPtr client) { SHMSTAT_TYPE buf; ShmDescPtr shmdesc; REQUEST(xShmAttachReq); REQUEST_SIZE_MATCH(xShmAttachReq); LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue; } for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next) { if (!SHMDESC_IS_FD(shmdesc) && shmdesc->shmid == stuff->shmid) break; } if (shmdesc) { if (!stuff->readOnly && !shmdesc->writable) return BadAccess; shmdesc->refcnt++; } else { shmdesc = malloc(sizeof(ShmDescRec)); if (!shmdesc) return BadAlloc; #ifdef SHM_FD_PASSING shmdesc->is_fd = FALSE; #endif shmdesc->addr = shmat(stuff->shmid, 0, stuff->readOnly ? SHM_RDONLY : 0); if ((shmdesc->addr == ((char *) -1)) || SHMSTAT(stuff->shmid, &buf)) { free(shmdesc); return BadAccess; } /* The attach was performed with root privs. We must * do manual checking of access rights for the credentials * of the client */ if (shm_access(client, &(SHM_PERM(buf)), stuff->readOnly) == -1) { shmdt(shmdesc->addr); free(shmdesc); return BadAccess; } shmdesc->shmid = stuff->shmid; shmdesc->refcnt = 1; shmdesc->writable = !stuff->readOnly; shmdesc->size = SHM_SEGSZ(buf); shmdesc->next = Shmsegs; Shmsegs = shmdesc; } if (!AddResource(stuff->shmseg, ShmSegType, (void *) shmdesc)) return BadAlloc; return Success; }
null
0
ProcShmAttach(ClientPtr client) { SHMSTAT_TYPE buf; ShmDescPtr shmdesc; REQUEST(xShmAttachReq); REQUEST_SIZE_MATCH(xShmAttachReq); LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue; } for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next) { if (!SHMDESC_IS_FD(shmdesc) && shmdesc->shmid == stuff->shmid) break; } if (shmdesc) { if (!stuff->readOnly && !shmdesc->writable) return BadAccess; shmdesc->refcnt++; } else { shmdesc = malloc(sizeof(ShmDescRec)); if (!shmdesc) return BadAlloc; #ifdef SHM_FD_PASSING shmdesc->is_fd = FALSE; #endif shmdesc->addr = shmat(stuff->shmid, 0, stuff->readOnly ? SHM_RDONLY : 0); if ((shmdesc->addr == ((char *) -1)) || SHMSTAT(stuff->shmid, &buf)) { free(shmdesc); return BadAccess; } /* The attach was performed with root privs. We must * do manual checking of access rights for the credentials * of the client */ if (shm_access(client, &(SHM_PERM(buf)), stuff->readOnly) == -1) { shmdt(shmdesc->addr); free(shmdesc); return BadAccess; } shmdesc->shmid = stuff->shmid; shmdesc->refcnt = 1; shmdesc->writable = !stuff->readOnly; shmdesc->size = SHM_SEGSZ(buf); shmdesc->next = Shmsegs; Shmsegs = shmdesc; } if (!AddResource(stuff->shmseg, ShmSegType, (void *) shmdesc)) return BadAlloc; return Success; }
@@ -1238,6 +1238,7 @@ ProcShmCreateSegment(ClientPtr client) }; REQUEST_SIZE_MATCH(xShmCreateSegmentReq); + LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue;
CWE-269
null
null
2,284
ProcShmAttachFd(ClientPtr client) { int fd; ShmDescPtr shmdesc; REQUEST(xShmAttachFdReq); struct stat statb; SetReqFds(client, 1); REQUEST_SIZE_MATCH(xShmAttachFdReq); LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue; } fd = ReadFdFromClient(client); if (fd < 0) return BadMatch; if (fstat(fd, &statb) < 0 || statb.st_size == 0) { close(fd); return BadMatch; } shmdesc = malloc(sizeof(ShmDescRec)); if (!shmdesc) { close(fd); return BadAlloc; } shmdesc->is_fd = TRUE; shmdesc->addr = mmap(NULL, statb.st_size, stuff->readOnly ? PROT_READ : PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); close(fd); if (shmdesc->addr == ((char *) -1)) { free(shmdesc); return BadAccess; } shmdesc->refcnt = 1; shmdesc->writable = !stuff->readOnly; shmdesc->size = statb.st_size; shmdesc->resource = stuff->shmseg; shmdesc->busfault = busfault_register_mmap(shmdesc->addr, shmdesc->size, ShmBusfaultNotify, shmdesc); if (!shmdesc->busfault) { munmap(shmdesc->addr, shmdesc->size); free(shmdesc); return BadAlloc; } shmdesc->next = Shmsegs; Shmsegs = shmdesc; if (!AddResource(stuff->shmseg, ShmSegType, (void *) shmdesc)) return BadAlloc; return Success; }
null
0
ProcShmAttachFd(ClientPtr client) { int fd; ShmDescPtr shmdesc; REQUEST(xShmAttachFdReq); struct stat statb; SetReqFds(client, 1); REQUEST_SIZE_MATCH(xShmAttachFdReq); LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue; } fd = ReadFdFromClient(client); if (fd < 0) return BadMatch; if (fstat(fd, &statb) < 0 || statb.st_size == 0) { close(fd); return BadMatch; } shmdesc = malloc(sizeof(ShmDescRec)); if (!shmdesc) { close(fd); return BadAlloc; } shmdesc->is_fd = TRUE; shmdesc->addr = mmap(NULL, statb.st_size, stuff->readOnly ? PROT_READ : PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); close(fd); if (shmdesc->addr == ((char *) -1)) { free(shmdesc); return BadAccess; } shmdesc->refcnt = 1; shmdesc->writable = !stuff->readOnly; shmdesc->size = statb.st_size; shmdesc->resource = stuff->shmseg; shmdesc->busfault = busfault_register_mmap(shmdesc->addr, shmdesc->size, ShmBusfaultNotify, shmdesc); if (!shmdesc->busfault) { munmap(shmdesc->addr, shmdesc->size); free(shmdesc); return BadAlloc; } shmdesc->next = Shmsegs; Shmsegs = shmdesc; if (!AddResource(stuff->shmseg, ShmSegType, (void *) shmdesc)) return BadAlloc; return Success; }
@@ -1238,6 +1238,7 @@ ProcShmCreateSegment(ClientPtr client) }; REQUEST_SIZE_MATCH(xShmCreateSegmentReq); + LEGAL_NEW_RESOURCE(stuff->shmseg, client); if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) { client->errorValue = stuff->readOnly; return BadValue;
CWE-269
null
null
2,285
FontFileAddEntry(FontTablePtr table, FontEntryPtr prototype) { FontEntryPtr entry; int newsize; /* can't add entries to a sorted table, pointers get broken! */ if (table->sorted) return (FontEntryPtr) 0; /* "cannot" happen */ if (table->used == table->size) { if (table->size >= ((INT32_MAX / sizeof(FontEntryRec)) - 100)) /* If we've read so many entries we're going to ask for 2gb or more of memory, something is so wrong with this font directory that we should just give up before we overflow. */ return NULL; newsize = table->size + 100; entry = realloc(table->entries, newsize * sizeof(FontEntryRec)); if (!entry) return (FontEntryPtr)0; table->size = newsize; table->entries = entry; } entry = &table->entries[table->used]; *entry = *prototype; entry->name.name = malloc(prototype->name.length + 1); if (!entry->name.name) return (FontEntryPtr)0; memcpy (entry->name.name, prototype->name.name, prototype->name.length); entry->name.name[entry->name.length] = '\0'; table->used++; return entry; }
DoS
0
FontFileAddEntry(FontTablePtr table, FontEntryPtr prototype) { FontEntryPtr entry; int newsize; /* can't add entries to a sorted table, pointers get broken! */ if (table->sorted) return (FontEntryPtr) 0; /* "cannot" happen */ if (table->used == table->size) { if (table->size >= ((INT32_MAX / sizeof(FontEntryRec)) - 100)) /* If we've read so many entries we're going to ask for 2gb or more of memory, something is so wrong with this font directory that we should just give up before we overflow. */ return NULL; newsize = table->size + 100; entry = realloc(table->entries, newsize * sizeof(FontEntryRec)); if (!entry) return (FontEntryPtr)0; table->size = newsize; table->entries = entry; } entry = &table->entries[table->used]; *entry = *prototype; entry->name.name = malloc(prototype->name.length + 1); if (!entry->name.name) return (FontEntryPtr)0; memcpy (entry->name.name, prototype->name.name, prototype->name.length); entry->name.name[entry->name.length] = '\0'; table->used++; return entry; }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,286
FontFileFreeDir (FontDirectoryPtr dir) { FontFileFreeTable (&dir->scalable); FontFileFreeTable (&dir->nonScalable); free(dir); }
DoS
0
FontFileFreeDir (FontDirectoryPtr dir) { FontFileFreeTable (&dir->scalable); FontFileFreeTable (&dir->nonScalable); free(dir); }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,287
FontFileFreeEntry (FontEntryPtr entry) { FontScalableExtraPtr extra; int i; if (entry->name.name) free(entry->name.name); entry->name.name = NULL; switch (entry->type) { case FONT_ENTRY_SCALABLE: free (entry->u.scalable.fileName); extra = entry->u.scalable.extra; for (i = 0; i < extra->numScaled; i++) if (extra->scaled[i].vals.ranges) free (extra->scaled[i].vals.ranges); free (extra->scaled); free (extra); break; case FONT_ENTRY_BITMAP: free (entry->u.bitmap.fileName); entry->u.bitmap.fileName = NULL; break; case FONT_ENTRY_ALIAS: free (entry->u.alias.resolved); entry->u.alias.resolved = NULL; break; } }
DoS
0
FontFileFreeEntry (FontEntryPtr entry) { FontScalableExtraPtr extra; int i; if (entry->name.name) free(entry->name.name); entry->name.name = NULL; switch (entry->type) { case FONT_ENTRY_SCALABLE: free (entry->u.scalable.fileName); extra = entry->u.scalable.extra; for (i = 0; i < extra->numScaled; i++) if (extra->scaled[i].vals.ranges) free (extra->scaled[i].vals.ranges); free (extra->scaled); free (extra); break; case FONT_ENTRY_BITMAP: free (entry->u.bitmap.fileName); entry->u.bitmap.fileName = NULL; break; case FONT_ENTRY_ALIAS: free (entry->u.alias.resolved); entry->u.alias.resolved = NULL; break; } }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,288
FontFileInitTable (FontTablePtr table, int size) { if (size < 0 || (size > INT32_MAX/sizeof(FontEntryRec))) return FALSE; if (size) { table->entries = malloc(sizeof(FontEntryRec) * size); if (!table->entries) return FALSE; } else table->entries = 0; table->used = 0; table->size = size; table->sorted = FALSE; return TRUE; }
DoS
0
FontFileInitTable (FontTablePtr table, int size) { if (size < 0 || (size > INT32_MAX/sizeof(FontEntryRec))) return FALSE; if (size) { table->entries = malloc(sizeof(FontEntryRec) * size); if (!table->entries) return FALSE; } else table->entries = 0; table->used = 0; table->size = size; table->sorted = FALSE; return TRUE; }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,289
FontFileSortDir(FontDirectoryPtr dir) { FontFileSortTable (&dir->scalable); FontFileSortTable (&dir->nonScalable); /* now that the table is fixed in size, swizzle the pointers */ FontFileSwitchStringsToBitmapPointers (dir); }
DoS
0
FontFileSortDir(FontDirectoryPtr dir) { FontFileSortTable (&dir->scalable); FontFileSortTable (&dir->nonScalable); /* now that the table is fixed in size, swizzle the pointers */ FontFileSwitchStringsToBitmapPointers (dir); }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,290
FontFileSortTable (FontTablePtr table) { if (!table->sorted) { qsort((char *) table->entries, table->used, sizeof(FontEntryRec), FontFileNameCompare); table->sorted = TRUE; } }
DoS
0
FontFileSortTable (FontTablePtr table) { if (!table->sorted) { qsort((char *) table->entries, table->used, sizeof(FontEntryRec), FontFileNameCompare); table->sorted = TRUE; } }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,291
SetupWildMatch(FontTablePtr table, FontNamePtr pat, int *leftp, int *rightp, int *privatep) { int nDashes; char c; char *t; char *firstWild; char *firstDigit; int first; int center, left, right; int result; char *name; name = pat->name; nDashes = pat->ndashes; firstWild = 0; firstDigit = 0; t = name; while ((c = *t++)) { if (isWild(c)) { if (!firstWild) firstWild = t - 1; } if (isDigit(c)) { if (!firstDigit) firstDigit = t - 1; } } left = 0; right = table->used; if (firstWild) *privatep = nDashes; else *privatep = -1; if (!table->sorted) { *leftp = left; *rightp = right; return -1; } else if (firstWild) { if (firstDigit && firstDigit < firstWild) first = firstDigit - name; else first = firstWild - name; while (left < right) { center = (left + right) / 2; result = strncmp(name, table->entries[center].name.name, first); if (result == 0) break; if (result < 0) right = center; else left = center + 1; } *leftp = left; *rightp = right; return -1; } else { while (left < right) { center = (left + right) / 2; result = strcmpn(name, table->entries[center].name.name); if (result == 0) return center; if (result < 0) right = center; else left = center + 1; } *leftp = 1; *rightp = 0; return -1; } }
DoS
0
SetupWildMatch(FontTablePtr table, FontNamePtr pat, int *leftp, int *rightp, int *privatep) { int nDashes; char c; char *t; char *firstWild; char *firstDigit; int first; int center, left, right; int result; char *name; name = pat->name; nDashes = pat->ndashes; firstWild = 0; firstDigit = 0; t = name; while ((c = *t++)) { if (isWild(c)) { if (!firstWild) firstWild = t - 1; } if (isDigit(c)) { if (!firstDigit) firstDigit = t - 1; } } left = 0; right = table->used; if (firstWild) *privatep = nDashes; else *privatep = -1; if (!table->sorted) { *leftp = left; *rightp = right; return -1; } else if (firstWild) { if (firstDigit && firstDigit < firstWild) first = firstDigit - name; else first = firstWild - name; while (left < right) { center = (left + right) / 2; result = strncmp(name, table->entries[center].name.name, first); if (result == 0) break; if (result < 0) right = center; else left = center + 1; } *leftp = left; *rightp = right; return -1; } else { while (left < right) { center = (left + right) / 2; result = strcmpn(name, table->entries[center].name.name); if (result == 0) return center; if (result < 0) right = center; else left = center + 1; } *leftp = 1; *rightp = 0; return -1; } }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,292
static int strcmpn(const char *s1, const char *s2) { int digits, predigits = 0; const char *ss1, *ss2; while (1) { if (*s1 == 0 && *s2 == 0) return 0; digits = Xisdigit(*s1) && Xisdigit(*s2); if (digits && !predigits) { ss1 = s1; ss2 = s2; while (Xisdigit(*ss1) && Xisdigit(*ss2)) ss1++, ss2++; if (!Xisdigit(*ss1) && Xisdigit(*ss2)) return -1; if (Xisdigit(*ss1) && !Xisdigit(*ss2)) return 1; } if ((unsigned char)*s1 < (unsigned char)*s2) return -1; if ((unsigned char)*s1 > (unsigned char)*s2) return 1; predigits = digits; s1++, s2++; } }
DoS
0
static int strcmpn(const char *s1, const char *s2) { int digits, predigits = 0; const char *ss1, *ss2; while (1) { if (*s1 == 0 && *s2 == 0) return 0; digits = Xisdigit(*s1) && Xisdigit(*s2); if (digits && !predigits) { ss1 = s1; ss2 = s2; while (Xisdigit(*ss1) && Xisdigit(*ss2)) ss1++, ss2++; if (!Xisdigit(*ss1) && Xisdigit(*ss2)) return -1; if (Xisdigit(*ss1) && !Xisdigit(*ss2)) return 1; } if ((unsigned char)*s1 < (unsigned char)*s2) return -1; if ((unsigned char)*s1 > (unsigned char)*s2) return 1; predigits = digits; s1++, s2++; } }
@@ -400,8 +400,10 @@ PatternMatch(char *pat, int patdashes, char *string, int stringdashes) } } case '?': - if (*string++ == XK_minus) + if ((t = *string++) == XK_minus) stringdashes--; + if (!t) + return 0; break; case '\0': return (*string == '\0');
CWE-125
null
null
2,293
copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr) { uint size = ref_stack_count(pstack) - skip; uint save_space = ialloc_space(idmemory); int code; if (size > 65535) size = 65535; ialloc_set_space(idmemory, avm_local); code = ialloc_ref_array(arr, a_all, size, "copy_stack"); if (code >= 0) code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory, "copy_stack"); ialloc_set_space(idmemory, save_space); return code; }
null
0
copy_stack(i_ctx_t *i_ctx_p, const ref_stack_t * pstack, int skip, ref * arr) { uint size = ref_stack_count(pstack) - skip; uint save_space = ialloc_space(idmemory); int code; if (size > 65535) size = 65535; ialloc_set_space(idmemory, avm_local); code = ialloc_ref_array(arr, a_all, size, "copy_stack"); if (code >= 0) code = ref_stack_store(pstack, arr, size, 0, 1, true, idmemory, "copy_stack"); ialloc_set_space(idmemory, save_space); return code; }
@@ -676,7 +676,12 @@ again: /* Push the error object on the operand stack if appropriate. */ if (!GS_ERROR_IS_INTERRUPT(code)) { /* Replace the error object if within an oparray or .errorexec. */ - *++osp = *perror_object; + osp++; + if (osp >= ostop) { + *pexit_code = gs_error_Fatal; + return_error(gs_error_Fatal); + } + *osp = *perror_object; errorexec_find(i_ctx_p, osp); } goto again;
CWE-388
null
null
2,294
gs_errorname(i_ctx_t *i_ctx_p, int code, ref * perror_name) { ref *perrordict, *pErrorNames; if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || dict_find_string(systemdict, "ErrorNames", &pErrorNames) <= 0 ) return_error(gs_error_undefined); /* errordict or ErrorNames not found?! */ return array_get(imemory, pErrorNames, (long)(-code - 1), perror_name); }
null
0
gs_errorname(i_ctx_t *i_ctx_p, int code, ref * perror_name) { ref *perrordict, *pErrorNames; if (dict_find_string(systemdict, "errordict", &perrordict) <= 0 || dict_find_string(systemdict, "ErrorNames", &pErrorNames) <= 0 ) return_error(gs_error_undefined); /* errordict or ErrorNames not found?! */ return array_get(imemory, pErrorNames, (long)(-code - 1), perror_name); }
@@ -676,7 +676,12 @@ again: /* Push the error object on the operand stack if appropriate. */ if (!GS_ERROR_IS_INTERRUPT(code)) { /* Replace the error object if within an oparray or .errorexec. */ - *++osp = *perror_object; + osp++; + if (osp >= ostop) { + *pexit_code = gs_error_Fatal; + return_error(gs_error_Fatal); + } + *osp = *perror_object; errorexec_find(i_ctx_p, osp); } goto again;
CWE-388
null
null
2,295
interp(i_ctx_t **pi_ctx_p /* context for execution, updated if resched */, const ref * pref /* object to interpret */, ref * perror_object) { i_ctx_t *i_ctx_p = *pi_ctx_p; /* * Note that iref may actually be either a ref * or a ref_packed *. * Certain DEC compilers assume that a ref * is ref-aligned even if it * is cast to a short *, and generate code on this assumption, leading * to "unaligned access" errors. For this reason, we declare * iref_packed, and use a macro to cast it to the more aligned type * where necessary (which is almost everywhere it is used). This may * lead to compiler warnings about "cast increases alignment * requirements", but this is less harmful than expensive traps at run * time. */ register const ref_packed *iref_packed = (const ref_packed *)pref; /* * To make matters worse, some versions of gcc/egcs have a bug that * leads them to assume that if iref_packed is EVER cast to a ref *, * it is ALWAYS ref-aligned. We detect this in stdpre.h and provide * the following workaround: */ #ifdef ALIGNMENT_ALIASING_BUG const ref *iref_temp; # define IREF (iref_temp = (const ref *)iref_packed, iref_temp) #else # define IREF ((const ref *)iref_packed) #endif #define SET_IREF(rp) (iref_packed = (const ref_packed *)(rp)) register int icount = 0; /* # of consecutive tokens at iref */ register os_ptr iosp = osp; /* private copy of osp */ register es_ptr iesp = esp; /* private copy of esp */ int code; ref token; /* token read from file or string, */ /* must be declared in this scope */ ref *pvalue; ref refnull; uint opindex; /* needed for oparrays */ os_ptr whichp; /* * We have to make the error information into a struct; * otherwise, the Watcom compiler will assign it to registers * strictly on the basis of textual frequency. * We also have to use ref_assign_inline everywhere, and * avoid direct assignments of refs, so that esi and edi * will remain available on Intel processors. */ struct interp_error_s { int code; int line; const ref *obj; ref full; } ierror; /* * Get a pointer to the name table so that we can use the * inline version of name_index_ref. */ const name_table *const int_nt = imemory->gs_lib_ctx->gs_name_table; #define set_error(ecode)\ { ierror.code = ecode; ierror.line = __LINE__; } #define return_with_error(ecode, objp)\ { set_error(ecode); ierror.obj = objp; goto rwe; } #define return_with_error_iref(ecode)\ { set_error(ecode); goto rwei; } #define return_with_code_iref()\ { ierror.line = __LINE__; goto rweci; } #define return_with_stackoverflow(objp)\ { o_stack.requested = 1; return_with_error(gs_error_stackoverflow, objp); } #define return_with_stackoverflow_iref()\ { o_stack.requested = 1; return_with_error_iref(gs_error_stackoverflow); } /* * If control reaches the special operators (x_add, etc.) as a result of * interpreting an executable name, iref points to the name, not the * operator, so the name rather than the operator becomes the error object, * which is wrong. We detect and handle this case explicitly when an error * occurs, so as not to slow down the non-error case. */ #define return_with_error_tx_op(err_code)\ { if (r_has_type(IREF, t_name)) {\ return_with_error(err_code, pvalue);\ } else {\ return_with_error_iref(err_code);\ }\ } int *ticks_left = &imemory_system->gs_lib_ctx->gcsignal; #if defined(DEBUG_TRACE_PS_OPERATORS) || defined(DEBUG) int (*call_operator_fn)(op_proc_t, i_ctx_t *) = do_call_operator; if (gs_debug_c('!')) call_operator_fn = do_call_operator_verbose; #endif *ticks_left = i_ctx_p->time_slice_ticks; make_null(&ierror.full); ierror.obj = &ierror.full; make_null(&refnull); pvalue = &refnull; /* * If we exceed the VMThreshold, set *ticks_left to -100 * to alert the interpreter that we need to garbage collect. */ set_gc_signal(i_ctx_p, -100); esfile_clear_cache(); /* * From here on, if icount > 0, iref and icount correspond * to the top entry on the execution stack: icount is the count * of sequential entries remaining AFTER the current one. */ #define IREF_NEXT(ip)\ ((const ref_packed *)((const ref *)(ip) + 1)) #define IREF_NEXT_EITHER(ip)\ ( r_is_packed(ip) ? (ip) + 1 : IREF_NEXT(ip) ) #define store_state(ep)\ ( icount > 0 ? (ep->value.const_refs = IREF + 1, r_set_size(ep, icount)) : 0 ) #define store_state_short(ep)\ ( icount > 0 ? (ep->value.packed = iref_packed + 1, r_set_size(ep, icount)) : 0 ) #define store_state_either(ep)\ ( icount > 0 ? (ep->value.packed = IREF_NEXT_EITHER(iref_packed), r_set_size(ep, icount)) : 0 ) #define next()\ if ( --icount > 0 ) { iref_packed = IREF_NEXT(iref_packed); goto top; } else goto out #define next_short()\ if ( --icount <= 0 ) { if ( icount < 0 ) goto up; iesp--; }\ ++iref_packed; goto top #define next_either()\ if ( --icount <= 0 ) { if ( icount < 0 ) goto up; iesp--; }\ iref_packed = IREF_NEXT_EITHER(iref_packed); goto top #if !PACKED_SPECIAL_OPS # undef next_either # define next_either() next() # undef store_state_either # define store_state_either(ep) store_state(ep) #endif /* We want to recognize executable arrays here, */ /* so we push the argument on the estack and enter */ /* the loop at the bottom. */ if (iesp >= estop) return_with_error(gs_error_execstackoverflow, pref); ++iesp; ref_assign_inline(iesp, pref); goto bot; top: /* * This is the top of the interpreter loop. * iref points to the ref being interpreted. * Note that this might be an element of a packed array, * not a real ref: we carefully arranged the first 16 bits of * a ref and of a packed array element so they could be distinguished * from each other. (See ghost.h and packed.h for more detail.) */ INCR(top); #ifdef DEBUG /* Do a little validation on the top o-stack entry. */ if (iosp >= osbot && (r_type(iosp) == t__invalid || r_type(iosp) >= tx_next_op) ) { mlprintf(imemory, "Invalid value on o-stack!\n"); return_with_error_iref(gs_error_Fatal); } if (gs_debug['I'] || (gs_debug['i'] && (r_is_packed(iref_packed) ? r_packed_is_name(iref_packed) : r_has_type(IREF, t_name))) ) { os_ptr save_osp = osp; /* avoid side-effects */ es_ptr save_esp = esp; osp = iosp; esp = iesp; dmlprintf5(imemory, "d%u,e%u<%u>0x%lx(%d): ", ref_stack_count(&d_stack), ref_stack_count(&e_stack), ref_stack_count(&o_stack), (ulong)IREF, icount); debug_print_ref(imemory, IREF); if (iosp >= osbot) { dmputs(imemory, " // "); debug_print_ref(imemory, iosp); } dmputc(imemory, '\n'); osp = save_osp; esp = save_esp; dmflush(imemory); } #endif /* Objects that have attributes (arrays, dictionaries, files, and strings) */ /* use lit and exec; other objects use plain and plain_exec. */ #define lit(t) type_xe_value(t, a_execute) #define exec(t) type_xe_value(t, a_execute + a_executable) #define nox(t) type_xe_value(t, 0) #define nox_exec(t) type_xe_value(t, a_executable) #define plain(t) type_xe_value(t, 0) #define plain_exec(t) type_xe_value(t, a_executable) /* * We have to populate enough cases of the switch statement to force * some compilers to use a dispatch rather than a testing loop. * What a nuisance! */ switch (r_type_xe(iref_packed)) { /* Access errors. */ #define cases_invalid()\ case plain(t__invalid): case plain_exec(t__invalid) cases_invalid(): return_with_error_iref(gs_error_Fatal); #define cases_nox()\ case nox_exec(t_array): case nox_exec(t_dictionary):\ case nox_exec(t_file): case nox_exec(t_string):\ case nox_exec(t_mixedarray): case nox_exec(t_shortarray) cases_nox(): return_with_error_iref(gs_error_invalidaccess); /* * Literal objects. We have to enumerate all the types. * In fact, we have to include some extra plain_exec entries * just to populate the switch. We break them up into groups * to avoid overflowing some preprocessors. */ #define cases_lit_1()\ case lit(t_array): case nox(t_array):\ case plain(t_boolean): case plain_exec(t_boolean):\ case lit(t_dictionary): case nox(t_dictionary) #define cases_lit_2()\ case lit(t_file): case nox(t_file):\ case plain(t_fontID): case plain_exec(t_fontID):\ case plain(t_integer): case plain_exec(t_integer):\ case plain(t_mark): case plain_exec(t_mark) #define cases_lit_3()\ case plain(t_name):\ case plain(t_null):\ case plain(t_oparray):\ case plain(t_operator) #define cases_lit_4()\ case plain(t_real): case plain_exec(t_real):\ case plain(t_save): case plain_exec(t_save):\ case lit(t_string): case nox(t_string) #define cases_lit_5()\ case lit(t_mixedarray): case nox(t_mixedarray):\ case lit(t_shortarray): case nox(t_shortarray):\ case plain(t_device): case plain_exec(t_device):\ case plain(t_struct): case plain_exec(t_struct):\ case plain(t_astruct): case plain_exec(t_astruct) /* Executable arrays are treated as literals in direct execution. */ #define cases_lit_array()\ case exec(t_array): case exec(t_mixedarray): case exec(t_shortarray) cases_lit_1(): cases_lit_2(): cases_lit_3(): cases_lit_4(): cases_lit_5(): INCR(lit); break; cases_lit_array(): INCR(lit_array); break; /* Special operators. */ case plain_exec(tx_op_add): x_add: INCR(x_add); osp = iosp; /* sync o_stack */ if ((code = zop_add(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp--; next_either(); case plain_exec(tx_op_def): x_def: INCR(x_def); osp = iosp; /* sync o_stack */ if ((code = zop_def(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp -= 2; next_either(); case plain_exec(tx_op_dup): x_dup: INCR(x_dup); if (iosp < osbot) return_with_error_tx_op(gs_error_stackunderflow); if (iosp >= ostop) { o_stack.requested = 1; return_with_error_tx_op(gs_error_stackoverflow); } iosp++; ref_assign_inline(iosp, iosp - 1); next_either(); case plain_exec(tx_op_exch): x_exch: INCR(x_exch); if (iosp <= osbot) return_with_error_tx_op(gs_error_stackunderflow); ref_assign_inline(&token, iosp); ref_assign_inline(iosp, iosp - 1); ref_assign_inline(iosp - 1, &token); next_either(); case plain_exec(tx_op_if): x_if: INCR(x_if); if (!r_is_proc(iosp)) return_with_error_tx_op(check_proc_failed(iosp)); if (!r_has_type(iosp - 1, t_boolean)) return_with_error_tx_op((iosp <= osbot ? gs_error_stackunderflow : gs_error_typecheck)); if (!iosp[-1].value.boolval) { iosp -= 2; next_either(); } if (iesp >= estop) return_with_error_tx_op(gs_error_execstackoverflow); store_state_either(iesp); whichp = iosp; iosp -= 2; goto ifup; case plain_exec(tx_op_ifelse): x_ifelse: INCR(x_ifelse); if (!r_is_proc(iosp)) return_with_error_tx_op(check_proc_failed(iosp)); if (!r_is_proc(iosp - 1)) return_with_error_tx_op(check_proc_failed(iosp - 1)); if (!r_has_type(iosp - 2, t_boolean)) return_with_error_tx_op((iosp < osbot + 2 ? gs_error_stackunderflow : gs_error_typecheck)); if (iesp >= estop) return_with_error_tx_op(gs_error_execstackoverflow); store_state_either(iesp); whichp = (iosp[-2].value.boolval ? iosp - 1 : iosp); iosp -= 3; /* Open code "up" for the array case(s) */ ifup:if ((icount = r_size(whichp) - 1) <= 0) { if (icount < 0) goto up; /* 0-element proc */ SET_IREF(whichp->value.refs); /* 1-element proc */ if (--(*ticks_left) > 0) goto top; } ++iesp; /* Do a ref_assign, but also set iref. */ iesp->tas = whichp->tas; SET_IREF(iesp->value.refs = whichp->value.refs); if (--(*ticks_left) > 0) goto top; goto slice; case plain_exec(tx_op_index): x_index: INCR(x_index); osp = iosp; /* zindex references o_stack */ if ((code = zindex(i_ctx_p)) < 0) return_with_error_tx_op(code); next_either(); case plain_exec(tx_op_pop): x_pop: INCR(x_pop); if (iosp < osbot) return_with_error_tx_op(gs_error_stackunderflow); iosp--; next_either(); case plain_exec(tx_op_roll): x_roll: INCR(x_roll); osp = iosp; /* zroll references o_stack */ if ((code = zroll(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp -= 2; next_either(); case plain_exec(tx_op_sub): x_sub: INCR(x_sub); osp = iosp; /* sync o_stack */ if ((code = zop_sub(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp--; next_either(); /* Executable types. */ case plain_exec(t_null): goto bot; case plain_exec(t_oparray): /* Replace with the definition and go again. */ INCR(exec_array); opindex = op_index(IREF); pvalue = (ref *)IREF->value.const_refs; opst: /* Prepare to call a t_oparray procedure in *pvalue. */ store_state(iesp); oppr: /* Record the stack depths in case of failure. */ if (iesp >= estop - 4) return_with_error_iref(gs_error_execstackoverflow); iesp += 5; osp = iosp; /* ref_stack_count_inline needs this */ make_mark_estack(iesp - 4, es_other, oparray_cleanup); make_int(iesp - 3, opindex); /* for .errorexec effect */ make_int(iesp - 2, ref_stack_count_inline(&o_stack)); make_int(iesp - 1, ref_stack_count_inline(&d_stack)); make_op_estack(iesp, oparray_pop); goto pr; prst: /* Prepare to call the procedure (array) in *pvalue. */ store_state(iesp); pr: /* Call the array in *pvalue. State has been stored. */ /* We want to do this check before assigning icount so icount is correct * in the event of a gs_error_execstackoverflow */ if (iesp >= estop) { return_with_error_iref(gs_error_execstackoverflow); } if ((icount = r_size(pvalue) - 1) <= 0) { if (icount < 0) goto up; /* 0-element proc */ SET_IREF(pvalue->value.refs); /* 1-element proc */ if (--(*ticks_left) > 0) goto top; } ++iesp; /* Do a ref_assign, but also set iref. */ iesp->tas = pvalue->tas; SET_IREF(iesp->value.refs = pvalue->value.refs); if (--(*ticks_left) > 0) goto top; goto slice; case plain_exec(t_operator): INCR(exec_operator); if (--(*ticks_left) <= 0) { /* The following doesn't work, */ /* and I can't figure out why. */ /****** goto sst; ******/ } esp = iesp; /* save for operator */ osp = iosp; /* ditto */ /* Operator routines take osp as an argument. */ /* This is just a convenience, since they adjust */ /* osp themselves to reflect the results. */ /* Operators that (net) push information on the */ /* operand stack must check for overflow: */ /* this normally happens automatically through */ /* the push macro (in oper.h). */ /* Operators that do not typecheck their operands, */ /* or take a variable number of arguments, */ /* must check explicitly for stack underflow. */ /* (See oper.h for more detail.) */ /* Note that each case must set iosp = osp: */ /* this is so we can switch on code without having to */ /* store it and reload it (for dumb compilers). */ switch (code = call_operator(real_opproc(IREF), i_ctx_p)) { case 0: /* normal case */ case 1: /* alternative success case */ iosp = osp; next(); case o_push_estack: /* store the state and go to up */ store_state(iesp); opush:iosp = osp; iesp = esp; if (--(*ticks_left) > 0) goto up; goto slice; case o_pop_estack: /* just go to up */ opop:iosp = osp; if (esp == iesp) goto bot; iesp = esp; goto up; case o_reschedule: store_state(iesp); goto res; case gs_error_Remap_Color: oe_remap: store_state(iesp); remap: if (iesp + 2 >= estop) { esp = iesp; code = ref_stack_extend(&e_stack, 2); if (code < 0) return_with_error_iref(code); iesp = esp; } packed_get(imemory, iref_packed, iesp + 1); make_oper(iesp + 2, 0, r_ptr(&istate->remap_color_info, int_remap_color_info_t)->proc); iesp += 2; goto up; } iosp = osp; iesp = esp; return_with_code_iref(); case plain_exec(t_name): INCR(exec_name); pvalue = IREF->value.pname->pvalue; if (!pv_valid(pvalue)) { uint nidx = names_index(int_nt, IREF); uint htemp; INCR(find_name); if ((pvalue = dict_find_name_by_index_inline(nidx, htemp)) == 0) return_with_error_iref(gs_error_undefined); } /* Dispatch on the type of the value. */ /* Again, we have to over-populate the switch. */ switch (r_type_xe(pvalue)) { cases_invalid(): return_with_error_iref(gs_error_Fatal); cases_nox(): /* access errors */ return_with_error_iref(gs_error_invalidaccess); cases_lit_1(): cases_lit_2(): cases_lit_3(): cases_lit_4(): cases_lit_5(): INCR(name_lit); /* Just push the value */ if (iosp >= ostop) return_with_stackoverflow(pvalue); ++iosp; ref_assign_inline(iosp, pvalue); next(); case exec(t_array): case exec(t_mixedarray): case exec(t_shortarray): INCR(name_proc); /* This is an executable procedure, execute it. */ goto prst; case plain_exec(tx_op_add): goto x_add; case plain_exec(tx_op_def): goto x_def; case plain_exec(tx_op_dup): goto x_dup; case plain_exec(tx_op_exch): goto x_exch; case plain_exec(tx_op_if): goto x_if; case plain_exec(tx_op_ifelse): goto x_ifelse; case plain_exec(tx_op_index): goto x_index; case plain_exec(tx_op_pop): goto x_pop; case plain_exec(tx_op_roll): goto x_roll; case plain_exec(tx_op_sub): goto x_sub; case plain_exec(t_null): goto bot; case plain_exec(t_oparray): INCR(name_oparray); opindex = op_index(pvalue); pvalue = (ref *)pvalue->value.const_refs; goto opst; case plain_exec(t_operator): INCR(name_operator); { /* Shortcut for operators. */ /* See above for the logic. */ if (--(*ticks_left) <= 0) { /* The following doesn't work, */ /* and I can't figure out why. */ /****** goto sst; ******/ } esp = iesp; osp = iosp; switch (code = call_operator(real_opproc(pvalue), i_ctx_p) ) { case 0: /* normal case */ case 1: /* alternative success case */ iosp = osp; next(); case o_push_estack: store_state(iesp); goto opush; case o_pop_estack: goto opop; case o_reschedule: store_state(iesp); goto res; case gs_error_Remap_Color: goto oe_remap; } iosp = osp; iesp = esp; return_with_error(code, pvalue); } case plain_exec(t_name): case exec(t_file): case exec(t_string): default: /* Not a procedure, reinterpret it. */ store_state(iesp); icount = 0; SET_IREF(pvalue); goto top; } case exec(t_file): { /* Executable file. Read the next token and interpret it. */ stream *s; scanner_state sstate; check_read_known_file(i_ctx_p, s, IREF, return_with_error_iref); rt: if (iosp >= ostop) /* check early */ return_with_stackoverflow_iref(); osp = iosp; /* gs_scan_token uses ostack */ gs_scanner_init_options(&sstate, IREF, i_ctx_p->scanner_options); again: code = gs_scan_token(i_ctx_p, &token, &sstate); iosp = osp; /* ditto */ switch (code) { case 0: /* read a token */ /* It's worth checking for literals, which make up */ /* the majority of input tokens, before storing the */ /* state on the e-stack. Note that because of //, */ /* the token may have *any* type and attributes. */ /* Note also that executable arrays aren't executed */ /* at the top level -- they're treated as literals. */ if (!r_has_attr(&token, a_executable) || r_is_array(&token) ) { /* If gs_scan_token used the o-stack, */ /* we know we can do a push now; if not, */ /* the pre-check is still valid. */ iosp++; ref_assign_inline(iosp, &token); goto rt; } store_state(iesp); /* Push the file on the e-stack */ if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); esfile_set_cache(++iesp); ref_assign_inline(iesp, IREF); SET_IREF(&token); icount = 0; goto top; case gs_error_undefined: /* //name undefined */ gs_scanner_error_object(i_ctx_p, &sstate, &token); return_with_error(code, &token); case scan_EOF: /* end of file */ esfile_clear_cache(); goto bot; case scan_BOS: /* Binary object sequences */ /* ARE executed at the top level. */ store_state(iesp); /* Push the file on the e-stack */ if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); esfile_set_cache(++iesp); ref_assign_inline(iesp, IREF); pvalue = &token; goto pr; case scan_Refill: store_state(iesp); /* iref may point into the exec stack; */ /* save its referent now. */ ref_assign_inline(&token, IREF); /* Push the file on the e-stack */ if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); ++iesp; ref_assign_inline(iesp, &token); esp = iesp; osp = iosp; code = gs_scan_handle_refill(i_ctx_p, &sstate, true, ztokenexec_continue); scan_cont: iosp = osp; iesp = esp; switch (code) { case 0: iesp--; /* don't push the file */ goto again; /* stacks are unchanged */ case o_push_estack: esfile_clear_cache(); if (--(*ticks_left) > 0) goto up; goto slice; } /* must be an error */ iesp--; /* don't push the file */ return_with_code_iref(); case scan_Comment: case scan_DSC_Comment: { /* See scan_Refill above for comments. */ ref file_token; store_state(iesp); ref_assign_inline(&file_token, IREF); if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); ++iesp; ref_assign_inline(iesp, &file_token); esp = iesp; osp = iosp; code = ztoken_handle_comment(i_ctx_p, &sstate, &token, code, true, true, ztokenexec_continue); } goto scan_cont; default: /* error */ ref_assign_inline(&token, IREF); gs_scanner_error_object(i_ctx_p, &sstate, &token); return_with_error(code, &token); } } case exec(t_string): { /* Executable string. Read a token and interpret it. */ stream ss; scanner_state sstate; s_init(&ss, NULL); sread_string(&ss, IREF->value.bytes, r_size(IREF)); gs_scanner_init_stream_options(&sstate, &ss, SCAN_FROM_STRING); osp = iosp; /* gs_scan_token uses ostack */ code = gs_scan_token(i_ctx_p, &token, &sstate); iosp = osp; /* ditto */ switch (code) { case 0: /* read a token */ case scan_BOS: /* binary object sequence */ store_state(iesp); /* If the updated string isn't empty, push it back */ /* on the e-stack. */ { uint size = sbufavailable(&ss); if (size) { if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); ++iesp; iesp->tas.type_attrs = IREF->tas.type_attrs; iesp->value.const_bytes = sbufptr(&ss); r_set_size(iesp, size); } } if (code == 0) { SET_IREF(&token); icount = 0; goto top; } /* Handle BOS specially */ pvalue = &token; goto pr; case scan_EOF: /* end of string */ goto bot; case scan_Refill: /* error */ code = gs_note_error(gs_error_syntaxerror); /* fall through */ default: /* error */ ref_assign_inline(&token, IREF); gs_scanner_error_object(i_ctx_p, &sstate, &token); return_with_error(code, &token); } } /* Handle packed arrays here by re-dispatching. */ /* This also picks up some anomalous cases of non-packed arrays. */ default: { uint index; switch (*iref_packed >> r_packed_type_shift) { case pt_full_ref: case pt_full_ref + 1: INCR(p_full); if (iosp >= ostop) return_with_stackoverflow_iref(); /* We know this can't be an executable object */ /* requiring special handling, so we just push it. */ ++iosp; /* We know that refs are properly aligned: */ /* see packed.h for details. */ ref_assign_inline(iosp, IREF); next(); case pt_executable_operator: index = *iref_packed & packed_value_mask; if (--(*ticks_left) <= 0) { /* The following doesn't work, */ /* and I can't figure out why. */ /****** goto sst_short; ******/ } if (!op_index_is_operator(index)) { INCR(p_exec_oparray); store_state_short(iesp); opindex = index; /* Call the operator procedure. */ index -= op_def_count; pvalue = (ref *) (index < r_size(&i_ctx_p->op_array_table_global.table) ? i_ctx_p->op_array_table_global.table.value.const_refs + index : i_ctx_p->op_array_table_local.table.value.const_refs + (index - r_size(&i_ctx_p->op_array_table_global.table))); goto oppr; } INCR(p_exec_operator); /* See the main plain_exec(t_operator) case */ /* for details of what happens here. */ #if PACKED_SPECIAL_OPS /* * We arranged in iinit.c that the special ops * have operator indices starting at 1. * * The (int) cast in the next line is required * because some compilers don't allow arithmetic * involving two different enumerated types. */ # define case_xop(xop) case xop - (int)tx_op + 1 switch (index) { case_xop(tx_op_add):goto x_add; case_xop(tx_op_def):goto x_def; case_xop(tx_op_dup):goto x_dup; case_xop(tx_op_exch):goto x_exch; case_xop(tx_op_if):goto x_if; case_xop(tx_op_ifelse):goto x_ifelse; case_xop(tx_op_index):goto x_index; case_xop(tx_op_pop):goto x_pop; case_xop(tx_op_roll):goto x_roll; case_xop(tx_op_sub):goto x_sub; case 0: /* for dumb compilers */ default: ; } # undef case_xop #endif INCR(p_exec_non_x_operator); esp = iesp; osp = iosp; switch (code = call_operator(op_index_proc(index), i_ctx_p)) { case 0: case 1: iosp = osp; next_short(); case o_push_estack: store_state_short(iesp); goto opush; case o_pop_estack: iosp = osp; if (esp == iesp) { next_short(); } iesp = esp; goto up; case o_reschedule: store_state_short(iesp); goto res; case gs_error_Remap_Color: store_state_short(iesp); goto remap; } iosp = osp; iesp = esp; return_with_code_iref(); case pt_integer: INCR(p_integer); if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; make_int(iosp, ((int)*iref_packed & packed_int_mask) + packed_min_intval); next_short(); case pt_literal_name: INCR(p_lit_name); { uint nidx = *iref_packed & packed_value_mask; if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; name_index_ref_inline(int_nt, nidx, iosp); next_short(); } case pt_executable_name: INCR(p_exec_name); { uint nidx = *iref_packed & packed_value_mask; pvalue = name_index_ptr_inline(int_nt, nidx)->pvalue; if (!pv_valid(pvalue)) { uint htemp; INCR(p_find_name); if ((pvalue = dict_find_name_by_index_inline(nidx, htemp)) == 0) { names_index_ref(int_nt, nidx, &token); return_with_error(gs_error_undefined, &token); } } if (r_has_masked_attrs(pvalue, a_execute, a_execute + a_executable)) { /* Literal, push it. */ INCR(p_name_lit); if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; ref_assign_inline(iosp, pvalue); next_short(); } if (r_is_proc(pvalue)) { /* This is an executable procedure, */ /* execute it. */ INCR(p_name_proc); store_state_short(iesp); goto pr; } /* Not a literal or procedure, reinterpret it. */ store_state_short(iesp); icount = 0; SET_IREF(pvalue); goto top; } /* default can't happen here */ } } } /* Literal type, just push it. */ if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; ref_assign_inline(iosp, IREF); bot:next(); out: /* At most 1 more token in the current procedure. */ /* (We already decremented icount.) */ if (!icount) { /* Pop the execution stack for tail recursion. */ iesp--; iref_packed = IREF_NEXT(iref_packed); goto top; } up:if (--(*ticks_left) < 0) goto slice; /* See if there is anything left on the execution stack. */ if (!r_is_proc(iesp)) { SET_IREF(iesp--); icount = 0; goto top; } SET_IREF(iesp->value.refs); /* next element of array */ icount = r_size(iesp) - 1; if (icount <= 0) { /* <= 1 more elements */ iesp--; /* pop, or tail recursion */ if (icount < 0) goto up; } goto top; res: /* Some operator has asked for context rescheduling. */ /* We've done a store_state. */ *pi_ctx_p = i_ctx_p; code = (*i_ctx_p->reschedule_proc)(pi_ctx_p); i_ctx_p = *pi_ctx_p; sched: /* We've just called a scheduling procedure. */ /* The interpreter state is in memory; iref is not current. */ if (code < 0) { set_error(code); /* * We need a real object to return as the error object. * (It only has to last long enough to store in * *perror_object.) */ make_null_proc(&ierror.full); SET_IREF(ierror.obj = &ierror.full); goto error_exit; } /* Reload state information from memory. */ iosp = osp; iesp = esp; goto up; #if 0 /****** ****** ***** */ sst: /* Time-slice, but push the current object first. */ store_state(iesp); if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); iesp++; ref_assign_inline(iesp, iref); #endif /****** ****** ***** */ slice: /* It's time to time-slice or garbage collect. */ /* iref is not live, so we don't need to do a store_state. */ osp = iosp; esp = iesp; /* If *ticks_left <= -100, we need to GC now. */ if ((*ticks_left) <= -100) { /* We need to garbage collect now. */ *pi_ctx_p = i_ctx_p; code = interp_reclaim(pi_ctx_p, -1); i_ctx_p = *pi_ctx_p; } else if (i_ctx_p->time_slice_proc != NULL) { *pi_ctx_p = i_ctx_p; code = (*i_ctx_p->time_slice_proc)(pi_ctx_p); i_ctx_p = *pi_ctx_p; } else code = 0; *ticks_left = i_ctx_p->time_slice_ticks; set_code_on_interrupt(imemory, &code); goto sched; /* Error exits. */ rweci: ierror.code = code; rwei: ierror.obj = IREF; rwe: if (!r_is_packed(iref_packed)) store_state(iesp); else { /* * We need a real object to return as the error object. * (It only has to last long enough to store in *perror_object.) */ packed_get(imemory, (const ref_packed *)ierror.obj, &ierror.full); store_state_short(iesp); if (IREF == ierror.obj) SET_IREF(&ierror.full); ierror.obj = &ierror.full; } error_exit: if (GS_ERROR_IS_INTERRUPT(ierror.code)) { /* We must push the current object being interpreted */ /* back on the e-stack so it will be re-executed. */ /* Currently, this is always an executable operator, */ /* but it might be something else someday if we check */ /* for interrupts in the interpreter loop itself. */ if (iesp >= estop) ierror.code = gs_error_execstackoverflow; else { iesp++; ref_assign_inline(iesp, IREF); } } esp = iesp; osp = iosp; ref_assign_inline(perror_object, ierror.obj); #ifdef DEBUG if (ierror.code == gs_error_InterpreterExit) { /* Do not call gs_log_error to reduce the noise. */ return gs_error_InterpreterExit; } #endif return gs_log_error(ierror.code, __FILE__, ierror.line); }
null
0
interp(i_ctx_t **pi_ctx_p /* context for execution, updated if resched */, const ref * pref /* object to interpret */, ref * perror_object) { i_ctx_t *i_ctx_p = *pi_ctx_p; /* * Note that iref may actually be either a ref * or a ref_packed *. * Certain DEC compilers assume that a ref * is ref-aligned even if it * is cast to a short *, and generate code on this assumption, leading * to "unaligned access" errors. For this reason, we declare * iref_packed, and use a macro to cast it to the more aligned type * where necessary (which is almost everywhere it is used). This may * lead to compiler warnings about "cast increases alignment * requirements", but this is less harmful than expensive traps at run * time. */ register const ref_packed *iref_packed = (const ref_packed *)pref; /* * To make matters worse, some versions of gcc/egcs have a bug that * leads them to assume that if iref_packed is EVER cast to a ref *, * it is ALWAYS ref-aligned. We detect this in stdpre.h and provide * the following workaround: */ #ifdef ALIGNMENT_ALIASING_BUG const ref *iref_temp; # define IREF (iref_temp = (const ref *)iref_packed, iref_temp) #else # define IREF ((const ref *)iref_packed) #endif #define SET_IREF(rp) (iref_packed = (const ref_packed *)(rp)) register int icount = 0; /* # of consecutive tokens at iref */ register os_ptr iosp = osp; /* private copy of osp */ register es_ptr iesp = esp; /* private copy of esp */ int code; ref token; /* token read from file or string, */ /* must be declared in this scope */ ref *pvalue; ref refnull; uint opindex; /* needed for oparrays */ os_ptr whichp; /* * We have to make the error information into a struct; * otherwise, the Watcom compiler will assign it to registers * strictly on the basis of textual frequency. * We also have to use ref_assign_inline everywhere, and * avoid direct assignments of refs, so that esi and edi * will remain available on Intel processors. */ struct interp_error_s { int code; int line; const ref *obj; ref full; } ierror; /* * Get a pointer to the name table so that we can use the * inline version of name_index_ref. */ const name_table *const int_nt = imemory->gs_lib_ctx->gs_name_table; #define set_error(ecode)\ { ierror.code = ecode; ierror.line = __LINE__; } #define return_with_error(ecode, objp)\ { set_error(ecode); ierror.obj = objp; goto rwe; } #define return_with_error_iref(ecode)\ { set_error(ecode); goto rwei; } #define return_with_code_iref()\ { ierror.line = __LINE__; goto rweci; } #define return_with_stackoverflow(objp)\ { o_stack.requested = 1; return_with_error(gs_error_stackoverflow, objp); } #define return_with_stackoverflow_iref()\ { o_stack.requested = 1; return_with_error_iref(gs_error_stackoverflow); } /* * If control reaches the special operators (x_add, etc.) as a result of * interpreting an executable name, iref points to the name, not the * operator, so the name rather than the operator becomes the error object, * which is wrong. We detect and handle this case explicitly when an error * occurs, so as not to slow down the non-error case. */ #define return_with_error_tx_op(err_code)\ { if (r_has_type(IREF, t_name)) {\ return_with_error(err_code, pvalue);\ } else {\ return_with_error_iref(err_code);\ }\ } int *ticks_left = &imemory_system->gs_lib_ctx->gcsignal; #if defined(DEBUG_TRACE_PS_OPERATORS) || defined(DEBUG) int (*call_operator_fn)(op_proc_t, i_ctx_t *) = do_call_operator; if (gs_debug_c('!')) call_operator_fn = do_call_operator_verbose; #endif *ticks_left = i_ctx_p->time_slice_ticks; make_null(&ierror.full); ierror.obj = &ierror.full; make_null(&refnull); pvalue = &refnull; /* * If we exceed the VMThreshold, set *ticks_left to -100 * to alert the interpreter that we need to garbage collect. */ set_gc_signal(i_ctx_p, -100); esfile_clear_cache(); /* * From here on, if icount > 0, iref and icount correspond * to the top entry on the execution stack: icount is the count * of sequential entries remaining AFTER the current one. */ #define IREF_NEXT(ip)\ ((const ref_packed *)((const ref *)(ip) + 1)) #define IREF_NEXT_EITHER(ip)\ ( r_is_packed(ip) ? (ip) + 1 : IREF_NEXT(ip) ) #define store_state(ep)\ ( icount > 0 ? (ep->value.const_refs = IREF + 1, r_set_size(ep, icount)) : 0 ) #define store_state_short(ep)\ ( icount > 0 ? (ep->value.packed = iref_packed + 1, r_set_size(ep, icount)) : 0 ) #define store_state_either(ep)\ ( icount > 0 ? (ep->value.packed = IREF_NEXT_EITHER(iref_packed), r_set_size(ep, icount)) : 0 ) #define next()\ if ( --icount > 0 ) { iref_packed = IREF_NEXT(iref_packed); goto top; } else goto out #define next_short()\ if ( --icount <= 0 ) { if ( icount < 0 ) goto up; iesp--; }\ ++iref_packed; goto top #define next_either()\ if ( --icount <= 0 ) { if ( icount < 0 ) goto up; iesp--; }\ iref_packed = IREF_NEXT_EITHER(iref_packed); goto top #if !PACKED_SPECIAL_OPS # undef next_either # define next_either() next() # undef store_state_either # define store_state_either(ep) store_state(ep) #endif /* We want to recognize executable arrays here, */ /* so we push the argument on the estack and enter */ /* the loop at the bottom. */ if (iesp >= estop) return_with_error(gs_error_execstackoverflow, pref); ++iesp; ref_assign_inline(iesp, pref); goto bot; top: /* * This is the top of the interpreter loop. * iref points to the ref being interpreted. * Note that this might be an element of a packed array, * not a real ref: we carefully arranged the first 16 bits of * a ref and of a packed array element so they could be distinguished * from each other. (See ghost.h and packed.h for more detail.) */ INCR(top); #ifdef DEBUG /* Do a little validation on the top o-stack entry. */ if (iosp >= osbot && (r_type(iosp) == t__invalid || r_type(iosp) >= tx_next_op) ) { mlprintf(imemory, "Invalid value on o-stack!\n"); return_with_error_iref(gs_error_Fatal); } if (gs_debug['I'] || (gs_debug['i'] && (r_is_packed(iref_packed) ? r_packed_is_name(iref_packed) : r_has_type(IREF, t_name))) ) { os_ptr save_osp = osp; /* avoid side-effects */ es_ptr save_esp = esp; osp = iosp; esp = iesp; dmlprintf5(imemory, "d%u,e%u<%u>0x%lx(%d): ", ref_stack_count(&d_stack), ref_stack_count(&e_stack), ref_stack_count(&o_stack), (ulong)IREF, icount); debug_print_ref(imemory, IREF); if (iosp >= osbot) { dmputs(imemory, " // "); debug_print_ref(imemory, iosp); } dmputc(imemory, '\n'); osp = save_osp; esp = save_esp; dmflush(imemory); } #endif /* Objects that have attributes (arrays, dictionaries, files, and strings) */ /* use lit and exec; other objects use plain and plain_exec. */ #define lit(t) type_xe_value(t, a_execute) #define exec(t) type_xe_value(t, a_execute + a_executable) #define nox(t) type_xe_value(t, 0) #define nox_exec(t) type_xe_value(t, a_executable) #define plain(t) type_xe_value(t, 0) #define plain_exec(t) type_xe_value(t, a_executable) /* * We have to populate enough cases of the switch statement to force * some compilers to use a dispatch rather than a testing loop. * What a nuisance! */ switch (r_type_xe(iref_packed)) { /* Access errors. */ #define cases_invalid()\ case plain(t__invalid): case plain_exec(t__invalid) cases_invalid(): return_with_error_iref(gs_error_Fatal); #define cases_nox()\ case nox_exec(t_array): case nox_exec(t_dictionary):\ case nox_exec(t_file): case nox_exec(t_string):\ case nox_exec(t_mixedarray): case nox_exec(t_shortarray) cases_nox(): return_with_error_iref(gs_error_invalidaccess); /* * Literal objects. We have to enumerate all the types. * In fact, we have to include some extra plain_exec entries * just to populate the switch. We break them up into groups * to avoid overflowing some preprocessors. */ #define cases_lit_1()\ case lit(t_array): case nox(t_array):\ case plain(t_boolean): case plain_exec(t_boolean):\ case lit(t_dictionary): case nox(t_dictionary) #define cases_lit_2()\ case lit(t_file): case nox(t_file):\ case plain(t_fontID): case plain_exec(t_fontID):\ case plain(t_integer): case plain_exec(t_integer):\ case plain(t_mark): case plain_exec(t_mark) #define cases_lit_3()\ case plain(t_name):\ case plain(t_null):\ case plain(t_oparray):\ case plain(t_operator) #define cases_lit_4()\ case plain(t_real): case plain_exec(t_real):\ case plain(t_save): case plain_exec(t_save):\ case lit(t_string): case nox(t_string) #define cases_lit_5()\ case lit(t_mixedarray): case nox(t_mixedarray):\ case lit(t_shortarray): case nox(t_shortarray):\ case plain(t_device): case plain_exec(t_device):\ case plain(t_struct): case plain_exec(t_struct):\ case plain(t_astruct): case plain_exec(t_astruct) /* Executable arrays are treated as literals in direct execution. */ #define cases_lit_array()\ case exec(t_array): case exec(t_mixedarray): case exec(t_shortarray) cases_lit_1(): cases_lit_2(): cases_lit_3(): cases_lit_4(): cases_lit_5(): INCR(lit); break; cases_lit_array(): INCR(lit_array); break; /* Special operators. */ case plain_exec(tx_op_add): x_add: INCR(x_add); osp = iosp; /* sync o_stack */ if ((code = zop_add(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp--; next_either(); case plain_exec(tx_op_def): x_def: INCR(x_def); osp = iosp; /* sync o_stack */ if ((code = zop_def(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp -= 2; next_either(); case plain_exec(tx_op_dup): x_dup: INCR(x_dup); if (iosp < osbot) return_with_error_tx_op(gs_error_stackunderflow); if (iosp >= ostop) { o_stack.requested = 1; return_with_error_tx_op(gs_error_stackoverflow); } iosp++; ref_assign_inline(iosp, iosp - 1); next_either(); case plain_exec(tx_op_exch): x_exch: INCR(x_exch); if (iosp <= osbot) return_with_error_tx_op(gs_error_stackunderflow); ref_assign_inline(&token, iosp); ref_assign_inline(iosp, iosp - 1); ref_assign_inline(iosp - 1, &token); next_either(); case plain_exec(tx_op_if): x_if: INCR(x_if); if (!r_is_proc(iosp)) return_with_error_tx_op(check_proc_failed(iosp)); if (!r_has_type(iosp - 1, t_boolean)) return_with_error_tx_op((iosp <= osbot ? gs_error_stackunderflow : gs_error_typecheck)); if (!iosp[-1].value.boolval) { iosp -= 2; next_either(); } if (iesp >= estop) return_with_error_tx_op(gs_error_execstackoverflow); store_state_either(iesp); whichp = iosp; iosp -= 2; goto ifup; case plain_exec(tx_op_ifelse): x_ifelse: INCR(x_ifelse); if (!r_is_proc(iosp)) return_with_error_tx_op(check_proc_failed(iosp)); if (!r_is_proc(iosp - 1)) return_with_error_tx_op(check_proc_failed(iosp - 1)); if (!r_has_type(iosp - 2, t_boolean)) return_with_error_tx_op((iosp < osbot + 2 ? gs_error_stackunderflow : gs_error_typecheck)); if (iesp >= estop) return_with_error_tx_op(gs_error_execstackoverflow); store_state_either(iesp); whichp = (iosp[-2].value.boolval ? iosp - 1 : iosp); iosp -= 3; /* Open code "up" for the array case(s) */ ifup:if ((icount = r_size(whichp) - 1) <= 0) { if (icount < 0) goto up; /* 0-element proc */ SET_IREF(whichp->value.refs); /* 1-element proc */ if (--(*ticks_left) > 0) goto top; } ++iesp; /* Do a ref_assign, but also set iref. */ iesp->tas = whichp->tas; SET_IREF(iesp->value.refs = whichp->value.refs); if (--(*ticks_left) > 0) goto top; goto slice; case plain_exec(tx_op_index): x_index: INCR(x_index); osp = iosp; /* zindex references o_stack */ if ((code = zindex(i_ctx_p)) < 0) return_with_error_tx_op(code); next_either(); case plain_exec(tx_op_pop): x_pop: INCR(x_pop); if (iosp < osbot) return_with_error_tx_op(gs_error_stackunderflow); iosp--; next_either(); case plain_exec(tx_op_roll): x_roll: INCR(x_roll); osp = iosp; /* zroll references o_stack */ if ((code = zroll(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp -= 2; next_either(); case plain_exec(tx_op_sub): x_sub: INCR(x_sub); osp = iosp; /* sync o_stack */ if ((code = zop_sub(i_ctx_p)) < 0) return_with_error_tx_op(code); iosp--; next_either(); /* Executable types. */ case plain_exec(t_null): goto bot; case plain_exec(t_oparray): /* Replace with the definition and go again. */ INCR(exec_array); opindex = op_index(IREF); pvalue = (ref *)IREF->value.const_refs; opst: /* Prepare to call a t_oparray procedure in *pvalue. */ store_state(iesp); oppr: /* Record the stack depths in case of failure. */ if (iesp >= estop - 4) return_with_error_iref(gs_error_execstackoverflow); iesp += 5; osp = iosp; /* ref_stack_count_inline needs this */ make_mark_estack(iesp - 4, es_other, oparray_cleanup); make_int(iesp - 3, opindex); /* for .errorexec effect */ make_int(iesp - 2, ref_stack_count_inline(&o_stack)); make_int(iesp - 1, ref_stack_count_inline(&d_stack)); make_op_estack(iesp, oparray_pop); goto pr; prst: /* Prepare to call the procedure (array) in *pvalue. */ store_state(iesp); pr: /* Call the array in *pvalue. State has been stored. */ /* We want to do this check before assigning icount so icount is correct * in the event of a gs_error_execstackoverflow */ if (iesp >= estop) { return_with_error_iref(gs_error_execstackoverflow); } if ((icount = r_size(pvalue) - 1) <= 0) { if (icount < 0) goto up; /* 0-element proc */ SET_IREF(pvalue->value.refs); /* 1-element proc */ if (--(*ticks_left) > 0) goto top; } ++iesp; /* Do a ref_assign, but also set iref. */ iesp->tas = pvalue->tas; SET_IREF(iesp->value.refs = pvalue->value.refs); if (--(*ticks_left) > 0) goto top; goto slice; case plain_exec(t_operator): INCR(exec_operator); if (--(*ticks_left) <= 0) { /* The following doesn't work, */ /* and I can't figure out why. */ /****** goto sst; ******/ } esp = iesp; /* save for operator */ osp = iosp; /* ditto */ /* Operator routines take osp as an argument. */ /* This is just a convenience, since they adjust */ /* osp themselves to reflect the results. */ /* Operators that (net) push information on the */ /* operand stack must check for overflow: */ /* this normally happens automatically through */ /* the push macro (in oper.h). */ /* Operators that do not typecheck their operands, */ /* or take a variable number of arguments, */ /* must check explicitly for stack underflow. */ /* (See oper.h for more detail.) */ /* Note that each case must set iosp = osp: */ /* this is so we can switch on code without having to */ /* store it and reload it (for dumb compilers). */ switch (code = call_operator(real_opproc(IREF), i_ctx_p)) { case 0: /* normal case */ case 1: /* alternative success case */ iosp = osp; next(); case o_push_estack: /* store the state and go to up */ store_state(iesp); opush:iosp = osp; iesp = esp; if (--(*ticks_left) > 0) goto up; goto slice; case o_pop_estack: /* just go to up */ opop:iosp = osp; if (esp == iesp) goto bot; iesp = esp; goto up; case o_reschedule: store_state(iesp); goto res; case gs_error_Remap_Color: oe_remap: store_state(iesp); remap: if (iesp + 2 >= estop) { esp = iesp; code = ref_stack_extend(&e_stack, 2); if (code < 0) return_with_error_iref(code); iesp = esp; } packed_get(imemory, iref_packed, iesp + 1); make_oper(iesp + 2, 0, r_ptr(&istate->remap_color_info, int_remap_color_info_t)->proc); iesp += 2; goto up; } iosp = osp; iesp = esp; return_with_code_iref(); case plain_exec(t_name): INCR(exec_name); pvalue = IREF->value.pname->pvalue; if (!pv_valid(pvalue)) { uint nidx = names_index(int_nt, IREF); uint htemp; INCR(find_name); if ((pvalue = dict_find_name_by_index_inline(nidx, htemp)) == 0) return_with_error_iref(gs_error_undefined); } /* Dispatch on the type of the value. */ /* Again, we have to over-populate the switch. */ switch (r_type_xe(pvalue)) { cases_invalid(): return_with_error_iref(gs_error_Fatal); cases_nox(): /* access errors */ return_with_error_iref(gs_error_invalidaccess); cases_lit_1(): cases_lit_2(): cases_lit_3(): cases_lit_4(): cases_lit_5(): INCR(name_lit); /* Just push the value */ if (iosp >= ostop) return_with_stackoverflow(pvalue); ++iosp; ref_assign_inline(iosp, pvalue); next(); case exec(t_array): case exec(t_mixedarray): case exec(t_shortarray): INCR(name_proc); /* This is an executable procedure, execute it. */ goto prst; case plain_exec(tx_op_add): goto x_add; case plain_exec(tx_op_def): goto x_def; case plain_exec(tx_op_dup): goto x_dup; case plain_exec(tx_op_exch): goto x_exch; case plain_exec(tx_op_if): goto x_if; case plain_exec(tx_op_ifelse): goto x_ifelse; case plain_exec(tx_op_index): goto x_index; case plain_exec(tx_op_pop): goto x_pop; case plain_exec(tx_op_roll): goto x_roll; case plain_exec(tx_op_sub): goto x_sub; case plain_exec(t_null): goto bot; case plain_exec(t_oparray): INCR(name_oparray); opindex = op_index(pvalue); pvalue = (ref *)pvalue->value.const_refs; goto opst; case plain_exec(t_operator): INCR(name_operator); { /* Shortcut for operators. */ /* See above for the logic. */ if (--(*ticks_left) <= 0) { /* The following doesn't work, */ /* and I can't figure out why. */ /****** goto sst; ******/ } esp = iesp; osp = iosp; switch (code = call_operator(real_opproc(pvalue), i_ctx_p) ) { case 0: /* normal case */ case 1: /* alternative success case */ iosp = osp; next(); case o_push_estack: store_state(iesp); goto opush; case o_pop_estack: goto opop; case o_reschedule: store_state(iesp); goto res; case gs_error_Remap_Color: goto oe_remap; } iosp = osp; iesp = esp; return_with_error(code, pvalue); } case plain_exec(t_name): case exec(t_file): case exec(t_string): default: /* Not a procedure, reinterpret it. */ store_state(iesp); icount = 0; SET_IREF(pvalue); goto top; } case exec(t_file): { /* Executable file. Read the next token and interpret it. */ stream *s; scanner_state sstate; check_read_known_file(i_ctx_p, s, IREF, return_with_error_iref); rt: if (iosp >= ostop) /* check early */ return_with_stackoverflow_iref(); osp = iosp; /* gs_scan_token uses ostack */ gs_scanner_init_options(&sstate, IREF, i_ctx_p->scanner_options); again: code = gs_scan_token(i_ctx_p, &token, &sstate); iosp = osp; /* ditto */ switch (code) { case 0: /* read a token */ /* It's worth checking for literals, which make up */ /* the majority of input tokens, before storing the */ /* state on the e-stack. Note that because of //, */ /* the token may have *any* type and attributes. */ /* Note also that executable arrays aren't executed */ /* at the top level -- they're treated as literals. */ if (!r_has_attr(&token, a_executable) || r_is_array(&token) ) { /* If gs_scan_token used the o-stack, */ /* we know we can do a push now; if not, */ /* the pre-check is still valid. */ iosp++; ref_assign_inline(iosp, &token); goto rt; } store_state(iesp); /* Push the file on the e-stack */ if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); esfile_set_cache(++iesp); ref_assign_inline(iesp, IREF); SET_IREF(&token); icount = 0; goto top; case gs_error_undefined: /* //name undefined */ gs_scanner_error_object(i_ctx_p, &sstate, &token); return_with_error(code, &token); case scan_EOF: /* end of file */ esfile_clear_cache(); goto bot; case scan_BOS: /* Binary object sequences */ /* ARE executed at the top level. */ store_state(iesp); /* Push the file on the e-stack */ if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); esfile_set_cache(++iesp); ref_assign_inline(iesp, IREF); pvalue = &token; goto pr; case scan_Refill: store_state(iesp); /* iref may point into the exec stack; */ /* save its referent now. */ ref_assign_inline(&token, IREF); /* Push the file on the e-stack */ if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); ++iesp; ref_assign_inline(iesp, &token); esp = iesp; osp = iosp; code = gs_scan_handle_refill(i_ctx_p, &sstate, true, ztokenexec_continue); scan_cont: iosp = osp; iesp = esp; switch (code) { case 0: iesp--; /* don't push the file */ goto again; /* stacks are unchanged */ case o_push_estack: esfile_clear_cache(); if (--(*ticks_left) > 0) goto up; goto slice; } /* must be an error */ iesp--; /* don't push the file */ return_with_code_iref(); case scan_Comment: case scan_DSC_Comment: { /* See scan_Refill above for comments. */ ref file_token; store_state(iesp); ref_assign_inline(&file_token, IREF); if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); ++iesp; ref_assign_inline(iesp, &file_token); esp = iesp; osp = iosp; code = ztoken_handle_comment(i_ctx_p, &sstate, &token, code, true, true, ztokenexec_continue); } goto scan_cont; default: /* error */ ref_assign_inline(&token, IREF); gs_scanner_error_object(i_ctx_p, &sstate, &token); return_with_error(code, &token); } } case exec(t_string): { /* Executable string. Read a token and interpret it. */ stream ss; scanner_state sstate; s_init(&ss, NULL); sread_string(&ss, IREF->value.bytes, r_size(IREF)); gs_scanner_init_stream_options(&sstate, &ss, SCAN_FROM_STRING); osp = iosp; /* gs_scan_token uses ostack */ code = gs_scan_token(i_ctx_p, &token, &sstate); iosp = osp; /* ditto */ switch (code) { case 0: /* read a token */ case scan_BOS: /* binary object sequence */ store_state(iesp); /* If the updated string isn't empty, push it back */ /* on the e-stack. */ { uint size = sbufavailable(&ss); if (size) { if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); ++iesp; iesp->tas.type_attrs = IREF->tas.type_attrs; iesp->value.const_bytes = sbufptr(&ss); r_set_size(iesp, size); } } if (code == 0) { SET_IREF(&token); icount = 0; goto top; } /* Handle BOS specially */ pvalue = &token; goto pr; case scan_EOF: /* end of string */ goto bot; case scan_Refill: /* error */ code = gs_note_error(gs_error_syntaxerror); /* fall through */ default: /* error */ ref_assign_inline(&token, IREF); gs_scanner_error_object(i_ctx_p, &sstate, &token); return_with_error(code, &token); } } /* Handle packed arrays here by re-dispatching. */ /* This also picks up some anomalous cases of non-packed arrays. */ default: { uint index; switch (*iref_packed >> r_packed_type_shift) { case pt_full_ref: case pt_full_ref + 1: INCR(p_full); if (iosp >= ostop) return_with_stackoverflow_iref(); /* We know this can't be an executable object */ /* requiring special handling, so we just push it. */ ++iosp; /* We know that refs are properly aligned: */ /* see packed.h for details. */ ref_assign_inline(iosp, IREF); next(); case pt_executable_operator: index = *iref_packed & packed_value_mask; if (--(*ticks_left) <= 0) { /* The following doesn't work, */ /* and I can't figure out why. */ /****** goto sst_short; ******/ } if (!op_index_is_operator(index)) { INCR(p_exec_oparray); store_state_short(iesp); opindex = index; /* Call the operator procedure. */ index -= op_def_count; pvalue = (ref *) (index < r_size(&i_ctx_p->op_array_table_global.table) ? i_ctx_p->op_array_table_global.table.value.const_refs + index : i_ctx_p->op_array_table_local.table.value.const_refs + (index - r_size(&i_ctx_p->op_array_table_global.table))); goto oppr; } INCR(p_exec_operator); /* See the main plain_exec(t_operator) case */ /* for details of what happens here. */ #if PACKED_SPECIAL_OPS /* * We arranged in iinit.c that the special ops * have operator indices starting at 1. * * The (int) cast in the next line is required * because some compilers don't allow arithmetic * involving two different enumerated types. */ # define case_xop(xop) case xop - (int)tx_op + 1 switch (index) { case_xop(tx_op_add):goto x_add; case_xop(tx_op_def):goto x_def; case_xop(tx_op_dup):goto x_dup; case_xop(tx_op_exch):goto x_exch; case_xop(tx_op_if):goto x_if; case_xop(tx_op_ifelse):goto x_ifelse; case_xop(tx_op_index):goto x_index; case_xop(tx_op_pop):goto x_pop; case_xop(tx_op_roll):goto x_roll; case_xop(tx_op_sub):goto x_sub; case 0: /* for dumb compilers */ default: ; } # undef case_xop #endif INCR(p_exec_non_x_operator); esp = iesp; osp = iosp; switch (code = call_operator(op_index_proc(index), i_ctx_p)) { case 0: case 1: iosp = osp; next_short(); case o_push_estack: store_state_short(iesp); goto opush; case o_pop_estack: iosp = osp; if (esp == iesp) { next_short(); } iesp = esp; goto up; case o_reschedule: store_state_short(iesp); goto res; case gs_error_Remap_Color: store_state_short(iesp); goto remap; } iosp = osp; iesp = esp; return_with_code_iref(); case pt_integer: INCR(p_integer); if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; make_int(iosp, ((int)*iref_packed & packed_int_mask) + packed_min_intval); next_short(); case pt_literal_name: INCR(p_lit_name); { uint nidx = *iref_packed & packed_value_mask; if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; name_index_ref_inline(int_nt, nidx, iosp); next_short(); } case pt_executable_name: INCR(p_exec_name); { uint nidx = *iref_packed & packed_value_mask; pvalue = name_index_ptr_inline(int_nt, nidx)->pvalue; if (!pv_valid(pvalue)) { uint htemp; INCR(p_find_name); if ((pvalue = dict_find_name_by_index_inline(nidx, htemp)) == 0) { names_index_ref(int_nt, nidx, &token); return_with_error(gs_error_undefined, &token); } } if (r_has_masked_attrs(pvalue, a_execute, a_execute + a_executable)) { /* Literal, push it. */ INCR(p_name_lit); if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; ref_assign_inline(iosp, pvalue); next_short(); } if (r_is_proc(pvalue)) { /* This is an executable procedure, */ /* execute it. */ INCR(p_name_proc); store_state_short(iesp); goto pr; } /* Not a literal or procedure, reinterpret it. */ store_state_short(iesp); icount = 0; SET_IREF(pvalue); goto top; } /* default can't happen here */ } } } /* Literal type, just push it. */ if (iosp >= ostop) return_with_stackoverflow_iref(); ++iosp; ref_assign_inline(iosp, IREF); bot:next(); out: /* At most 1 more token in the current procedure. */ /* (We already decremented icount.) */ if (!icount) { /* Pop the execution stack for tail recursion. */ iesp--; iref_packed = IREF_NEXT(iref_packed); goto top; } up:if (--(*ticks_left) < 0) goto slice; /* See if there is anything left on the execution stack. */ if (!r_is_proc(iesp)) { SET_IREF(iesp--); icount = 0; goto top; } SET_IREF(iesp->value.refs); /* next element of array */ icount = r_size(iesp) - 1; if (icount <= 0) { /* <= 1 more elements */ iesp--; /* pop, or tail recursion */ if (icount < 0) goto up; } goto top; res: /* Some operator has asked for context rescheduling. */ /* We've done a store_state. */ *pi_ctx_p = i_ctx_p; code = (*i_ctx_p->reschedule_proc)(pi_ctx_p); i_ctx_p = *pi_ctx_p; sched: /* We've just called a scheduling procedure. */ /* The interpreter state is in memory; iref is not current. */ if (code < 0) { set_error(code); /* * We need a real object to return as the error object. * (It only has to last long enough to store in * *perror_object.) */ make_null_proc(&ierror.full); SET_IREF(ierror.obj = &ierror.full); goto error_exit; } /* Reload state information from memory. */ iosp = osp; iesp = esp; goto up; #if 0 /****** ****** ***** */ sst: /* Time-slice, but push the current object first. */ store_state(iesp); if (iesp >= estop) return_with_error_iref(gs_error_execstackoverflow); iesp++; ref_assign_inline(iesp, iref); #endif /****** ****** ***** */ slice: /* It's time to time-slice or garbage collect. */ /* iref is not live, so we don't need to do a store_state. */ osp = iosp; esp = iesp; /* If *ticks_left <= -100, we need to GC now. */ if ((*ticks_left) <= -100) { /* We need to garbage collect now. */ *pi_ctx_p = i_ctx_p; code = interp_reclaim(pi_ctx_p, -1); i_ctx_p = *pi_ctx_p; } else if (i_ctx_p->time_slice_proc != NULL) { *pi_ctx_p = i_ctx_p; code = (*i_ctx_p->time_slice_proc)(pi_ctx_p); i_ctx_p = *pi_ctx_p; } else code = 0; *ticks_left = i_ctx_p->time_slice_ticks; set_code_on_interrupt(imemory, &code); goto sched; /* Error exits. */ rweci: ierror.code = code; rwei: ierror.obj = IREF; rwe: if (!r_is_packed(iref_packed)) store_state(iesp); else { /* * We need a real object to return as the error object. * (It only has to last long enough to store in *perror_object.) */ packed_get(imemory, (const ref_packed *)ierror.obj, &ierror.full); store_state_short(iesp); if (IREF == ierror.obj) SET_IREF(&ierror.full); ierror.obj = &ierror.full; } error_exit: if (GS_ERROR_IS_INTERRUPT(ierror.code)) { /* We must push the current object being interpreted */ /* back on the e-stack so it will be re-executed. */ /* Currently, this is always an executable operator, */ /* but it might be something else someday if we check */ /* for interrupts in the interpreter loop itself. */ if (iesp >= estop) ierror.code = gs_error_execstackoverflow; else { iesp++; ref_assign_inline(iesp, IREF); } } esp = iesp; osp = iosp; ref_assign_inline(perror_object, ierror.obj); #ifdef DEBUG if (ierror.code == gs_error_InterpreterExit) { /* Do not call gs_log_error to reduce the noise. */ return gs_error_InterpreterExit; } #endif return gs_log_error(ierror.code, __FILE__, ierror.line); }
@@ -676,7 +676,12 @@ again: /* Push the error object on the operand stack if appropriate. */ if (!GS_ERROR_IS_INTERRUPT(code)) { /* Replace the error object if within an oparray or .errorexec. */ - *++osp = *perror_object; + osp++; + if (osp >= ostop) { + *pexit_code = gs_error_Fatal; + return_error(gs_error_Fatal); + } + *osp = *perror_object; errorexec_find(i_ctx_p, osp); } goto again;
CWE-388
null
null
2,296
oparray_cleanup(i_ctx_t *i_ctx_p) { /* esp points just below the cleanup procedure. */ es_ptr ep = esp; uint ocount_old = (uint) ep[3].value.intval; uint dcount_old = (uint) ep[4].value.intval; uint ocount = ref_stack_count(&o_stack); uint dcount = ref_stack_count(&d_stack); if (ocount > ocount_old) ref_stack_pop(&o_stack, ocount - ocount_old); if (dcount > dcount_old) { ref_stack_pop(&d_stack, dcount - dcount_old); dict_set_top(); } return 0; }
null
0
oparray_cleanup(i_ctx_t *i_ctx_p) { /* esp points just below the cleanup procedure. */ es_ptr ep = esp; uint ocount_old = (uint) ep[3].value.intval; uint dcount_old = (uint) ep[4].value.intval; uint ocount = ref_stack_count(&o_stack); uint dcount = ref_stack_count(&d_stack); if (ocount > ocount_old) ref_stack_pop(&o_stack, ocount - ocount_old); if (dcount > dcount_old) { ref_stack_pop(&d_stack, dcount - dcount_old); dict_set_top(); } return 0; }
@@ -676,7 +676,12 @@ again: /* Push the error object on the operand stack if appropriate. */ if (!GS_ERROR_IS_INTERRUPT(code)) { /* Replace the error object if within an oparray or .errorexec. */ - *++osp = *perror_object; + osp++; + if (osp >= ostop) { + *pexit_code = gs_error_Fatal; + return_error(gs_error_Fatal); + } + *osp = *perror_object; errorexec_find(i_ctx_p, osp); } goto again;
CWE-388
null
null
2,297
oparray_no_cleanup(i_ctx_t *i_ctx_p) { return 0; }
null
0
oparray_no_cleanup(i_ctx_t *i_ctx_p) { return 0; }
@@ -676,7 +676,12 @@ again: /* Push the error object on the operand stack if appropriate. */ if (!GS_ERROR_IS_INTERRUPT(code)) { /* Replace the error object if within an oparray or .errorexec. */ - *++osp = *perror_object; + osp++; + if (osp >= ostop) { + *pexit_code = gs_error_Fatal; + return_error(gs_error_Fatal); + } + *osp = *perror_object; errorexec_find(i_ctx_p, osp); } goto again;
CWE-388
null
null
2,298
zerrorexec(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; check_op(2); check_estack(4); /* mark/cleanup, errobj, pop, obj */ push_mark_estack(es_other, errorexec_cleanup); *++esp = op[-1]; push_op_estack(errorexec_pop); code = zexec(i_ctx_p); if (code >= 0) pop(1); else esp -= 3; /* undo our additions to estack */ return code; }
null
0
zerrorexec(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; check_op(2); check_estack(4); /* mark/cleanup, errobj, pop, obj */ push_mark_estack(es_other, errorexec_cleanup); *++esp = op[-1]; push_op_estack(errorexec_pop); code = zexec(i_ctx_p); if (code >= 0) pop(1); else esp -= 3; /* undo our additions to estack */ return code; }
@@ -676,7 +676,12 @@ again: /* Push the error object on the operand stack if appropriate. */ if (!GS_ERROR_IS_INTERRUPT(code)) { /* Replace the error object if within an oparray or .errorexec. */ - *++osp = *perror_object; + osp++; + if (osp >= ostop) { + *pexit_code = gs_error_Fatal; + return_error(gs_error_Fatal); + } + *osp = *perror_object; errorexec_find(i_ctx_p, osp); } goto again;
CWE-388
null
null
2,299
zfinderrorobject(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref errobj; if (errorexec_find(i_ctx_p, &errobj)) { push(2); op[-1] = errobj; make_true(op); } else { push(1); make_false(op); } return 0; }
null
0
zfinderrorobject(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref errobj; if (errorexec_find(i_ctx_p, &errobj)) { push(2); op[-1] = errobj; make_true(op); } else { push(1); make_false(op); } return 0; }
@@ -676,7 +676,12 @@ again: /* Push the error object on the operand stack if appropriate. */ if (!GS_ERROR_IS_INTERRUPT(code)) { /* Replace the error object if within an oparray or .errorexec. */ - *++osp = *perror_object; + osp++; + if (osp >= ostop) { + *pexit_code = gs_error_Fatal; + return_error(gs_error_Fatal); + } + *osp = *perror_object; errorexec_find(i_ctx_p, osp); } goto again;
CWE-388
null
null