project
stringclasses 633
values | commit_id
stringlengths 7
81
| target
int64 0
1
| func
stringlengths 5
484k
| cwe
stringclasses 131
values | big_vul_idx
float64 0
189k
⌀ | idx
int64 0
522k
| hash
stringlengths 34
39
| size
float64 1
24k
⌀ | message
stringlengths 0
11.5k
⌀ | dataset
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validate_spaces(i_ctx_t *i_ctx_p, ref *arr, int *depth)
{
ref space, *sp = &space;
int code = 0;
PS_colour_space_t *obj;
ref_assign(&space, arr);
*depth = 0;
do {
code = get_space_object(i_ctx_p, sp, &obj);
if (code < 0)
return code;
(*depth)++;
if (!obj->validateproc)
break;
code = obj->validateproc(i_ctx_p, &sp);
if (code < 0)
return code;
}while(sp);
return 0;
}
|
CWE-704
| 3,157 | 13,245 |
173607376825206725515467557400610769859
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validatecalrgbspace(i_ctx_t * i_ctx_p, ref **r)
{
int code=0;
ref *space, calrgbdict;
space = *r;
if (!r_is_array(space))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(space) < 2)
return_error(gs_error_rangecheck);
code = array_get(imemory, space, 1, &calrgbdict);
if (code < 0)
return code;
if (!r_has_type(&calrgbdict, t_dictionary))
return_error(gs_error_typecheck);
/* Check the white point, which is required */
code = checkWhitePoint(i_ctx_p, &calrgbdict);
if (code != 0)
return code;
/* The rest are optional. Need to validate though */
code = checkBlackPoint(i_ctx_p, &calrgbdict);
if (code < 0)
return code;
/* Check Gamma values */
code = checkGamma(i_ctx_p, &calrgbdict, 3);
if (code < 0)
return code;
/* Check Matrix */
code = checkCalMatrix(i_ctx_p, &calrgbdict);
if (code < 0)
return code;
*r = 0; /* No nested space */
return 0;
}
|
CWE-704
| 3,159 | 13,246 |
291636827448119594005670850689925014518
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validatecieabcspace(i_ctx_t * i_ctx_p, ref **r)
{
int code = 0, i;
float value[9];
ref CIEdict, *CIEspace = *r, *tempref, valref;
if (!r_is_array(CIEspace))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(CIEspace) != 2)
return_error(gs_error_rangecheck);
code = array_get(imemory, CIEspace, 1, &CIEdict);
if (code < 0)
return code;
check_read_type(CIEdict, t_dictionary);
/* Check white point exists, and is an array of three numbers */
code = checkWhitePoint(i_ctx_p, &CIEdict);
if (code != 0)
return code;
/* Remaining parameters are optional, but we must validate
* them if they are present
*/
code = dict_find_string(&CIEdict, "RangeABC", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
if (!r_is_array(tempref))
return_error(gs_error_typecheck);
if (r_size(tempref) != 6)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, tempref, 6, value);
if (code < 0)
return code;
if (value[1] < value[0] || value[3] < value[2] || value[5] < value[4])
return_error(gs_error_rangecheck);
}
code = dict_find_string(&CIEdict, "DecodeABC", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
if (!r_is_array(tempref))
return_error(gs_error_typecheck);
if (r_size(tempref) != 3)
return_error(gs_error_rangecheck);
for (i=0;i<3;i++) {
code = array_get(imemory, tempref, i, &valref);
if (code < 0)
return code;
check_proc(valref);
}
}
code = dict_find_string(&CIEdict, "MatrixABC", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
if (!r_is_array(tempref))
return_error(gs_error_typecheck);
if (r_size(tempref) != 9)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, tempref, 9, value);
if (code < 0)
return code;
}
code = checkRangeLMN(i_ctx_p, &CIEdict);
if (code != 0)
return code;
code = checkDecodeLMN(i_ctx_p, &CIEdict);
if (code != 0)
return code;
code = checkMatrixLMN(i_ctx_p, &CIEdict);
if (code != 0)
return code;
code = checkBlackPoint(i_ctx_p, &CIEdict);
if (code != 0)
return code;
*r = 0;
return 0;
}
|
CWE-704
| 3,160 | 13,247 |
34943893895604839580418489661297748120
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validatecieaspace(i_ctx_t * i_ctx_p, ref **r)
{
int code;
float value[9];
ref CIEdict, *CIEspace = *r, *tempref;
if (!r_is_array(CIEspace))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(CIEspace) != 2)
return_error(gs_error_rangecheck);
code = array_get(imemory, CIEspace, 1, &CIEdict);
if (code < 0)
return code;
check_read_type(CIEdict, t_dictionary);
/* Check white point exists, and is an array of three numbers */
code = checkWhitePoint(i_ctx_p, &CIEdict);
if (code != 0)
return code;
/* Remaining parameters are optional, but we must validate
* them if they are present
*/
code = dict_find_string(&CIEdict, "RangeA", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
/* Array of two numbers A0 < A1 */
if (!r_is_array(tempref))
return_error(gs_error_typecheck);
if (r_size(tempref) != 2)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, tempref, 2, value);
if (code < 0)
return code;
if (value[1] < value[0])
return_error(gs_error_rangecheck);
}
code = dict_find_string(&CIEdict, "DecodeA", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
check_proc(*tempref);
}
code = dict_find_string(&CIEdict, "MatrixA", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
if (!r_is_array(tempref))
return_error(gs_error_typecheck);
if (r_size(tempref) != 3)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, tempref, 3, value);
if (code < 0)
return code;
}
code = checkRangeLMN(i_ctx_p, &CIEdict);
if (code != 0)
return code;
code = checkDecodeLMN(i_ctx_p, &CIEdict);
if (code != 0)
return code;
code = checkMatrixLMN(i_ctx_p, &CIEdict);
if (code != 0)
return code;
code = checkBlackPoint(i_ctx_p, &CIEdict);
if (code != 0)
return code;
*r = 0;
return 0;
}
|
CWE-704
| 3,161 | 13,248 |
39587262493656335919289301235871922164
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validateciedefgspace(i_ctx_t * i_ctx_p, ref **r)
{
int code = 0, i, j;
float value[8];
ref CIEdict, *CIEspace = *r, tempref, arrayref, valref, *pref = &tempref;
if (!r_is_array(CIEspace))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(CIEspace) != 2)
return_error(gs_error_rangecheck);
code = array_get(imemory, CIEspace, 1, &CIEdict);
if (code < 0)
return code;
check_read_type(CIEdict, t_dictionary);
code = validatecieabcspace(i_ctx_p, r);
if (code != 0)
return code;
code = dict_find_string(&CIEdict, "Table", &pref);
if (code > 0) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 5)
return_error(gs_error_rangecheck);
for (i=0;i<4;i++) {
code = array_get(imemory, pref, i, &valref);
if (code < 0)
return code;
if (r_has_type(&valref, t_integer))
value[i] = (float)valref.value.intval;
else
return_error(gs_error_typecheck);
}
if (value[0] <= 1 || value[1] <= 1 || value[2] <= 1 || value[3] <= 1)
return_error(gs_error_rangecheck);
code = array_get(imemory, pref, 4, &arrayref);
if (code < 0)
return code;
if (!r_is_array(&arrayref))
return_error(gs_error_typecheck);
if (r_size(&arrayref) != value[0])
return_error(gs_error_rangecheck);
for (i=0;i<value[0];i++) {
code = array_get(imemory, &arrayref, i, &tempref);
if (code < 0)
return code;
for (j=0;j<value[1];j++) {
code = array_get(imemory, &tempref, i, &valref);
if (code < 0)
return code;
if (!r_has_type(&valref, t_string))
return_error(gs_error_typecheck);
if (r_size(&valref) != (3 * value[2] * value[3]))
return_error(gs_error_rangecheck);
}
}
} else {
return_error(gs_error_rangecheck);
}
/* Remaining parameters are optional, but we must validate
* them if they are present
*/
code = dict_find_string(&CIEdict, "RangeDEFG", &pref);
if (code > 0 && !r_has_type(pref, t_null)) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 8)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, pref, 8, value);
if (code < 0)
return code;
if (value[1] < value[0] || value[3] < value[2] || value[5] < value[4] || value[7] < value[6])
return_error(gs_error_rangecheck);
}
code = dict_find_string(&CIEdict, "DecodeDEFG", &pref);
if (code > 0 && !r_has_type(pref, t_null)) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 4)
return_error(gs_error_rangecheck);
for (i=0;i<4;i++) {
code = array_get(imemory, pref, i, &valref);
if (code < 0)
return code;
check_proc(valref);
}
}
code = dict_find_string(&CIEdict, "RangeHIJK", &pref);
if (code > 0 && !r_has_type(pref, t_null)) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 8)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, pref, 8, value);
if (code < 0)
return code;
if (value[1] < value[0] || value[3] < value[2] || value[5] < value[4] || value[7] < value[6])
return_error(gs_error_rangecheck);
}
*r = 0;
return 0;
}
|
CWE-704
| 3,162 | 13,249 |
69549453545169050889041215260787775158
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validateciedefspace(i_ctx_t * i_ctx_p, ref **r)
{
int code = 0, i;
float value[6];
ref CIEdict, *pref, *CIEspace = *r, tempref, valref;
if (!r_is_array(CIEspace))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(CIEspace) != 2)
return_error(gs_error_rangecheck);
code = array_get(imemory, CIEspace, 1, &CIEdict);
if (code < 0)
return code;
check_read_type(CIEdict, t_dictionary);
code = validatecieabcspace(i_ctx_p, r);
if (code != 0)
return code;
pref = &tempref;
code = dict_find_string(&CIEdict, "Table", &pref);
if (code > 0) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 4)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, pref, 3, value);
if (code < 0)
return code;
if (value[0] <= 1 || value[1] <= 1 || value[2] <= 1)
return_error(gs_error_rangecheck);
code = array_get(imemory, pref, 3, &valref);
if (code < 0)
return code;
if (!r_is_array(&valref))
return_error(gs_error_typecheck);
if (r_size(&valref) != value[0])
return_error(gs_error_rangecheck);
for (i=0;i<value[0];i++) {
code = array_get(imemory, &valref, i, &tempref);
if (code < 0)
return code;
if (!r_has_type(&tempref, t_string))
return_error(gs_error_typecheck);
if (r_size(&tempref) != (3 * value[1] * value[2]))
return_error(gs_error_rangecheck);
}
} else {
return_error(gs_error_rangecheck);
}
/* Remaining parameters are optional, but we must validate
* them if they are present
*/
code = dict_find_string(&CIEdict, "RangeDEF", &pref);
if (code > 0 && !r_has_type(&tempref, t_null)) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 6)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, pref, 6, value);
if (code < 0)
return code;
if (value[1] < value[0] || value[3] < value[2] || value[5] < value[4])
return_error(gs_error_rangecheck);
}
code = dict_find_string(&CIEdict, "DecodeDEF", &pref);
if (code > 0 && !r_has_type(pref, t_null)) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 3)
return_error(gs_error_rangecheck);
for (i=0;i<3;i++) {
code = array_get(imemory, pref, i, &valref);
if (code < 0)
return code;
check_proc(valref);
}
}
code = dict_find_string(&CIEdict, "RangeHIJ", &pref);
if (code > 0 && !r_has_type(pref, t_null)) {
if (!r_is_array(pref))
return_error(gs_error_typecheck);
if (r_size(pref) != 6)
return_error(gs_error_rangecheck);
code = get_cie_param_array(imemory, pref, 6, value);
if (code < 0)
return code;
if (value[1] < value[0] || value[3] < value[2] || value[5] < value[4])
return_error(gs_error_rangecheck);
}
*r = 0;
return 0;
}
|
CWE-704
| 3,163 | 13,250 |
31797642257505411104671196206287400129
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validatedevicenspace(i_ctx_t * i_ctx_p, ref **space)
{
int i, code = 0;
ref *devicenspace = *space, proc;
ref nameref, sref, altspace, namesarray, sname;
/* Check enough arguments in the space */
if (r_size(devicenspace) < 4)
return_error(gs_error_rangecheck);
/* Check the names parameter is an array */
code = array_get(imemory, devicenspace, 1, &namesarray);
if (code < 0)
return code;
if (!r_is_array(&namesarray))
return_error(gs_error_typecheck);
/* Ensure we have at least one ink */
if (r_size(&namesarray) < 1)
return_error(gs_error_typecheck);
/* Make sure no more inks than we can cope with */
if (r_size(&namesarray) > MAX_COMPONENTS_IN_DEVN) /* MUST match psi/icremap.h int_remap_color_info_s */
return_error(gs_error_limitcheck);
/* Check the tint transform is a procedure */
code = array_get(imemory, devicenspace, 3, &proc);
if (code < 0)
return code;
check_proc(proc);
/* Check the array of ink names only contains names or strings */
for (i = 0; i < r_size(&namesarray); ++i) {
array_get(imemory, &namesarray, (long)i, &sname);
switch (r_type(&sname)) {
case t_string:
case t_name:
break;
default:
return_error(gs_error_typecheck);
}
}
/* Get the name of the alternate space */
code = array_get(imemory, devicenspace, 2, &altspace);
if (code < 0)
return code;
if (r_has_type(&altspace, t_name))
ref_assign(&nameref, &altspace);
else {
/* Make sure the alternate space is an array */
if (!r_is_array(&altspace))
return_error(gs_error_typecheck);
/* And has a name for its type */
code = array_get(imemory, &altspace, 0, &nameref);
if (code < 0)
return code;
if (!r_has_type(&nameref, t_name))
return_error(gs_error_typecheck);
}
/* Convert alternate space name to string */
name_string_ref(imemory, &nameref, &sref);
/* Check its not /Indexed, /Pattern, /DeviceN */
if (r_size(&sref) == 7) {
if (strncmp((const char *)sref.value.const_bytes, "Indexed", 7) == 0)
return_error(gs_error_typecheck);
if (strncmp((const char *)sref.value.const_bytes, "Pattern", 7) == 0)
return_error(gs_error_typecheck);
if (strncmp((const char *)sref.value.const_bytes, "DeviceN", 7) == 0)
return_error(gs_error_typecheck);
}
/* and also not /Separation */
if (r_size(&sref) == 9 && strncmp((const char *)sref.value.const_bytes, "Separation", 9) == 0)
return_error(gs_error_typecheck);
ref_assign(*space, &altspace);
return 0;
}
|
CWE-704
| 3,164 | 13,251 |
55812159981520191086034386751585473637
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validatedevicepspace(i_ctx_t * i_ctx_p, ref **space)
{
int code = 0;
ref *r = *space, bpp;
if (!r_is_array(r))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(r) != 2)
return_error(gs_error_rangecheck);
/* Make sure 'bits per pixel' is an integer */
code = array_get(imemory, r, 1, &bpp);
if (code < 0)
return code;
if (!r_has_type(&bpp, t_integer))
return_error(gs_error_typecheck);
/* Make sure 'bits per pixel' lies between 0 and 31 */
if (bpp.value.intval < 0 || bpp.value.intval > 31)
return_error(gs_error_rangecheck);
*space = 0;
return code;
}
|
CWE-704
| 3,165 | 13,252 |
336311273571582200198680828973508254791
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validateiccspace(i_ctx_t * i_ctx_p, ref **r)
{
int code=0, i, components = 0;
ref *space, *tempref, valref, ICCdict, sref;
space = *r;
if (!r_is_array(space))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(space) != 2)
return_error(gs_error_rangecheck);
code = array_get(imemory, space, 1, &ICCdict);
if (code < 0)
return code;
check_type(ICCdict, t_dictionary);
code = dict_find_string(&ICCdict, "N", &tempref);
if (code < 0)
return code;
if (code == 0)
return gs_note_error(gs_error_undefined);
if (!r_has_type(tempref, t_null)) {
if (!r_has_type(tempref, t_integer))
return_error(gs_error_typecheck);
components = tempref->value.intval;
} else
return_error(gs_error_typecheck);
code = dict_find_string(&ICCdict, "DataSource", &tempref);
if (code <= 0)
return_error(gs_error_typecheck);
if (!r_has_type(tempref, t_null)) {
if (!r_has_type(tempref, t_string) && !r_has_type(tempref, t_file))
return_error(gs_error_typecheck);
} else
return_error(gs_error_typecheck);
/* Following are optional entries */
code = dict_find_string(&ICCdict, "Range", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
if (!r_is_array(tempref))
return_error(gs_error_typecheck);
if (r_size(tempref) < (components * 2))
return_error(gs_error_rangecheck);
for (i=0;i<components * 2;i++) {
code = array_get(imemory, tempref, i, &valref);
if (code < 0)
return code;
if (!r_has_type(&valref, t_integer) && !r_has_type(&valref, t_real))
return_error(gs_error_typecheck);
}
}
code = dict_find_string(&ICCdict, "Alternate", &tempref);
if (code > 0 && !r_has_type(tempref, t_null)) {
ref_assign(*r, tempref);
if (r_has_type(tempref, t_name)) {
name_string_ref(imemory, tempref, &sref);
if (sref.value.bytes && strncmp((const char *)sref.value.bytes, "Pattern", 7) == 0)
return_error(gs_error_typecheck);
} else {
if (r_is_array(tempref)) {
code = array_get(imemory, tempref, 0, &valref);
if (code < 0)
return code;
if (!r_has_type(&valref, t_name) && !r_has_type(&valref, t_string))
return_error(gs_error_typecheck);
if (r_has_type(&valref, t_name))
name_string_ref(imemory, &valref, &sref);
else
sref.value.bytes = valref.value.bytes;
if (sref.value.bytes && strncmp((const char *)sref.value.bytes, "Pattern", 7) == 0)
return_error(gs_error_typecheck);
} else
return_error(gs_error_typecheck);
}
} else {
ref nameref;
switch (components) {
case 1:
code = name_enter_string(imemory, "DeviceGray", &nameref);
break;
case 3:
code = name_enter_string(imemory, "DeviceRGB", &nameref);
break;
case 4:
code = name_enter_string(imemory, "DeviceCMYK", &nameref);
break;
default:
return_error(gs_error_rangecheck);
}
if (code < 0)
return code;
/* In case this space is the /ALternate for a previous ICCBased space
* insert the named space into the ICC dictionary. If we simply returned
* the named space, as before, then we are replacing the second ICCBased
* space in the first ICCBased space with the named space!
*/
code = idict_put_string(&ICCdict, "Alternate", &nameref);
if (code < 0)
return code;
/* And now revalidate with the newly updated dictionary */
return validateiccspace(i_ctx_p, r);
}
return code;
}
|
CWE-704
| 3,166 | 13,253 |
294017925161212467027271589600841846487
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validateindexedspace(i_ctx_t * i_ctx_p, ref **space)
{
int code = 0;
ref *r = *space;
ref nameref, sref, hival, lookup, altspace;
if (!r_is_array(r))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(r) != 4)
return_error(gs_error_rangecheck);
/* Check operand type(s) */
/* Make sure 'hival' is an integer */
code = array_get(imemory, r, 2, &hival);
if (code < 0)
return code;
if (!r_has_type(&hival, t_integer))
return_error(gs_error_typecheck);
/* Make sure 'hival' lies between 0 and 4096 */
if (hival.value.intval < 0 || hival.value.intval > 4096)
return_error(gs_error_rangecheck);
/* Ensure the 'lookup' is either a string or a procedure */
code = array_get(imemory, r, 3, &lookup);
if (code < 0)
return code;
if (!r_has_type(&lookup, t_string))
check_proc(lookup);
/* Get the name of the alternate space */
code = array_get(imemory, r, 1, &altspace);
if (code < 0)
return code;
if (r_has_type(&altspace, t_name))
ref_assign(&nameref, &altspace);
else {
if (!r_is_array(&altspace))
return_error(gs_error_typecheck);
code = array_get(imemory, &altspace, 0, &nameref);
if (code < 0)
return code;
}
/* Convert alternate space name to string */
name_string_ref(imemory, &nameref, &sref);
/* Check its not /Indexed or /Pattern */
if (r_size(&sref) == 7) {
if (strncmp((const char *)sref.value.const_bytes, "Indexed", 7) == 0)
return_error(gs_error_typecheck);
if (strncmp((const char *)sref.value.const_bytes, "Pattern", 7) == 0)
return_error(gs_error_typecheck);
}
ref_assign(*space, &altspace);
return 0;
}
|
CWE-704
| 3,167 | 13,254 |
288734162667476855656668893950038351784
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validatelabspace(i_ctx_t * i_ctx_p, ref **r)
{
int code=0;
ref *space, labdict;
space = *r;
if (!r_is_array(space))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(space) < 2)
return_error(gs_error_rangecheck);
code = array_get(imemory, space, 1, &labdict);
if (code < 0)
return code;
check_type(labdict, t_dictionary);
/* Check the white point, which is required. */
code = checkWhitePoint(i_ctx_p, &labdict);
if (code != 0)
return code;
/* The rest are optional. Need to validate though */
code = checkBlackPoint(i_ctx_p, &labdict);
if (code < 0)
return code;
/* Range on a b values */
code = checkrangeab(i_ctx_p, &labdict);
if (code < 0)
return code;
*r = 0; /* No nested space */
return 0;
}
|
CWE-704
| 3,168 | 13,255 |
46320979364447968893910986878224198313
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validatepatternspace(i_ctx_t * i_ctx_p, ref **r)
{
int code;
ref tref;
/* since makepattern has already been run, we don't need to do much validation */
if (!r_has_type(*r, t_name)) {
if (r_is_array(*r)) {
if (r_size(*r) > 1) {
code = array_get(imemory, *r, 1, &tref);
if (code < 0)
return code;
ref_assign(*r, &tref);
} else
*r = 0;
} else
return_error(gs_error_typecheck);
} else
*r = 0;
return 0;
}
|
CWE-704
| 3,169 | 13,256 |
83406521575146078857898136561348749668
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
static int validateseparationspace(i_ctx_t * i_ctx_p, ref **space)
{
int code = 0;
ref *sepspace = *space;
ref nameref, sref, sname, altspace, tref;
if (!r_is_array(sepspace))
return_error(gs_error_typecheck);
/* Validate parameters, check we have enough operands */
if (r_size(sepspace) != 4)
return_error(gs_error_rangecheck);
/* Check separation name is a string or name object */
code = array_get(imemory, sepspace, 1, &sname);
if (code < 0)
return code;
if (!r_has_type(&sname, t_name)) {
if (!r_has_type(&sname, t_string))
return_error(gs_error_typecheck);
else {
code = name_from_string(imemory, &sname, &sname);
if (code < 0)
return code;
}
}
/* Check the tint transform is a procedure */
code = array_get(imemory, sepspace, 3, &tref);
if (code < 0)
return code;
check_proc(tref);
/* Get the name of the alternate space */
code = array_get(imemory, sepspace, 2, &altspace);
if (code < 0)
return code;
if (r_has_type(&altspace, t_name))
ref_assign(&nameref, &altspace);
else {
/* Make sure the alternate space is an array */
if (!r_is_array(&altspace))
return_error(gs_error_typecheck);
/* And has a name for its type */
code = array_get(imemory, &altspace, 0, &tref);
if (code < 0)
return code;
if (!r_has_type(&tref, t_name))
return_error(gs_error_typecheck);
ref_assign(&nameref, &tref);
}
/* Convert alternate space name to string */
name_string_ref(imemory, &nameref, &sref);
/* Check its not /Indexed or /Pattern or /DeviceN */
if (r_size(&sref) == 7) {
if (strncmp((const char *)sref.value.const_bytes, "Indexed", 7) == 0)
return_error(gs_error_typecheck);
if (strncmp((const char *)sref.value.const_bytes, "Pattern", 7) == 0)
return_error(gs_error_typecheck);
if (strncmp((const char *)sref.value.const_bytes, "DeviceN", 7) == 0)
return_error(gs_error_typecheck);
}
/* and also not /Separation */
if (r_size(&sref) == 9 && strncmp((const char *)sref.value.const_bytes, "Separation", 9) == 0)
return_error(gs_error_typecheck);
ref_assign(*space, &altspace);
return 0;
}
|
CWE-704
| 3,170 | 13,257 |
13840422847007603313464352902077213074
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zcolor_remap_color(i_ctx_t *i_ctx_p)
{
/* Remap both colors. This should never hurt. */
gs_swapcolors(igs);
gx_unset_dev_color(igs);
gs_swapcolors(igs);
gx_unset_dev_color(igs);
return 0;
}
|
CWE-704
| 3,171 | 13,258 |
93853109019717044386977666319222968823
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zcolor_remap_one_finish(i_ctx_t *i_ctx_p)
{
return zcolor_remap_one_store(i_ctx_p, 0.0);
}
|
CWE-704
| 3,173 | 13,259 |
93679487300323879327698036987911670894
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zcolor_remap_one_signed_finish(i_ctx_t *i_ctx_p)
{
return zcolor_remap_one_store(i_ctx_p, -1.0);
}
|
CWE-704
| 3,174 | 13,260 |
82011362238937344839296246380724711152
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zcolor_remap_one_store(i_ctx_t *i_ctx_p, double min_value)
{
int i;
gx_transfer_map *pmap = r_ptr(esp, gx_transfer_map);
if (ref_stack_count(&o_stack) < transfer_map_size)
return_error(gs_error_stackunderflow);
for (i = 0; i < transfer_map_size; i++) {
double v;
int code =
real_param(ref_stack_index(&o_stack, transfer_map_size - 1 - i),
&v);
if (code < 0)
return code;
pmap->values[i] =
(v < min_value ? float2frac(min_value) :
v >= 1.0 ? frac_1 :
float2frac(v));
}
ref_stack_pop(&o_stack, transfer_map_size);
esp--; /* pop pointer to transfer map */
return o_pop_estack;
}
|
CWE-704
| 3,175 | 13,261 |
8529577523878192386327562081058973667
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zcolor_reset_transfer(i_ctx_t *i_ctx_p)
{
gx_set_effective_transfer(igs);
return zcolor_remap_color(i_ctx_p);
}
|
CWE-704
| 3,176 | 13,262 |
339820021661780552075299366447040696718
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zcurrentcmykcolor(i_ctx_t * i_ctx_p)
{
int code;
code = zcurrentcolor(i_ctx_p);
if (code < 0)
return code;
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(7);
push_mark_estack(es_other, colour_cleanup);
esp++;
/* variable to hold stack depth for tint transform */
make_int(&esp[0], 0);
esp++;
/* Store the 'base' type color wanted, in this case CMYK */
make_int(&esp[0], 3);
make_int(&esp[1], 1);
/* Store the 'stage' of processing (initially 0) */
make_int(&esp[2], 0);
/* Store a pointer to the color space stored on the operand stack
* as the stack may grow unpredictably making further access
* to the space difficult
*/
esp[3] = istate->colorspace[0].array;
esp += 3; /* The push_op_estack macro increments esp before using it */
/* Finally, the actual continuation routine */
push_op_estack(currentbasecolor_cont);
return o_push_estack;
}
|
CWE-704
| 3,177 | 13,263 |
220285344120604717278542955575527667477
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zcurrentrgbcolor(i_ctx_t * i_ctx_p)
{
int code;
code = zcurrentcolor(i_ctx_p);
if (code < 0)
return code;
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(7);
push_mark_estack(es_other, colour_cleanup);
esp++;
/* variable to hold stack depth for tint transform */
make_int(&esp[0], 0);
esp++;
/* Store the 'base' type color wanted, in this case RGB */
make_int(&esp[0], 2);
make_int(&esp[1], 1);
/* Store the 'stage' of processing (initially 0) */
make_int(&esp[2], 0);
/* Store a pointer to the color space stored on the operand stack
* as the stack may grow unpredictably making further access
* to the space difficult
*/
esp[3] = istate->colorspace[0].array;
esp += 3; /* The push_op_estack macro increments esp before using it */
/* Finally, the actual continuation routine */
push_op_estack(currentbasecolor_cont);
return o_push_estack;
}
|
CWE-704
| 3,179 | 13,264 |
40154676620433342292836097787655339676
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zincludecolorspace(i_ctx_t * i_ctx_p)
{
os_ptr op = osp;
ref nsref;
int code;
check_type(*op, t_name);
name_string_ref(imemory, op, &nsref);
code = gs_includecolorspace(igs, nsref.value.const_bytes, r_size(&nsref));
if (!code)
pop(1);
return code;
}
|
CWE-704
| 3,181 | 13,265 |
98234919261431554013462244623313252946
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zprocesscolors(i_ctx_t * i_ctx_p)
{
os_ptr op = osp;
push(1);
make_int(op, gs_currentdevice(igs)->color_info.num_components);
return 0;
}
|
CWE-704
| 3,182 | 13,266 |
333381149696498165004122388352349266694
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetcmykcolor(i_ctx_t * i_ctx_p)
{
os_ptr op = osp; /* required by "push" macro */
int code, i;
float values[4];
/* Gather numeric operand value(s) (also checks type) */
code = float_params(op, 4, (float *)&values);
if (code < 0)
return code;
/* Clamp numeric operand range(s) */
for (i = 0;i < 4; i++) {
if (values[i] < 0)
values[i] = 0;
else if (values[i] > 1)
values[i] = 1;
}
code = make_floats(&op[-3], (const float *)&values, 4);
if (code < 0)
return code;
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(5);
push_mark_estack(es_other, colour_cleanup);
esp++;
/* variable to hold base type (2 = CMYK) */
make_int(esp, 2);
esp++;
/* Store the 'stage' of processing (initially 0) */
make_int(esp, 0);
/* Finally, the actual continuation routine */
push_op_estack(setdevicecolor_cont);
return o_push_estack;
}
|
CWE-704
| 3,183 | 13,267 |
50567363780952454322025458051633330727
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetcolorspace(i_ctx_t * i_ctx_p)
{
os_ptr op = osp;
es_ptr ep;
int code, depth;
bool is_CIE;
/* Make sure we have an operand... */
check_op(1);
/* Check its either a name (base space) or an array */
if (!r_has_type(op, t_name))
if (!r_is_array(op))
return_error(gs_error_typecheck);
code = validate_spaces(i_ctx_p, op, &depth);
if (code < 0)
return code;
is_CIE = istate->use_cie_color.value.boolval;
/* See if its the same as the current space */
if (is_same_colorspace(i_ctx_p, op, &istate->colorspace[0].array, is_CIE)) {
PS_colour_space_t *cspace;
/* Even if its the same space, we still need to set the correct
* initial color value.
*/
code = get_space_object(i_ctx_p, &istate->colorspace[0].array, &cspace);
if (code < 0)
return 0;
if (cspace->initialcolorproc) {
cspace->initialcolorproc(i_ctx_p, &istate->colorspace[0].array);
}
/* Pop the space off the stack */
pop(1);
return 0;
}
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(5);
/* Store the initial value of CIE substitution (not substituting) */
ep = esp += 1;
make_int(ep, 0);
/* Store the 'depth' of the space returned during checking above */
ep = esp += 1;
make_int(ep, depth);
/* Store the 'stage' of processing (initially 0) */
ep = esp += 1;
make_int(ep, 0);
/* Store a pointer to the color space stored on the operand stack
* as the stack may grow unpredictably making further access
* to the space difficult
*/
ep = esp += 1;
*ep = *op;
/* Finally, the actual continuation routine */
push_op_estack(setcolorspace_cont);
return o_push_estack;
}
|
CWE-704
| 3,184 | 13,268 |
195941685089870287703767643416808020898
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetfillcolor(i_ctx_t * i_ctx_p)
{
return zsetcolor(i_ctx_p);
}
|
CWE-704
| 3,185 | 13,269 |
277830584500988981604269191095070286361
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetfillcolorspace(i_ctx_t * i_ctx_p)
{
return zsetcolorspace(i_ctx_p);
}
|
CWE-704
| 3,186 | 13,270 |
37519148671284703320373065931416411429
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetgray(i_ctx_t * i_ctx_p)
{
os_ptr op = osp; /* required by "push" macro */
float value;
int code;
/* Gather numeric operand value(s) */
code = float_params(op, 1, &value);
if (code < 0)
return code;
/* Clamp numeric operand range(s) */
if (value < 0)
value = 0;
else if (value > 1)
value = 1;
code = make_floats(op, &value, 1);
if (code < 0)
return code;
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(5);
push_mark_estack(es_other, colour_cleanup);
esp++;
/* variable to hold base type (0 = gray) */
make_int(esp, 0);
esp++;
/* Store the 'stage' of processing (initially 0) */
make_int(esp, 0);
/* Finally, the actual continuation routine */
push_op_estack(setdevicecolor_cont);
return o_push_estack;
}
|
CWE-704
| 3,187 | 13,271 |
6398775369448887494700356472334959710
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsethsbcolor(i_ctx_t * i_ctx_p)
{
os_ptr op = osp; /* required by "push" macro */
int code, i;
float values[3];
/* Gather numeric operand value(s) (also checks type) */
code = float_params(op, 3, (float *)&values);
if (code < 0)
return code;
/* Clamp numeric operand range(s) */
for (i = 0;i < 3; i++) {
if (values[i] < 0)
values[i] = 0;
else if (values[i] > 1)
values[i] = 1;
}
hsb2rgb((float *)&values);
code = make_floats(&op[-2], (const float *)&values, 3);
if (code < 0)
return code;
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(5);
push_mark_estack(es_other, colour_cleanup);
esp++;
/* variable to hold base type (1 = RGB) */
make_int(esp, 1);
esp++;
/* Store the 'stage' of processing (initially 0) */
make_int(esp, 0);
/* Finally, the actual continuation routine */
push_op_estack(setdevicecolor_cont);
return o_push_estack;
}
|
CWE-704
| 3,188 | 13,272 |
114829634304202327998178110587685679773
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetrgbcolor(i_ctx_t * i_ctx_p)
{
os_ptr op = osp; /* required by "push" macro */
int code, i;
float values[3];
/* Gather numeric operand value(s) (also checks type) */
code = float_params(op, 3, (float *)&values);
if (code < 0)
return code;
/* Clamp numeric operand range(s) */
for (i = 0;i < 3; i++) {
if (values[i] < 0)
values[i] = 0;
else if (values[i] > 1)
values[i] = 1;
}
code = make_floats(&op[-2], (const float *)&values, 3);
if (code < 0)
return code;
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(5);
push_mark_estack(es_other, colour_cleanup);
esp++;
/* variable to hold base type (1 = RGB) */
make_int(esp, 1);
esp++;
/* Store the 'stage' of processing (initially 0) */
make_int(esp, 0);
/* Finally, the actual continuation routine */
push_op_estack(setdevicecolor_cont);
return o_push_estack;
}
|
CWE-704
| 3,189 | 13,273 |
314974742352196388192375201877969631166
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetstrokecolor(i_ctx_t * i_ctx_p)
{
int code;
code = zswapcolors(i_ctx_p);
if (code < 0)
return code;
/* Set up for the continuation procedure which will finish by restoring the fill colour space */
/* Make sure the exec stack has enough space */
check_estack(1);
/* Now, the actual continuation routine */
push_op_estack(setstrokecolor_cont);
code = zsetcolor(i_ctx_p);
if (code >= 0)
return o_push_estack;
return code;
}
|
CWE-704
| 3,190 | 13,274 |
36749744249402571322252382416377717222
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsetstrokecolorspace(i_ctx_t * i_ctx_p)
{
int code;
code = zswapcolors(i_ctx_p);
if (code < 0)
return code;
/* Set up for the continuation procedure which will finish by restoring the fill colour space */
/* Make sure the exec stack has enough space */
check_estack(1);
/* Now, the actual continuation routine */
push_op_estack(setstrokecolorspace_cont);
code = zsetcolorspace(i_ctx_p);
if (code >= 0)
return o_push_estack;
return code;
}
|
CWE-704
| 3,191 | 13,275 |
247728083845484594002474321221305590332
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zsettransfer(i_ctx_t * i_ctx_p)
{
os_ptr op = osp;
int code;
check_proc(*op);
check_ostack(zcolor_remap_one_ostack - 1);
check_estack(1 + zcolor_remap_one_estack);
istate->transfer_procs.red =
istate->transfer_procs.green =
istate->transfer_procs.blue =
istate->transfer_procs.gray = *op;
if ((code = gs_settransfer_remap(igs, gs_mapped_transfer, false)) < 0)
return code;
push_op_estack(zcolor_reset_transfer);
pop(1);
return zcolor_remap_one( i_ctx_p,
&istate->transfer_procs.gray,
igs->set_transfer.gray,
igs,
zcolor_remap_one_finish );
}
|
CWE-704
| 3,192 | 13,276 |
182865095919560649235016471079281661493
| null | null | null |
ghostscript
|
b326a71659b7837d3acde954b18bda1a6f5e9498
| 0 |
zswapcolors(i_ctx_t * i_ctx_p)
{
ref_colorspace tmp_cs;
ref tmp_pat;
tmp_cs = istate->colorspace[0];
istate->colorspace[0] = istate->colorspace[1];
istate->colorspace[1] = tmp_cs;
tmp_pat = istate->pattern[0];
istate->pattern[0] = istate->pattern[1];
istate->pattern[1] = tmp_pat;
return gs_swapcolors(igs);
}
|
CWE-704
| 3,193 | 13,277 |
297384633050994187726434532745042365661
| null | null | null |
ghostscript
|
ea735ba37dc0fd5f5622d031830b9a559dec1cc9
| 0 |
zsetcolor(i_ctx_t * i_ctx_p)
{
os_ptr op = osp;
es_ptr ep;
const gs_color_space * pcs = gs_currentcolorspace(igs);
gs_client_color cc;
int n_comps, n_numeric_comps, num_offset = 0, code, depth;
PS_colour_space_t *space;
/* initialize the client color pattern pointer for GC */
cc.pattern = 0;
/* check for a pattern color space */
if ((n_comps = cs_num_components(pcs)) < 0) {
n_comps = -n_comps;
if (r_has_type(op, t_dictionary)) {
ref *pImpl, pPatInst;
if ((code = dict_find_string(op, "Implementation", &pImpl)) < 0)
return code;
if (code > 0) {
code = array_get(imemory, pImpl, 0, &pPatInst);
if (code < 0)
return code;
cc.pattern = r_ptr(&pPatInst, gs_pattern_instance_t);
n_numeric_comps = ( pattern_instance_uses_base_space(cc.pattern)
? n_comps - 1
: 0 );
} else
n_numeric_comps = 0;
} else
n_numeric_comps = 0;
num_offset = 1;
} else
n_numeric_comps = n_comps;
/* gather the numeric operands */
code = float_params(op - num_offset, n_numeric_comps, cc.paint.values);
if (code < 0)
return code;
/* The values are copied to graphic state and compared with */
/* other colors by memcmp() in gx_hld_saved_color_equal() */
/* This is the easiest way to avoid indeterminism */
memset(cc.paint.values + n_numeric_comps, 0,
sizeof(cc.paint.values) - sizeof(*cc.paint.values)*n_numeric_comps);
code = get_space_object(i_ctx_p, &istate->colorspace[0].array, &space);
if (code < 0)
return code;
if (space->validatecomponents) {
code = space->validatecomponents(i_ctx_p,
&istate->colorspace[0].array,
cc.paint.values, n_numeric_comps);
if (code < 0)
return code;
}
/* pass the color to the graphic library */
if ((code = gs_setcolor(igs, &cc)) >= 0) {
if (n_comps > n_numeric_comps) {
istate->pattern[0] = *op; /* save pattern dict or null */
}
}
/* Check the color spaces, to see if we need to run any tint transform
* procedures. Some Adobe applications *eg Photoshop) expect that the
* tint transform will be run and use this to set up duotone DeviceN
* spaces.
*/
code = validate_spaces(i_ctx_p, &istate->colorspace[0].array, &depth);
if (code < 0)
return code;
/* Set up for the continuation procedure which will do the work */
/* Make sure the exec stack has enough space */
check_estack(5);
/* A place holder for data potentially used by transform functions */
ep = esp += 1;
make_int(ep, 0);
/* Store the 'depth' of the space returned during checking above */
ep = esp += 1;
make_int(ep, 0);
/* Store the 'stage' of processing (initially 0) */
ep = esp += 1;
make_int(ep, 0);
/* Store a pointer to the color space stored on the operand stack
* as the stack may grow unpredictably making further access
* to the space difficult
*/
ep = esp += 1;
*ep = istate->colorspace[0].array;
/* Finally, the actual continuation routine */
push_op_estack(setcolor_cont);
return o_push_estack;
}
|
CWE-119
| 3,210 | 13,292 |
151317392453793853396074999525384076924
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
calc_rate (wgint bytes, double secs, int *units)
{
double dlrate;
double bibyte = 1000.0;
if (!opt.report_bps)
bibyte = 1024.0;
assert (secs >= 0);
assert (bytes >= 0);
if (secs == 0)
/* If elapsed time is exactly zero, it means we're under the
resolution of the timer. This can easily happen on systems
that use time() for the timer. Since the interval lies between
0 and the timer's resolution, assume half the resolution. */
secs = ptimer_resolution () / 2.0;
dlrate = convert_to_bits (bytes) / secs;
if (dlrate < bibyte)
*units = 0;
else if (dlrate < (bibyte * bibyte))
*units = 1, dlrate /= bibyte;
else if (dlrate < (bibyte * bibyte * bibyte))
*units = 2, dlrate /= (bibyte * bibyte);
else
/* Maybe someone will need this, one day. */
*units = 3, dlrate /= (bibyte * bibyte * bibyte);
return dlrate;
}
|
CWE-119
| 3,211 | 13,293 |
309451795890062507912163907847372939148
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
fd_read_hunk (int fd, hunk_terminator_t terminator, long sizehint, long maxsize)
{
long bufsize = sizehint;
char *hunk = xmalloc (bufsize);
int tail = 0; /* tail position in HUNK */
assert (!maxsize || maxsize >= bufsize);
while (1)
{
const char *end;
int pklen, rdlen, remain;
/* First, peek at the available data. */
pklen = fd_peek (fd, hunk + tail, bufsize - 1 - tail, -1);
if (pklen < 0)
{
xfree (hunk);
return NULL;
}
end = terminator (hunk, hunk + tail, pklen);
if (end)
{
/* The data contains the terminator: we'll drain the data up
to the end of the terminator. */
remain = end - (hunk + tail);
assert (remain >= 0);
if (remain == 0)
{
/* No more data needs to be read. */
hunk[tail] = '\0';
return hunk;
}
if (bufsize - 1 < tail + remain)
{
bufsize = tail + remain + 1;
hunk = xrealloc (hunk, bufsize);
}
}
else
/* No terminator: simply read the data we know is (or should
be) available. */
remain = pklen;
/* Now, read the data. Note that we make no assumptions about
how much data we'll get. (Some TCP stacks are notorious for
read returning less data than the previous MSG_PEEK.) */
rdlen = fd_read (fd, hunk + tail, remain, 0);
if (rdlen < 0)
{
xfree (hunk);
return NULL;
}
tail += rdlen;
hunk[tail] = '\0';
if (rdlen == 0)
{
if (tail == 0)
{
/* EOF without anything having been read */
xfree (hunk);
errno = 0;
return NULL;
}
else
/* EOF seen: return the data we've read. */
return hunk;
}
if (end && rdlen == remain)
/* The terminator was seen and the remaining data drained --
we got what we came for. */
return hunk;
/* Keep looping until all the data arrives. */
if (tail == bufsize - 1)
{
/* Double the buffer size, but refuse to allocate more than
MAXSIZE bytes. */
if (maxsize && bufsize >= maxsize)
{
xfree (hunk);
errno = ENOMEM;
return NULL;
}
bufsize <<= 1;
if (maxsize && bufsize > maxsize)
bufsize = maxsize;
hunk = xrealloc (hunk, bufsize);
}
}
}
|
CWE-119
| 3,212 | 13,294 |
149873434514180781355894736638846998732
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
free_urlpos (struct urlpos *l)
{
while (l)
{
struct urlpos *next = l->next;
if (l->url)
url_free (l->url);
xfree (l->local_name);
xfree (l);
l = next;
}
}
|
CWE-119
| 3,214 | 13,295 |
167385682884158390165892158174306857184
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
getproxy (struct url *u)
{
char *proxy = NULL;
char *rewritten_url;
if (!opt.use_proxy)
return NULL;
if (no_proxy_match (u->host, (const char **)opt.no_proxy))
return NULL;
switch (u->scheme)
{
case SCHEME_HTTP:
proxy = opt.http_proxy ? opt.http_proxy : getenv ("http_proxy");
break;
#ifdef HAVE_SSL
case SCHEME_HTTPS:
proxy = opt.https_proxy ? opt.https_proxy : getenv ("https_proxy");
break;
case SCHEME_FTPS:
proxy = opt.ftp_proxy ? opt.ftp_proxy : getenv ("ftps_proxy");
break;
#endif
case SCHEME_FTP:
proxy = opt.ftp_proxy ? opt.ftp_proxy : getenv ("ftp_proxy");
break;
case SCHEME_INVALID:
break;
}
if (!proxy || !*proxy)
return NULL;
/* Handle shorthands. `rewritten_storage' is a kludge to allow
getproxy() to return static storage. */
rewritten_url = rewrite_shorthand_url (proxy);
if (rewritten_url)
return rewritten_url;
return strdup(proxy);
}
|
CWE-119
| 3,215 | 13,296 |
61540123359353145307559125158671394138
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
input_file_url (const char *input_file)
{
static bool first = true;
if (input_file
&& url_has_scheme (input_file)
&& first)
{
first = false;
return true;
}
else
return false;
}
|
CWE-119
| 3,216 | 13,297 |
272920896114129424933915941296308673868
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
limit_bandwidth (wgint bytes, struct ptimer *timer)
{
double delta_t = ptimer_read (timer) - limit_data.chunk_start;
double expected;
limit_data.chunk_bytes += bytes;
/* Calculate the amount of time we expect downloading the chunk
should take. If in reality it took less time, sleep to
compensate for the difference. */
expected = (double) limit_data.chunk_bytes / opt.limit_rate;
if (expected > delta_t)
{
double slp = expected - delta_t + limit_data.sleep_adjust;
double t0, t1;
if (slp < 0.2)
{
DEBUGP (("deferring a %.2f ms sleep (%s/%.2f).\n",
slp * 1000, number_to_static_string (limit_data.chunk_bytes),
delta_t));
return;
}
DEBUGP (("\nsleeping %.2f ms for %s bytes, adjust %.2f ms\n",
slp * 1000, number_to_static_string (limit_data.chunk_bytes),
limit_data.sleep_adjust));
t0 = ptimer_read (timer);
xsleep (slp);
t1 = ptimer_measure (timer);
/* Due to scheduling, we probably slept slightly longer (or
shorter) than desired. Calculate the difference between the
desired and the actual sleep, and adjust the next sleep by
that amount. */
limit_data.sleep_adjust = slp - (t1 - t0);
/* If sleep_adjust is very large, it's likely due to suspension
and not clock inaccuracy. Don't enforce those. */
if (limit_data.sleep_adjust > 0.5)
limit_data.sleep_adjust = 0.5;
else if (limit_data.sleep_adjust < -0.5)
limit_data.sleep_adjust = -0.5;
}
limit_data.chunk_bytes = 0;
limit_data.chunk_start = ptimer_read (timer);
}
|
CWE-119
| 3,217 | 13,298 |
126250866824264850872337788935609219992
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
limit_bandwidth_reset (void)
{
xzero (limit_data);
}
|
CWE-119
| 3,218 | 13,299 |
15062904819119380985306069696730582858
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
line_terminator (const char *start _GL_UNUSED, const char *peeked, int peeklen)
{
const char *p = memchr (peeked, '\n', peeklen);
if (p)
/* p+1 because the line must include '\n' */
return p + 1;
return NULL;
}
|
CWE-119
| 3,219 | 13,300 |
128414862913392467413568039548179537961
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
no_proxy_match (const char *host, const char **no_proxy)
{
if (!no_proxy)
return false;
else
return sufmatch (no_proxy, host);
}
|
CWE-119
| 3,220 | 13,301 |
214656008469847805376322433730193746547
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
printwhat (int n1, int n2)
{
logputs (LOG_VERBOSE, (n1 == n2) ? _("Giving up.\n\n") : _("Retrying.\n\n"));
}
|
CWE-119
| 3,221 | 13,302 |
264171437916334610066219700468337129347
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
retr_rate (wgint bytes, double secs)
{
static char res[20];
static const char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" };
static const char *rate_names_bits[] = {"b/s", "Kb/s", "Mb/s", "Gb/s" };
int units;
double dlrate = calc_rate (bytes, secs, &units);
/* Use more digits for smaller numbers (regardless of unit used),
e.g. "1022", "247", "12.5", "2.38". */
snprintf (res, sizeof(res), "%.*f %s",
dlrate >= 99.95 ? 0 : dlrate >= 9.995 ? 1 : 2,
dlrate, !opt.report_bps ? rate_names[units]: rate_names_bits[units]);
return res;
}
|
CWE-119
| 3,222 | 13,303 |
303478846550105765747385518189282538999
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
retrieve_from_file (const char *file, bool html, int *count)
{
uerr_t status;
struct urlpos *url_list, *cur_url;
struct iri *iri = iri_new();
char *input_file, *url_file = NULL;
const char *url = file;
status = RETROK; /* Suppose everything is OK. */
*count = 0; /* Reset the URL count. */
/* sXXXav : Assume filename and links in the file are in the locale */
set_uri_encoding (iri, opt.locale, true);
set_content_encoding (iri, opt.locale);
if (url_valid_scheme (url))
{
int dt,url_err;
struct url *url_parsed = url_parse (url, &url_err, iri, true);
if (!url_parsed)
{
char *error = url_error (url, url_err);
logprintf (LOG_NOTQUIET, "%s: %s.\n", url, error);
xfree (error);
iri_free (iri);
return URLERROR;
}
if (!opt.base_href)
opt.base_href = xstrdup (url);
status = retrieve_url (url_parsed, url, &url_file, NULL, NULL, &dt,
false, iri, true);
url_free (url_parsed);
if (!url_file || (status != RETROK))
return status;
if (dt & TEXTHTML)
html = true;
#ifdef ENABLE_IRI
/* If we have a found a content encoding, use it.
* ( == is okay, because we're checking for identical object) */
if (iri->content_encoding != opt.locale)
set_uri_encoding (iri, iri->content_encoding, false);
#endif
/* Reset UTF-8 encode status */
iri->utf8_encode = opt.enable_iri;
xfree (iri->orig_url);
input_file = url_file;
}
else
input_file = (char *) file;
url_list = (html ? get_urls_html (input_file, NULL, NULL, iri)
: get_urls_file (input_file));
xfree (url_file);
for (cur_url = url_list; cur_url; cur_url = cur_url->next, ++*count)
{
char *filename = NULL, *new_file = NULL, *proxy;
int dt = 0;
struct iri *tmpiri = iri_dup (iri);
struct url *parsed_url = NULL;
if (cur_url->ignore_when_downloading)
continue;
if (opt.quota && total_downloaded_bytes > opt.quota)
{
status = QUOTEXC;
break;
}
parsed_url = url_parse (cur_url->url->url, NULL, tmpiri, true);
proxy = getproxy (cur_url->url);
if ((opt.recursive || opt.page_requisites)
&& ((cur_url->url->scheme != SCHEME_FTP
#ifdef HAVE_SSL
&& cur_url->url->scheme != SCHEME_FTPS
#endif
) || proxy))
{
int old_follow_ftp = opt.follow_ftp;
/* Turn opt.follow_ftp on in case of recursive FTP retrieval */
if (cur_url->url->scheme == SCHEME_FTP
#ifdef HAVE_SSL
|| cur_url->url->scheme == SCHEME_FTPS
#endif
)
opt.follow_ftp = 1;
status = retrieve_tree (parsed_url ? parsed_url : cur_url->url,
tmpiri);
opt.follow_ftp = old_follow_ftp;
}
else
status = retrieve_url (parsed_url ? parsed_url : cur_url->url,
cur_url->url->url, &filename,
&new_file, NULL, &dt, opt.recursive, tmpiri,
true);
xfree (proxy);
if (parsed_url)
url_free (parsed_url);
if (filename && opt.delete_after && file_exists_p (filename, NULL))
{
DEBUGP (("\
Removing file due to --delete-after in retrieve_from_file():\n"));
logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename);
if (unlink (filename))
logprintf (LOG_NOTQUIET, "Failed to unlink %s: (%d) %s\n", filename, errno, strerror (errno));
dt &= ~RETROKF;
}
xfree (new_file);
xfree (filename);
iri_free (tmpiri);
}
/* Free the linked list of URL-s. */
free_urlpos (url_list);
iri_free (iri);
return status;
}
|
CWE-119
| 3,223 | 13,304 |
6362759562777173818902570748574996046
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
char **newloc, const char *refurl, int *dt, bool recursive,
struct iri *iri, bool register_status)
{
uerr_t result;
char *url;
bool location_changed;
bool iri_fallbacked = 0;
int dummy;
char *mynewloc, *proxy;
struct url *u = orig_parsed, *proxy_url;
int up_error_code; /* url parse error code */
char *local_file = NULL;
int redirection_count = 0;
bool method_suspended = false;
char *saved_body_data = NULL;
char *saved_method = NULL;
char *saved_body_file_name = NULL;
/* If dt is NULL, use local storage. */
if (!dt)
{
dt = &dummy;
dummy = 0;
}
url = xstrdup (origurl);
if (newloc)
*newloc = NULL;
if (file)
*file = NULL;
if (!refurl)
refurl = opt.referer;
redirected:
/* (also for IRI fallbacking) */
result = NOCONERROR;
mynewloc = NULL;
xfree(local_file);
proxy_url = NULL;
proxy = getproxy (u);
if (proxy)
{
struct iri *pi = iri_new ();
set_uri_encoding (pi, opt.locale, true);
pi->utf8_encode = false;
/* Parse the proxy URL. */
proxy_url = url_parse (proxy, &up_error_code, pi, true);
if (!proxy_url)
{
char *error = url_error (proxy, up_error_code);
logprintf (LOG_NOTQUIET, _("Error parsing proxy URL %s: %s.\n"),
proxy, error);
xfree (url);
xfree (error);
xfree (proxy);
iri_free (pi);
RESTORE_METHOD;
result = PROXERR;
goto bail;
}
if (proxy_url->scheme != SCHEME_HTTP && proxy_url->scheme != u->scheme)
{
logprintf (LOG_NOTQUIET, _("Error in proxy URL %s: Must be HTTP.\n"), proxy);
url_free (proxy_url);
xfree (url);
xfree (proxy);
iri_free (pi);
RESTORE_METHOD;
result = PROXERR;
goto bail;
}
iri_free(pi);
xfree (proxy);
}
if (u->scheme == SCHEME_HTTP
#ifdef HAVE_SSL
|| u->scheme == SCHEME_HTTPS
#endif
|| (proxy_url && proxy_url->scheme == SCHEME_HTTP))
{
#ifdef HAVE_HSTS
#ifdef TESTING
/* we don't link against main.o when we're testing */
hsts_store_t hsts_store = NULL;
#else
extern hsts_store_t hsts_store;
#endif
if (opt.hsts && hsts_store)
{
if (hsts_match (hsts_store, u))
logprintf (LOG_VERBOSE, "URL transformed to HTTPS due to an HSTS policy\n");
}
#endif
result = http_loop (u, orig_parsed, &mynewloc, &local_file, refurl, dt,
proxy_url, iri);
}
else if (u->scheme == SCHEME_FTP
#ifdef HAVE_SSL
|| u->scheme == SCHEME_FTPS
#endif
)
{
/* If this is a redirection, temporarily turn off opt.ftp_glob
and opt.recursive, both being undesirable when following
redirects. */
bool oldrec = recursive, glob = opt.ftp_glob;
if (redirection_count)
oldrec = glob = false;
result = ftp_loop (u, orig_parsed, &local_file, dt, proxy_url,
recursive, glob);
recursive = oldrec;
/* There is a possibility of having HTTP being redirected to
FTP. In these cases we must decide whether the text is HTML
according to the suffix. The HTML suffixes are `.html',
`.htm' and a few others, case-insensitive. */
if (redirection_count && local_file && (u->scheme == SCHEME_FTP
#ifdef HAVE_SSL
|| u->scheme == SCHEME_FTPS
#endif
))
{
if (has_html_suffix_p (local_file))
*dt |= TEXTHTML;
}
}
if (proxy_url)
{
url_free (proxy_url);
proxy_url = NULL;
}
location_changed = (result == NEWLOCATION || result == NEWLOCATION_KEEP_POST);
if (location_changed)
{
char *construced_newloc;
struct url *newloc_parsed;
assert (mynewloc != NULL);
xfree (local_file);
/* The HTTP specs only allow absolute URLs to appear in
redirects, but a ton of boneheaded webservers and CGIs out
there break the rules and use relative URLs, and popular
browsers are lenient about this, so wget should be too. */
construced_newloc = uri_merge (url, mynewloc ? mynewloc : "");
xfree (mynewloc);
mynewloc = construced_newloc;
#ifdef ENABLE_IRI
/* Reset UTF-8 encoding state, set the URI encoding and reset
the content encoding. */
iri->utf8_encode = opt.enable_iri;
if (opt.encoding_remote)
set_uri_encoding (iri, opt.encoding_remote, true);
set_content_encoding (iri, NULL);
xfree (iri->orig_url);
#endif
/* Now, see if this new location makes sense. */
newloc_parsed = url_parse (mynewloc, &up_error_code, iri, true);
if (!newloc_parsed)
{
char *error = url_error (mynewloc, up_error_code);
logprintf (LOG_NOTQUIET, "%s: %s.\n", escnonprint_uri (mynewloc),
error);
if (orig_parsed != u)
{
url_free (u);
}
xfree (url);
xfree (mynewloc);
xfree (error);
RESTORE_METHOD;
goto bail;
}
/* Now mynewloc will become newloc_parsed->url, because if the
Location contained relative paths like .././something, we
don't want that propagating as url. */
xfree (mynewloc);
mynewloc = xstrdup (newloc_parsed->url);
/* Check for max. number of redirections. */
if (++redirection_count > opt.max_redirect)
{
logprintf (LOG_NOTQUIET, _("%d redirections exceeded.\n"),
opt.max_redirect);
url_free (newloc_parsed);
if (orig_parsed != u)
{
url_free (u);
}
xfree (url);
xfree (mynewloc);
RESTORE_METHOD;
result = WRONGCODE;
goto bail;
}
xfree (url);
url = mynewloc;
if (orig_parsed != u)
{
url_free (u);
}
u = newloc_parsed;
/* If we're being redirected from POST, and we received a
redirect code different than 307, we don't want to POST
again. Many requests answer POST with a redirection to an
index page; that redirection is clearly a GET. We "suspend"
POST data for the duration of the redirections, and restore
it when we're done.
RFC2616 HTTP/1.1 introduces code 307 Temporary Redirect
specifically to preserve the method of the request.
*/
if (result != NEWLOCATION_KEEP_POST && !method_suspended)
SUSPEND_METHOD;
goto redirected;
}
else
{
xfree(mynewloc);
}
/* Try to not encode in UTF-8 if fetching failed */
if (!(*dt & RETROKF) && iri->utf8_encode)
{
iri->utf8_encode = false;
if (orig_parsed != u)
{
url_free (u);
}
u = url_parse (origurl, NULL, iri, true);
if (u)
{
if (strcmp(u->url, orig_parsed->url))
{
DEBUGP (("[IRI fallbacking to non-utf8 for %s\n", quote (url)));
xfree (url);
url = xstrdup (u->url);
iri_fallbacked = 1;
goto redirected;
}
else
DEBUGP (("[Needn't fallback to non-utf8 for %s\n", quote (url)));
}
else
DEBUGP (("[Couldn't fallback to non-utf8 for %s\n", quote (url)));
}
if (local_file && u && (*dt & RETROKF || opt.content_on_error))
{
register_download (u->url, local_file);
if (!opt.spider && redirection_count && 0 != strcmp (origurl, u->url))
register_redirection (origurl, u->url);
if (*dt & TEXTHTML)
register_html (local_file);
if (*dt & TEXTCSS)
register_css (local_file);
}
if (file)
*file = local_file ? local_file : NULL;
else
xfree (local_file);
if (orig_parsed != u)
{
url_free (u);
}
if (redirection_count || iri_fallbacked)
{
if (newloc)
*newloc = url;
else
xfree (url);
}
else
{
if (newloc)
*newloc = NULL;
xfree (url);
}
RESTORE_METHOD;
bail:
if (register_status)
inform_exit_status (result);
return result;
}
|
CWE-119
| 3,224 | 13,305 |
328713513349489212596217495724164218835
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
rotate_backups(const char *fname)
{
#ifdef __VMS
# define SEP "_"
# define AVS ";*" /* All-version suffix. */
# define AVSL (sizeof (AVS) - 1)
#else
# define SEP "."
# define AVSL 0
#endif
int maxlen = strlen (fname) + sizeof (SEP) + numdigit (opt.backups) + AVSL;
char *from = alloca (maxlen);
char *to = alloca (maxlen);
struct stat sb;
int i;
if (stat (fname, &sb) == 0)
if (S_ISREG (sb.st_mode) == 0)
return;
for (i = opt.backups; i > 1; i--)
{
#ifdef VMS
/* Delete (all versions of) any existing max-suffix file, to avoid
* creating multiple versions of it. (On VMS, rename() will
* create a new version of an existing destination file, not
* destroy/overwrite it.)
*/
if (i == opt.backups)
{
snprintf (to, sizeof(to), "%s%s%d%s", fname, SEP, i, AVS);
delete (to);
}
#endif
snprintf (to, maxlen, "%s%s%d", fname, SEP, i);
snprintf (from, maxlen, "%s%s%d", fname, SEP, i - 1);
if (rename (from, to))
logprintf (LOG_NOTQUIET, "Failed to rename %s to %s: (%d) %s\n",
from, to, errno, strerror (errno));
}
snprintf (to, maxlen, "%s%s%d", fname, SEP, 1);
if (rename(fname, to))
logprintf (LOG_NOTQUIET, "Failed to rename %s to %s: (%d) %s\n",
fname, to, errno, strerror (errno));
}
|
CWE-119
| 3,225 | 13,306 |
294026260071657709054672298283891420602
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
set_local_file (const char **file, const char *default_file)
{
if (opt.output_document)
{
if (output_stream_regular)
*file = opt.output_document;
}
else
*file = default_file;
}
|
CWE-119
| 3,226 | 13,307 |
87212489917141355537167860358981914547
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
sleep_between_retrievals (int count)
{
static bool first_retrieval = true;
if (first_retrieval)
{
/* Don't sleep before the very first retrieval. */
first_retrieval = false;
return;
}
if (opt.waitretry && count > 1)
{
/* If opt.waitretry is specified and this is a retry, wait for
COUNT-1 number of seconds, or for opt.waitretry seconds. */
if (count <= opt.waitretry)
xsleep (count - 1);
else
xsleep (opt.waitretry);
}
else if (opt.wait)
{
if (!opt.random_wait || count > 1)
/* If random-wait is not specified, or if we are sleeping
between retries of the same download, sleep the fixed
interval. */
xsleep (opt.wait);
else
{
/* Sleep a random amount of time averaging in opt.wait
seconds. The sleeping amount ranges from 0.5*opt.wait to
1.5*opt.wait. */
double waitsecs = (0.5 + random_float ()) * opt.wait;
DEBUGP (("sleep_between_retrievals: avg=%f,sleep=%f\n",
opt.wait, waitsecs));
xsleep (waitsecs);
}
}
}
|
CWE-119
| 3,227 | 13,308 |
88821277517548467300985250588172092136
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
url_uses_proxy (struct url * u)
{
bool ret;
char *proxy;
if (!u)
return false;
proxy = getproxy (u);
ret = proxy != NULL;
xfree (proxy);
return ret;
}
|
CWE-119
| 3,228 | 13,309 |
239828032782237846959248671875133904931
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
zalloc (voidpf opaque, unsigned int items, unsigned int size)
{
(void) opaque;
return (voidpf) xcalloc (items, size);
}
|
CWE-119
| 3,230 | 13,310 |
48044752433430689143667468731440996289
| null | null | null |
savannah
|
ba6b44f6745b14dce414761a8e4b35d31b176bba
| 0 |
zfree (voidpf opaque, voidpf address)
{
(void) opaque;
xfree (address);
}
|
CWE-119
| 3,231 | 13,311 |
4528613452142046848287888424139133570
| null | null | null |
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
check_file_permissions(i_ctx_t *i_ctx_p, const char *fname, int len,
gx_io_device *iodev, const char *permitgroup)
{
char fname_reduced[gp_file_name_sizeof];
uint rlen = sizeof(fname_reduced);
if (gp_file_name_reduce(fname, len, fname_reduced, &rlen) != gp_combine_success)
return gs_error_invalidaccess; /* fail if we couldn't reduce */
return check_file_permissions_reduced(i_ctx_p, fname_reduced, rlen, iodev, permitgroup);
}
| 3,348 | 13,370 |
64640629699522056264730904451748547729
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
execfile_cleanup(i_ctx_t *i_ctx_p)
{
check_ostack(1);
*++osp = esp[2];
return zclosefile(i_ctx_p);
}
| 3,349 | 13,371 |
32290595450673672732208209857531648781
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
execfile_finish(i_ctx_t *i_ctx_p)
{
check_ostack(1);
esp -= 2;
execfile_cleanup(i_ctx_p);
return o_pop_estack;
}
| 3,350 | 13,372 |
53055284484100289885489934239406462396
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
file_cleanup(i_ctx_t *i_ctx_p)
{
gx_io_device *iodev = r_ptr(esp + 2, gx_io_device);
iodev->procs.enumerate_close(r_ptr(esp + 5, file_enum));
return 0;
}
| 3,351 | 13,373 |
60715895058148941936498838947572972150
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
file_continue(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
es_ptr pscratch = esp - 2;
file_enum *pfen = r_ptr(esp - 1, file_enum);
int devlen = esp[-3].value.intval;
gx_io_device *iodev = r_ptr(esp - 4, gx_io_device);
uint len = r_size(pscratch);
uint code;
if (len < devlen)
return_error(gs_error_rangecheck); /* not even room for device len */
do {
memcpy((char *)pscratch->value.bytes, iodev->dname, devlen);
code = iodev->procs.enumerate_next(pfen, (char *)pscratch->value.bytes + devlen,
len - devlen);
if (code == ~(uint) 0) { /* all done */
esp -= 5; /* pop proc, pfen, devlen, iodev , mark */
return o_pop_estack;
} else if (code > len) /* overran string */
return_error(gs_error_rangecheck);
else if (iodev != iodev_default(imemory)
|| (check_file_permissions(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, iodev, "PermitFileReading")) == 0) {
push(1);
ref_assign(op, pscratch);
r_set_size(op, code + devlen);
push_op_estack(file_continue); /* come again */
*++esp = pscratch[2]; /* proc */
return o_push_estack;
}
} while(1);
}
| 3,352 | 13,374 |
333724299582216166002742348576321935634
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
file_is_tempfile(i_ctx_t *i_ctx_p, const uchar *fname, int len)
{
ref *SAFETY;
ref *tempfiles;
ref kname;
if (dict_find_string(systemdict, "SAFETY", &SAFETY) <= 0 ||
dict_find_string(SAFETY, "tempfiles", &tempfiles) <= 0)
return false;
if (name_ref(imemory, fname, len, &kname, -1) < 0 ||
dict_find(tempfiles, &kname, &SAFETY) <= 0)
return false;
return true;
}
| 3,353 | 13,375 |
271616700076594174480702628662965413806
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
make_invalid_file(i_ctx_t *i_ctx_p, ref * fp)
{
make_file(fp, avm_invalid_file_entry, ~0, i_ctx_p->invalid_file_stream);
}
| 3,354 | 13,376 |
285969683974576388217458579865357288238
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
prefix_is_simple(const char *pstr)
{
int i;
char c;
for (i = 0; (c = pstr[i]) != 0; i++) {
if (!(c == '-' || c == '_' || (c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')))
return false;
}
return true;
}
| 3,355 | 13,377 |
73473627103539537756619558964511787062
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zdeletefile(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
gs_parsed_file_name_t pname;
int code = parse_real_file_name(op, &pname, imemory, "deletefile");
if (code < 0)
return code;
if (pname.iodev == iodev_default(imemory)) {
if ((code = check_file_permissions(i_ctx_p, pname.fname, pname.len,
pname.iodev, "PermitFileControl")) < 0 &&
!file_is_tempfile(i_ctx_p, op->value.bytes, r_size(op))) {
return code;
}
}
code = (*pname.iodev->procs.delete_file)(pname.iodev, pname.fname);
gs_free_file_name(&pname, "deletefile");
if (code < 0)
return code;
pop(1);
return 0;
}
| 3,357 | 13,378 |
22559057806888130607787067667831616736
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zexecfile(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
check_type_access(*op, t_file, a_executable | a_read | a_execute);
check_estack(4); /* cleanup, file, finish, file */
push_mark_estack(es_other, execfile_cleanup);
*++esp = *op;
push_op_estack(execfile_finish);
return zexec(i_ctx_p);
}
| 3,358 | 13,379 |
270955082830400958757180340942405664975
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zfile(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
char file_access[4];
gs_parsed_file_name_t pname;
int code = parse_file_access_string(op, file_access);
stream *s;
if (code < 0)
return code;
code = parse_file_name(op-1, &pname, i_ctx_p->LockFilePermissions, imemory);
if (code < 0)
return code;
/*
* HACK: temporarily patch the current context pointer into the
* state pointer for stdio-related devices. See ziodev.c for
* more information.
*/
if (pname.iodev && pname.iodev->dtype == iodev_dtype_stdio) {
bool statement = (strcmp(pname.iodev->dname, "%statementedit%") == 0);
bool lineedit = (strcmp(pname.iodev->dname, "%lineedit%") == 0);
if (pname.fname)
return_error(gs_error_invalidfileaccess);
if (statement || lineedit) {
/* These need special code to support callouts */
gx_io_device *indev = gs_findiodevice(imemory,
(const byte *)"%stdin", 6);
stream *ins;
if (strcmp(file_access, "r"))
return_error(gs_error_invalidfileaccess);
indev->state = i_ctx_p;
code = (indev->procs.open_device)(indev, file_access, &ins, imemory);
indev->state = 0;
if (code < 0)
return code;
check_ostack(2);
push(2);
make_stream_file(op - 3, ins, file_access);
make_bool(op-2, statement);
make_int(op-1, 0);
make_string(op, icurrent_space, 0, NULL);
return zfilelineedit(i_ctx_p);
}
pname.iodev->state = i_ctx_p;
code = (*pname.iodev->procs.open_device)(pname.iodev,
file_access, &s, imemory);
pname.iodev->state = NULL;
} else {
if (pname.iodev == NULL)
pname.iodev = iodev_default(imemory);
code = zopen_file(i_ctx_p, &pname, file_access, &s, imemory);
}
if (code < 0)
return code;
code = ssetfilename(s, op[-1].value.const_bytes, r_size(op - 1));
if (code < 0) {
sclose(s);
return_error(gs_error_VMerror);
}
make_stream_file(op - 1, s, file_access);
pop(1);
return code;
}
| 3,359 | 13,380 |
257929439913272661642181951714005843621
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zfilenameforall(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
file_enum *pfen;
gx_io_device *iodev = NULL;
gs_parsed_file_name_t pname;
int code = 0;
check_write_type(*op, t_string);
check_proc(op[-1]);
check_read_type(op[-2], t_string);
/* Push a mark, the iodev, devicenamelen, the scratch string, the enumerator, */
/* and the procedure, and invoke the continuation. */
check_estack(7);
/* Get the iodevice */
code = parse_file_name(op-2, &pname, i_ctx_p->LockFilePermissions, imemory);
if (code < 0)
return code;
iodev = (pname.iodev == NULL) ? iodev_default(imemory) : pname.iodev;
/* Check for several conditions that just cause us to return success */
if (pname.len == 0 || iodev->procs.enumerate_files == iodev_no_enumerate_files) {
pop(3);
return 0; /* no pattern, or device not found -- just return */
}
pfen = iodev->procs.enumerate_files(iodev, (const char *)pname.fname,
pname.len, imemory);
if (pfen == 0)
return_error(gs_error_VMerror);
push_mark_estack(es_for, file_cleanup);
++esp;
make_istruct(esp, 0, iodev);
++esp;
make_int(esp, r_size(op-2) - pname.len);
*++esp = *op;
++esp;
make_istruct(esp, 0, pfen);
*++esp = op[-1];
pop(3);
code = file_continue(i_ctx_p);
return (code == o_pop_estack ? o_push_estack : code);
}
| 3,360 | 13,381 |
172501702646678625091150490659335910541
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zfilenamelistseparator(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
push(1);
make_const_string(op, avm_foreign | a_readonly, 1,
(const byte *)&gp_file_name_list_separator);
return 0;
}
| 3,361 | 13,382 |
72363697945693168299626055851447277526
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zfilenamesplit(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
check_read_type(*op, t_string);
/****** NOT IMPLEMENTED YET ******/
return_error(gs_error_undefined);
}
| 3,362 | 13,383 |
308168029720086571513811045970767199045
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zlibfile(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
int code;
byte cname[DEFAULT_BUFFER_SIZE];
uint clen;
gs_parsed_file_name_t pname;
stream *s;
gx_io_device *iodev_dflt;
check_ostack(2);
code = parse_file_name(op, &pname, i_ctx_p->LockFilePermissions, imemory);
if (code < 0)
return code;
iodev_dflt = iodev_default(imemory);
if (pname.iodev == NULL)
pname.iodev = iodev_dflt;
if (pname.iodev != iodev_dflt) { /* Non-OS devices don't have search paths (yet). */
code = zopen_file(i_ctx_p, &pname, "r", &s, imemory);
if (code >= 0) {
code = ssetfilename(s, op->value.const_bytes, r_size(op));
if (code < 0) {
sclose(s);
return_error(gs_error_VMerror);
}
}
if (code < 0) {
push(1);
make_false(op);
return 0;
}
make_stream_file(op, s, "r");
} else {
ref fref;
code = lib_file_open(i_ctx_p->lib_path, imemory, i_ctx_p, pname.fname, pname.len,
(char *)cname, sizeof(cname), &clen, &fref);
if (code >= 0) {
s = fptr(&fref);
code = ssetfilename(s, cname, clen);
if (code < 0) {
sclose(s);
return_error(gs_error_VMerror);
}
}
if (code < 0) {
if (code == gs_error_VMerror || code == gs_error_invalidfileaccess)
return code;
push(1);
make_false(op);
return 0;
}
ref_assign(op, &fref);
}
push(1);
make_true(op);
return 0;
}
| 3,363 | 13,384 |
198223944056374148520908471679426279805
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zrenamefile(i_ctx_t *i_ctx_p)
{
int code;
os_ptr op = osp;
gs_parsed_file_name_t pname1, pname2;
code = parse_real_file_name(op, &pname2, imemory, "renamefile(to)");
if (code < 0)
return code;
pname1.fname = 0;
code = parse_real_file_name(op - 1, &pname1, imemory, "renamefile(from)");
if (code >= 0) {
gx_io_device *iodev_dflt = iodev_default(imemory);
if (pname1.iodev != pname2.iodev ) {
if (pname1.iodev == iodev_dflt)
pname1.iodev = pname2.iodev;
if (pname2.iodev == iodev_dflt)
pname2.iodev = pname1.iodev;
}
if (pname1.iodev != pname2.iodev ||
(pname1.iodev == iodev_dflt &&
/*
* We require FileControl permissions on the source path
* unless it is a temporary file. Also, we require FileControl
* and FileWriting permissions to the destination file/path.
*/
((check_file_permissions(i_ctx_p, pname1.fname, pname1.len,
pname1.iodev, "PermitFileControl") < 0 &&
!file_is_tempfile(i_ctx_p, op[-1].value.bytes, r_size(op - 1))) ||
(check_file_permissions(i_ctx_p, pname2.fname, pname2.len,
pname2.iodev, "PermitFileControl") < 0 ||
check_file_permissions(i_ctx_p, pname2.fname, pname2.len,
pname2.iodev, "PermitFileWriting") < 0 )))) {
code = gs_note_error(gs_error_invalidfileaccess);
} else {
code = (*pname1.iodev->procs.rename_file)(pname1.iodev,
pname1.fname, pname2.fname);
}
}
gs_free_file_name(&pname2, "renamefile(to)");
gs_free_file_name(&pname1, "renamefile(from)");
if (code < 0)
return code;
pop(2);
return 0;
}
| 3,364 | 13,385 |
311604776856509470164145998591308195867
| null | null | null |
|
ghostscript
|
0d3901189f245232f0161addf215d7268c4d05a3
| 0 |
zstatus(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
switch (r_type(op)) {
case t_file:
{
stream *s;
make_bool(op, (file_is_valid(s, op) ? 1 : 0));
}
return 0;
case t_string:
{
gs_parsed_file_name_t pname;
struct stat fstat;
int code = parse_file_name(op, &pname,
i_ctx_p->LockFilePermissions, imemory);
if (code < 0) {
if (code == gs_error_undefinedfilename) {
make_bool(op, 0);
code = 0;
}
return code;
}
code = gs_terminate_file_name(&pname, imemory, "status");
if (code < 0)
return code;
if ((code = check_file_permissions(i_ctx_p, pname.fname, pname.len,
pname.iodev, "PermitFileReading")) >= 0) {
code = (*pname.iodev->procs.file_status)(pname.iodev,
pname.fname, &fstat);
}
switch (code) {
case 0:
check_ostack(4);
/*
* Check to make sure that the file size fits into
* a PostScript integer. (On some systems, long is
* 32 bits, but file sizes are 64 bits.)
*/
push(4);
make_int(op - 4, stat_blocks(&fstat));
make_int(op - 3, fstat.st_size);
/*
* We can't check the value simply by using ==,
* because signed/unsigned == does the wrong thing.
* Instead, since integer assignment only keeps the
* bottom bits, we convert the values to double
* and then test for equality. This handles all
* cases of signed/unsigned or width mismatch.
*/
if ((double)op[-4].value.intval !=
(double)stat_blocks(&fstat) ||
(double)op[-3].value.intval !=
(double)fstat.st_size
)
return_error(gs_error_limitcheck);
make_int(op - 2, fstat.st_mtime);
make_int(op - 1, fstat.st_ctime);
make_bool(op, 1);
break;
case gs_error_undefinedfilename:
make_bool(op, 0);
code = 0;
}
gs_free_file_name(&pname, "status");
return code;
}
default:
return_op_typecheck(op);
}
}
| 3,365 | 13,386 |
249372932293879607957909647912730073353
| null | null | null |
|
drm
|
9f1f1a2dab38d4ce87a13565cf4dc1b73bef3a5f
| 0 |
int __drm_get_edid_firmware_path(char *buf, size_t bufsize)
{
return scnprintf(buf, bufsize, "%s", edid_firmware);
}
|
CWE-476
| 3,366 | 13,387 |
167247304375795271580274066184679786328
| null | null | null |
drm
|
9f1f1a2dab38d4ce87a13565cf4dc1b73bef3a5f
| 0 |
int __drm_set_edid_firmware_path(const char *path)
{
scnprintf(edid_firmware, sizeof(edid_firmware), "%s", path);
return 0;
}
|
CWE-476
| 3,367 | 13,388 |
2596171284463625998421206544754375269
| null | null | null |
drm
|
9f1f1a2dab38d4ce87a13565cf4dc1b73bef3a5f
| 0 |
static void *edid_load(struct drm_connector *connector, const char *name,
const char *connector_name)
{
const struct firmware *fw = NULL;
const u8 *fwdata;
u8 *edid;
int fwsize, builtin;
int i, valid_extensions = 0;
bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
builtin = match_string(generic_edid_name, GENERIC_EDIDS, name);
if (builtin >= 0) {
fwdata = generic_edid[builtin];
fwsize = sizeof(generic_edid[builtin]);
} else {
struct platform_device *pdev;
int err;
pdev = platform_device_register_simple(connector_name, -1, NULL, 0);
if (IS_ERR(pdev)) {
DRM_ERROR("Failed to register EDID firmware platform device "
"for connector \"%s\"\n", connector_name);
return ERR_CAST(pdev);
}
err = request_firmware(&fw, name, &pdev->dev);
platform_device_unregister(pdev);
if (err) {
DRM_ERROR("Requesting EDID firmware \"%s\" failed (err=%d)\n",
name, err);
return ERR_PTR(err);
}
fwdata = fw->data;
fwsize = fw->size;
}
if (edid_size(fwdata, fwsize) != fwsize) {
DRM_ERROR("Size of EDID firmware \"%s\" is invalid "
"(expected %d, got %d\n", name,
edid_size(fwdata, fwsize), (int)fwsize);
edid = ERR_PTR(-EINVAL);
goto out;
}
edid = kmemdup(fwdata, fwsize, GFP_KERNEL);
if (edid == NULL) {
edid = ERR_PTR(-ENOMEM);
goto out;
}
if (!drm_edid_block_valid(edid, 0, print_bad_edid,
&connector->edid_corrupt)) {
connector->bad_edid_counter++;
DRM_ERROR("Base block of EDID firmware \"%s\" is invalid ",
name);
kfree(edid);
edid = ERR_PTR(-EINVAL);
goto out;
}
for (i = 1; i <= edid[0x7e]; i++) {
if (i != valid_extensions + 1)
memcpy(edid + (valid_extensions + 1) * EDID_LENGTH,
edid + i * EDID_LENGTH, EDID_LENGTH);
if (drm_edid_block_valid(edid + i * EDID_LENGTH, i,
print_bad_edid,
NULL))
valid_extensions++;
}
if (valid_extensions != edid[0x7e]) {
u8 *new_edid;
edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
DRM_INFO("Found %d valid extensions instead of %d in EDID data "
"\"%s\" for connector \"%s\"\n", valid_extensions,
edid[0x7e], name, connector_name);
edid[0x7e] = valid_extensions;
new_edid = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH,
GFP_KERNEL);
if (new_edid)
edid = new_edid;
}
DRM_INFO("Got %s EDID base block and %d extension%s from "
"\"%s\" for connector \"%s\"\n", (builtin >= 0) ? "built-in" :
"external", valid_extensions, valid_extensions == 1 ? "" : "s",
name, connector_name);
out:
release_firmware(fw);
return edid;
}
|
CWE-476
| 3,368 | 13,389 |
69145133261595555986767402094411611548
| null | null | null |
drm
|
9f1f1a2dab38d4ce87a13565cf4dc1b73bef3a5f
| 0 |
static int edid_size(const u8 *edid, int data_size)
{
if (data_size < EDID_LENGTH)
return 0;
return (edid[0x7e] + 1) * EDID_LENGTH;
}
|
CWE-476
| 3,369 | 13,390 |
336785181459859883947005494545317435881
| null | null | null |
savannah
|
c265cad1c95b84abfd4e8d861f25926ef13b5d91
| 0 |
irc_server_set_prefix_modes_chars (struct t_irc_server *server,
const char *prefix)
{
char *pos;
int i, length_modes, length_chars;
if (!server || !prefix)
return;
/* free previous values */
if (server->prefix_modes)
{
free (server->prefix_modes);
server->prefix_modes = NULL;
}
if (server->prefix_chars)
{
free (server->prefix_chars);
server->prefix_chars = NULL;
}
/* assign new values */
pos = strchr (prefix, ')');
if (pos)
{
server->prefix_modes = weechat_strndup (prefix + 1,
pos - prefix - 1);
if (server->prefix_modes)
{
pos++;
length_modes = strlen (server->prefix_modes);
length_chars = strlen (pos);
server->prefix_chars = malloc (length_modes + 1);
if (server->prefix_chars)
{
for (i = 0; i < length_modes; i++)
{
server->prefix_chars[i] = (i < length_chars) ? pos[i] : ' ';
}
server->prefix_chars[length_modes] = '\0';
}
else
{
free (server->prefix_modes);
server->prefix_modes = NULL;
}
}
}
}
|
CWE-20
| 3,522 | 13,508 |
139147605210658704577205323275048076828
| null | null | null |
haproxy
|
7ec765568883b2d4e5a2796adbeb492a22ec9bd4
| 0 |
void buffer_dump(FILE *o, struct buffer *b, int from, int to)
{
fprintf(o, "Dumping buffer %p\n", b);
fprintf(o, " data=%p o=%d i=%d p=%p\n"
" relative: p=0x%04x\n",
b->data, b->o, b->i, b->p, (unsigned int)(b->p - b->data));
fprintf(o, "Dumping contents from byte %d to byte %d\n", from, to);
fprintf(o, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
/* dump hexa */
while (from < to) {
int i;
fprintf(o, " %04x: ", from);
for (i = 0; ((from + i) < to) && (i < 16) ; i++) {
fprintf(o, "%02x ", (unsigned char)b->data[from + i]);
if (((from + i) & 15) == 7)
fprintf(o, "- ");
}
if (to - from < 16) {
int j = 0;
for (j = 0; j < from + 16 - to; j++)
fprintf(o, " ");
if (j > 8)
fprintf(o, " ");
}
fprintf(o, " ");
for (i = 0; (from + i < to) && (i < 16) ; i++) {
fprintf(o, "%c", isprint((int)b->data[from + i]) ? b->data[from + i] : '.') ;
if ((((from + i) & 15) == 15) && ((from + i) != to-1))
fprintf(o, "\n");
}
from += i;
}
fprintf(o, "\n--\n");
fflush(o);
}
|
CWE-119
| 3,532 | 13,514 |
226756074562389132494745960719594042179
| null | null | null |
haproxy
|
7ec765568883b2d4e5a2796adbeb492a22ec9bd4
| 0 |
int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
{
int delta;
delta = len + 2;
if (bi_end(b) + delta >= b->data + b->size)
return 0; /* no space left */
if (buffer_not_empty(b) &&
bi_end(b) + delta > bo_ptr(b) &&
bo_ptr(b) >= bi_end(b))
return 0; /* no space left before wrapping data */
/* first, protect the end of the buffer */
memmove(pos + delta, pos, bi_end(b) - pos);
/* now, copy str over pos */
if (len && str) {
memcpy(pos, str, len);
pos[len] = '\r';
pos[len + 1] = '\n';
}
b->i += delta;
return delta;
}
|
CWE-119
| 3,533 | 13,515 |
213590683596263264512213135387704349558
| null | null | null |
haproxy
|
7ec765568883b2d4e5a2796adbeb492a22ec9bd4
| 0 |
int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len)
{
int delta;
delta = len - (end - pos);
if (bi_end(b) + delta > b->data + b->size)
return 0; /* no space left */
if (buffer_not_empty(b) &&
bi_end(b) + delta > bo_ptr(b) &&
bo_ptr(b) >= bi_end(b))
return 0; /* no space left before wrapping data */
/* first, protect the end of the buffer */
memmove(end + delta, end, bi_end(b) - end);
/* now, copy str over pos */
if (len)
memcpy(pos, str, len);
b->i += delta;
if (buffer_empty(b))
b->p = b->data;
return delta;
}
|
CWE-119
| 3,534 | 13,516 |
334969875149820210409797215358691351331
| null | null | null |
haproxy
|
7ec765568883b2d4e5a2796adbeb492a22ec9bd4
| 0 |
int init_buffer()
{
pool2_buffer = create_pool("buffer", sizeof (struct buffer) + global.tune.bufsize, MEM_F_SHARED);
return pool2_buffer != NULL;
}
|
CWE-119
| 3,535 | 13,517 |
63967265063489698209849829221684640730
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
api_opaque_lsa_print (struct lsa_header *data)
{
struct opaque_lsa
{
struct lsa_header header;
u_char mydata[];
};
struct opaque_lsa *olsa;
int opaquelen;
int i;
ospf_lsa_header_dump (data);
olsa = (struct opaque_lsa *) data;
opaquelen = ntohs (data->length) - OSPF_LSA_HEADER_SIZE;
zlog_debug ("apiserver_lsa_print: opaquelen=%d\n", opaquelen);
for (i = 0; i < opaquelen; i++)
{
zlog_debug ("0x%x ", olsa->mydata[i]);
}
zlog_debug ("\n");
}
|
CWE-119
| 3,563 | 13,543 |
130434259034029992574491463460096228965
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_dup (struct msg *msg)
{
struct msg *new;
assert (msg);
new = msg_new (msg->hdr.msgtype, STREAM_DATA (msg->s),
ntohl (msg->hdr.msgseq), ntohs (msg->hdr.msglen));
return new;
}
|
CWE-119
| 3,564 | 13,544 |
254899380917647595920988423588824089498
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_fifo_flush (struct msg_fifo *fifo)
{
struct msg *op;
struct msg *next;
for (op = fifo->head; op; op = next)
{
next = op->next;
msg_free (op);
}
fifo->head = fifo->tail = NULL;
fifo->count = 0;
}
|
CWE-119
| 3,565 | 13,545 |
287099124128760406350056079725609158890
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_fifo_free (struct msg_fifo *fifo)
{
msg_fifo_flush (fifo);
XFREE (MTYPE_OSPF_API_FIFO, fifo);
}
|
CWE-119
| 3,566 | 13,546 |
55246014808040434632519279347493110262
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_fifo_head (struct msg_fifo *fifo)
{
return fifo->head;
}
|
CWE-119
| 3,567 | 13,547 |
64612968300241443397674618049840324010
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_fifo_new ()
{
return XCALLOC (MTYPE_OSPF_API_FIFO, sizeof (struct msg_fifo));
}
|
CWE-119
| 3,568 | 13,548 |
182082531806792208745821704565018834271
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_fifo_pop (struct msg_fifo *fifo)
{
struct msg *msg;
msg = fifo->head;
if (msg)
{
fifo->head = msg->next;
if (fifo->head == NULL)
fifo->tail = NULL;
fifo->count--;
}
return msg;
}
|
CWE-119
| 3,569 | 13,549 |
62212069805203738071699380278739408849
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_fifo_push (struct msg_fifo *fifo, struct msg *msg)
{
if (fifo->tail)
fifo->tail->next = msg;
else
fifo->head = msg;
fifo->tail = msg;
fifo->count++;
}
|
CWE-119
| 3,570 | 13,550 |
65943404959067439087790472078747705383
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_free (struct msg *msg)
{
if (msg->s)
stream_free (msg->s);
XFREE (MTYPE_OSPF_API_MSG, msg);
}
|
CWE-119
| 3,571 | 13,551 |
45219216526661756249389592199276755057
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_get_seq (struct msg *msg)
{
assert (msg);
return ntohl (msg->hdr.msgseq);
}
|
CWE-119
| 3,572 | 13,552 |
1875383675659823832433110524209401760
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_new (u_char msgtype, void *msgbody, u_int32_t seqnum, u_int16_t msglen)
{
struct msg *new;
new = XCALLOC (MTYPE_OSPF_API_MSG, sizeof (struct msg));
new->hdr.version = OSPF_API_VERSION;
new->hdr.msgtype = msgtype;
new->hdr.msglen = htons (msglen);
new->hdr.msgseq = htonl (seqnum);
new->s = stream_new (msglen);
assert (new->s);
stream_put (new->s, msgbody, msglen);
return new;
}
|
CWE-119
| 3,573 | 13,553 |
82711549419008662863320132866748188257
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_print (struct msg *msg)
{
if (!msg)
{
zlog_debug ("msg_print msg=NULL!\n");
return;
}
#ifdef ORIGINAL_CODING
zlog_debug
("msg=%p msgtype=%d msglen=%d msgseq=%d streamdata=%p streamsize=%lu\n",
msg, msg->hdr.msgtype, ntohs (msg->hdr.msglen), ntohl (msg->hdr.msgseq),
STREAM_DATA (msg->s), STREAM_SIZE (msg->s));
#else /* ORIGINAL_CODING */
/* API message common header part. */
zlog_debug
("API-msg [%s]: type(%d),len(%d),seq(%lu),data(%p),size(%zd)",
ospf_api_typename (msg->hdr.msgtype), msg->hdr.msgtype,
ntohs (msg->hdr.msglen), (unsigned long) ntohl (msg->hdr.msgseq),
STREAM_DATA (msg->s), STREAM_SIZE (msg->s));
/* API message body part. */
#ifdef ndef
/* Generic Hex/Ascii dump */
DumpBuf (STREAM_DATA (msg->s), STREAM_SIZE (msg->s)); /* Sorry, deleted! */
#else /* ndef */
/* Message-type dependent dump function. */
#endif /* ndef */
return;
#endif /* ORIGINAL_CODING */
}
|
CWE-119
| 3,574 | 13,554 |
141677799278948595251678049788216929869
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_read (int fd)
{
struct msg *msg;
struct apimsghdr hdr;
u_char buf[OSPF_API_MAX_MSG_SIZE];
int bodylen;
int rlen;
/* Read message header */
rlen = readn (fd, (u_char *) &hdr, sizeof (struct apimsghdr));
if (rlen < 0)
{
zlog_warn ("msg_read: readn %s", safe_strerror (errno));
return NULL;
}
else if (rlen == 0)
{
zlog_warn ("msg_read: Connection closed by peer");
return NULL;
}
else if (rlen != sizeof (struct apimsghdr))
{
zlog_warn ("msg_read: Cannot read message header!");
return NULL;
}
/* Check version of API protocol */
if (hdr.version != OSPF_API_VERSION)
{
zlog_warn ("msg_read: OSPF API protocol version mismatch");
return NULL;
}
/* Determine body length. */
bodylen = ntohs (hdr.msglen);
if (bodylen > 0)
{
/* Read message body */
rlen = readn (fd, buf, bodylen);
if (rlen < 0)
{
zlog_warn ("msg_read: readn %s", safe_strerror (errno));
return NULL;
}
else if (rlen == 0)
{
zlog_warn ("msg_read: Connection closed by peer");
return NULL;
}
else if (rlen != bodylen)
{
zlog_warn ("msg_read: Cannot read message body!");
return NULL;
}
}
/* Allocate new message */
msg = msg_new (hdr.msgtype, buf, ntohl (hdr.msgseq), ntohs (hdr.msglen));
return msg;
}
|
CWE-119
| 3,575 | 13,555 |
291553876229684957018602172387546411100
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_set_seq (struct msg *msg, u_int32_t seqnr)
{
assert (msg);
msg->hdr.msgseq = htonl (seqnr);
}
|
CWE-119
| 3,576 | 13,556 |
110809287690485783175508099757713227071
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
msg_write (int fd, struct msg *msg)
{
u_char buf[OSPF_API_MAX_MSG_SIZE];
int l;
int wlen;
assert (msg);
assert (msg->s);
/* Length of message including header */
l = sizeof (struct apimsghdr) + ntohs (msg->hdr.msglen);
/* Make contiguous memory buffer for message */
memcpy (buf, &msg->hdr, sizeof (struct apimsghdr));
memcpy (buf + sizeof (struct apimsghdr), STREAM_DATA (msg->s),
ntohs (msg->hdr.msglen));
wlen = writen (fd, buf, l);
if (wlen < 0)
{
zlog_warn ("msg_write: writen %s", safe_strerror (errno));
return -1;
}
else if (wlen == 0)
{
zlog_warn ("msg_write: Connection closed by peer");
return -1;
}
else if (wlen != l)
{
zlog_warn ("msg_write: Cannot write API message");
return -1;
}
return 0;
}
|
CWE-119
| 3,577 | 13,557 |
332616913869967959835949427241725015601
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
new_msg_register_opaque_type (u_int32_t seqnum, u_char ltype, u_char otype)
{
struct msg_register_opaque_type rmsg;
rmsg.lsatype = ltype;
rmsg.opaquetype = otype;
memset (&rmsg.pad, 0, sizeof (rmsg.pad));
return msg_new (MSG_REGISTER_OPAQUETYPE, &rmsg, seqnum,
sizeof (struct msg_register_opaque_type));
}
|
CWE-119
| 3,578 | 13,558 |
135726875398627101281892862630014644808
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
ospf_api_errname (int errcode)
{
struct nametab NameTab[] = {
{ OSPF_API_OK, "OK", },
{ OSPF_API_NOSUCHINTERFACE, "No such interface", },
{ OSPF_API_NOSUCHAREA, "No such area", },
{ OSPF_API_NOSUCHLSA, "No such LSA", },
{ OSPF_API_ILLEGALLSATYPE, "Illegal LSA type", },
{ OSPF_API_OPAQUETYPEINUSE, "Opaque type in use", },
{ OSPF_API_OPAQUETYPENOTREGISTERED, "Opaque type not registered", },
{ OSPF_API_NOTREADY, "Not ready", },
{ OSPF_API_NOMEMORY, "No memory", },
{ OSPF_API_ERROR, "Other error", },
{ OSPF_API_UNDEF, "Undefined", },
};
int i, n = array_size(NameTab);
const char *name = NULL;
for (i = 0; i < n; i++)
{
if (NameTab[i].value == errcode)
{
name = NameTab[i].name;
break;
}
}
return name ? name : "?";
}
|
CWE-119
| 3,579 | 13,559 |
151591803687641253710993486028147136568
| null | null | null |
savannah
|
3f872fe60463a931c5c766dbf8c36870c0023e88
| 0 |
ospf_api_typename (int msgtype)
{
struct nametab NameTab[] = {
{ MSG_REGISTER_OPAQUETYPE, "Register opaque-type", },
{ MSG_UNREGISTER_OPAQUETYPE, "Unregister opaque-type", },
{ MSG_REGISTER_EVENT, "Register event", },
{ MSG_SYNC_LSDB, "Sync LSDB", },
{ MSG_ORIGINATE_REQUEST, "Originate request", },
{ MSG_DELETE_REQUEST, "Delete request", },
{ MSG_REPLY, "Reply", },
{ MSG_READY_NOTIFY, "Ready notify", },
{ MSG_LSA_UPDATE_NOTIFY, "LSA update notify", },
{ MSG_LSA_DELETE_NOTIFY, "LSA delete notify", },
{ MSG_NEW_IF, "New interface", },
{ MSG_DEL_IF, "Del interface", },
{ MSG_ISM_CHANGE, "ISM change", },
{ MSG_NSM_CHANGE, "NSM change", },
};
int i, n = array_size(NameTab);
const char *name = NULL;
for (i = 0; i < n; i++)
{
if (NameTab[i].value == msgtype)
{
name = NameTab[i].name;
break;
}
}
return name ? name : "?";
}
|
CWE-119
| 3,580 | 13,560 |
110936867630387802119408358182431298221
| null | null | null |
openssl
|
3c66a669dfc7b3792f7af0758ea26fe8502ce70c
| 0 |
static int ca_dn_cmp(const X509_NAME *const *a, const X509_NAME *const *b)
{
return (X509_NAME_cmp(*a, *b));
}
|
CWE-362
| 3,581 | 13,561 |
84039795952708792758535345324035143783
| null | null | null |
openssl
|
3c66a669dfc7b3792f7af0758ea26fe8502ce70c
| 0 |
static DH *get_server_static_dh_key(SESS_CERT *scert)
{
DH *dh_srvr = NULL;
EVP_PKEY *spkey = NULL;
int idx = scert->peer_cert_type;
if (idx >= 0)
spkey = X509_get_pubkey(scert->peer_pkeys[idx].x509);
if (spkey) {
dh_srvr = EVP_PKEY_get1_DH(spkey);
EVP_PKEY_free(spkey);
}
if (dh_srvr == NULL)
SSLerr(SSL_F_GET_SERVER_STATIC_DH_KEY, ERR_R_INTERNAL_ERROR);
return dh_srvr;
}
|
CWE-362
| 3,582 | 13,562 |
185299895901166035978696433527145482612
| null | null | null |
openssl
|
3c66a669dfc7b3792f7af0758ea26fe8502ce70c
| 0 |
int ssl3_check_cert_and_algorithm(SSL *s)
{
int i, idx;
long alg_k, alg_a;
EVP_PKEY *pkey = NULL;
int pkey_bits;
SESS_CERT *sc;
#ifndef OPENSSL_NO_RSA
RSA *rsa;
#endif
#ifndef OPENSSL_NO_DH
DH *dh;
#endif
int al = SSL_AD_HANDSHAKE_FAILURE;
alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
alg_a = s->s3->tmp.new_cipher->algorithm_auth;
/* we don't have a certificate */
if ((alg_a & (SSL_aNULL | SSL_aKRB5)) || (alg_k & SSL_kPSK))
return (1);
sc = s->session->sess_cert;
if (sc == NULL) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);
goto err;
}
#ifndef OPENSSL_NO_RSA
rsa = s->session->sess_cert->peer_rsa_tmp;
#endif
#ifndef OPENSSL_NO_DH
dh = s->session->sess_cert->peer_dh_tmp;
#endif
/* This is the passed certificate */
idx = sc->peer_cert_type;
#ifndef OPENSSL_NO_ECDH
if (idx == SSL_PKEY_ECC) {
if (ssl_check_srvr_ecc_cert_and_alg(sc->peer_pkeys[idx].x509, s) == 0) {
/* check failed */
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_BAD_ECC_CERT);
goto f_err;
} else {
return 1;
}
} else if (alg_a & SSL_aECDSA) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_ECDSA_SIGNING_CERT);
goto f_err;
} else if (alg_k & (SSL_kECDHr | SSL_kECDHe)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_MISSING_ECDH_CERT);
goto f_err;
}
#endif
pkey = X509_get_pubkey(sc->peer_pkeys[idx].x509);
pkey_bits = EVP_PKEY_bits(pkey);
i = X509_certificate_type(sc->peer_pkeys[idx].x509, pkey);
EVP_PKEY_free(pkey);
/* Check that we have a certificate if we require one */
if ((alg_a & SSL_aRSA) && !has_bits(i, EVP_PK_RSA | EVP_PKT_SIGN)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_RSA_SIGNING_CERT);
goto f_err;
}
#ifndef OPENSSL_NO_DSA
else if ((alg_a & SSL_aDSS) && !has_bits(i, EVP_PK_DSA | EVP_PKT_SIGN)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_DSA_SIGNING_CERT);
goto f_err;
}
#endif
#ifndef OPENSSL_NO_RSA
if (alg_k & SSL_kRSA) {
if (!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&
!has_bits(i, EVP_PK_RSA | EVP_PKT_ENC)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_RSA_ENCRYPTING_CERT);
goto f_err;
} else if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)) {
if (pkey_bits <= SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) {
if (!has_bits(i, EVP_PK_RSA | EVP_PKT_ENC)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_RSA_ENCRYPTING_CERT);
goto f_err;
}
if (rsa != NULL) {
/* server key exchange is not allowed. */
al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);
goto f_err;
}
}
}
}
#endif
#ifndef OPENSSL_NO_DH
if ((alg_k & SSL_kEDH) && dh == NULL) {
al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);
goto f_err;
}
if ((alg_k & SSL_kDHr) && !SSL_USE_SIGALGS(s) &&
!has_bits(i, EVP_PK_DH | EVP_PKS_RSA)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_DH_RSA_CERT);
goto f_err;
}
# ifndef OPENSSL_NO_DSA
if ((alg_k & SSL_kDHd) && !SSL_USE_SIGALGS(s) &&
!has_bits(i, EVP_PK_DH | EVP_PKS_DSA)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_DH_DSA_CERT);
goto f_err;
}
# endif
if (alg_k & (SSL_kDHE | SSL_kDHr | SSL_kDHd)) {
int dh_size;
if (alg_k & SSL_kDHE) {
dh_size = BN_num_bits(dh->p);
} else {
DH *dh_srvr = get_server_static_dh_key(sc);
if (dh_srvr == NULL)
goto f_err;
dh_size = BN_num_bits(dh_srvr->p);
DH_free(dh_srvr);
}
if ((!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 768)
|| (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && dh_size < 512)) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, SSL_R_DH_KEY_TOO_SMALL);
goto f_err;
}
}
#endif /* !OPENSSL_NO_DH */
if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&
pkey_bits > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) {
#ifndef OPENSSL_NO_RSA
if (alg_k & SSL_kRSA) {
if (rsa == NULL) {
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
goto f_err;
} else if (BN_num_bits(rsa->n) >
SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) {
/* We have a temporary RSA key but it's too large. */
al = SSL_AD_EXPORT_RESTRICTION;
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
goto f_err;
}
} else
#endif
#ifndef OPENSSL_NO_DH
if (alg_k & SSL_kDHE) {
if (BN_num_bits(dh->p) >
SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) {
/* We have a temporary DH key but it's too large. */
al = SSL_AD_EXPORT_RESTRICTION;
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_EXPORT_TMP_DH_KEY);
goto f_err;
}
} else if (alg_k & (SSL_kDHr | SSL_kDHd)) {
/* The cert should have had an export DH key. */
al = SSL_AD_EXPORT_RESTRICTION;
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_MISSING_EXPORT_TMP_DH_KEY);
goto f_err;
} else
#endif
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
goto f_err;
}
}
return (1);
f_err:
ssl3_send_alert(s, SSL3_AL_FATAL, al);
err:
return (0);
}
|
CWE-362
| 3,583 | 13,563 |
105175890379637459515375336470149610523
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.