idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
2,500
static int septransform(i_ctx_t *i_ctx_p, ref *sepspace, int *usealternate, int *stage, int *stack_depth) { gx_device * dev = igs->device; ref sname, proc; int code, colorant_number; code = array_get(imemory, sepspace, 1, &sname); if (code < 0) return code; if (r_has_type(&sname, t_name)) { name_string_ref(imemory, &sname, &sname); } /* Check for /All and /None, never need the alternate for these */ if (r_size(&sname) == 3 && strncmp("All", (const char *)sname.value.bytes, r_size(&sname)) == 0) { *usealternate = 0; return 0; } if (r_size(&sname) == 4 && strncmp("None", (const char *)sname.value.bytes, r_size(&sname)) == 0) { *usealternate = 0; return 0; } /* * Compare the colorant name to the device's. If the device's * compare routine returns GX_DEVICE_COLOR_MAX_COMPONENTS then the * colorant is in the SeparationNames list but not in the * SeparationOrder list. */ colorant_number = (*dev_proc(dev, get_color_comp_index)) (dev, (const char *)sname.value.bytes, r_size(&sname), SEPARATION_NAME); if (colorant_number >= 0) { /* If valid colorant name */ *usealternate = 0; } else *usealternate = 1; if (*usealternate && *stage == 0) { (*stage)++; esp++; code = array_get(imemory, sepspace, 3, &proc); if (code < 0) return code; *esp = proc; return o_push_estack; } *stage = 0; return 0; }
null
0
static int septransform(i_ctx_t *i_ctx_p, ref *sepspace, int *usealternate, int *stage, int *stack_depth) { gx_device * dev = igs->device; ref sname, proc; int code, colorant_number; code = array_get(imemory, sepspace, 1, &sname); if (code < 0) return code; if (r_has_type(&sname, t_name)) { name_string_ref(imemory, &sname, &sname); } /* Check for /All and /None, never need the alternate for these */ if (r_size(&sname) == 3 && strncmp("All", (const char *)sname.value.bytes, r_size(&sname)) == 0) { *usealternate = 0; return 0; } if (r_size(&sname) == 4 && strncmp("None", (const char *)sname.value.bytes, r_size(&sname)) == 0) { *usealternate = 0; return 0; } /* * Compare the colorant name to the device's. If the device's * compare routine returns GX_DEVICE_COLOR_MAX_COMPONENTS then the * colorant is in the SeparationNames list but not in the * SeparationOrder list. */ colorant_number = (*dev_proc(dev, get_color_comp_index)) (dev, (const char *)sname.value.bytes, r_size(&sname), SEPARATION_NAME); if (colorant_number >= 0) { /* If valid colorant name */ *usealternate = 0; } else *usealternate = 1; if (*usealternate && *stage == 0) { (*stage)++; esp++; code = array_get(imemory, sepspace, 3, &proc); if (code < 0) return code; *esp = proc; return o_push_estack; } *stage = 0; return 0; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,501
static int sepvalidate(i_ctx_t *i_ctx_p, ref *space, float *values, int num_comps) { os_ptr op = osp; if (num_comps < 1) return_error(gs_error_stackunderflow); if (!r_has_type(op, t_integer) && !r_has_type(op, t_real)) return_error(gs_error_typecheck); if (*values > 1.0) *values = 1.0; if (*values < 0.0) *values = 0.0; return 0; }
null
0
static int sepvalidate(i_ctx_t *i_ctx_p, ref *space, float *values, int num_comps) { os_ptr op = osp; if (num_comps < 1) return_error(gs_error_stackunderflow); if (!r_has_type(op, t_integer) && !r_has_type(op, t_real)) return_error(gs_error_typecheck); if (*values > 1.0) *values = 1.0; if (*values < 0.0) *values = 0.0; return 0; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,502
static int setcalgrayspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { ref graydict; int code = 0; float gamma, white[3], black[3]; double dflt_gamma = 1.0; static const float dflt_black[3] = {0,0,0}, dflt_white[3] = {0,0,0}; gs_client_color cc; *cont = 0; code = array_get(imemory, r, 1, &graydict); if (code < 0) return code; /* Get all the parts */ code = dict_float_param(&graydict, "Gamma", dflt_gamma, &gamma); if (code < 0) return code; if (gamma <= 0 ) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &graydict, "BlackPoint", 3, black, dflt_black ); if (code < 0) return code; code = dict_floats_param( imemory, &graydict, "WhitePoint", 3, white, dflt_white ); if (code < 0) return code; if (white[0] <= 0 || white[1] != 1.0 || white[2] <= 0) return_error(gs_error_rangecheck); code = seticc_cal(i_ctx_p, white, black, &gamma, NULL, 1, graydict.value.saveid); if ( code < 0) return gs_rethrow(code, "setting CalGray color space"); cc.pattern = 0x00; cc.paint.values[0] = 0; code = gs_setcolor(igs, &cc); return code; }
null
0
static int setcalgrayspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { ref graydict; int code = 0; float gamma, white[3], black[3]; double dflt_gamma = 1.0; static const float dflt_black[3] = {0,0,0}, dflt_white[3] = {0,0,0}; gs_client_color cc; *cont = 0; code = array_get(imemory, r, 1, &graydict); if (code < 0) return code; /* Get all the parts */ code = dict_float_param(&graydict, "Gamma", dflt_gamma, &gamma); if (code < 0) return code; if (gamma <= 0 ) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &graydict, "BlackPoint", 3, black, dflt_black ); if (code < 0) return code; code = dict_floats_param( imemory, &graydict, "WhitePoint", 3, white, dflt_white ); if (code < 0) return code; if (white[0] <= 0 || white[1] != 1.0 || white[2] <= 0) return_error(gs_error_rangecheck); code = seticc_cal(i_ctx_p, white, black, &gamma, NULL, 1, graydict.value.saveid); if ( code < 0) return gs_rethrow(code, "setting CalGray color space"); cc.pattern = 0x00; cc.paint.values[0] = 0; code = gs_setcolor(igs, &cc); return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,503
static int setcalrgbspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { ref rgbdict; int code = 0; float gamma[3], white[3], black[3], matrix[9]; static const float dflt_gamma[3] = { 1.0, 1.0, 1.0 }; static const float dflt_black[3] = {0,0,0}, dflt_white[3] = {0,0,0}; static const float dflt_matrix[9] = {1,0,0,0,1,0,0,0,1}; int i; gs_client_color cc; *cont = 0; code = array_get(imemory, r, 1, &rgbdict); if (code < 0) return code; /* Get all the parts */ code = dict_floats_param( imemory, &rgbdict, "Gamma", 3, gamma, dflt_gamma ); if (code < 0) return code; if (gamma[0] <= 0 || gamma[1] <= 0 || gamma[2] <= 0) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &rgbdict, "BlackPoint", 3, black, dflt_black ); if (code < 0) return code; code = dict_floats_param( imemory, &rgbdict, "WhitePoint", 3, white, dflt_white ); if (code < 0) return code; if (white[0] <= 0 || white[1] != 1.0 || white[2] <= 0) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &rgbdict, "Matrix", 9, matrix, dflt_matrix ); if (code < 0) return code; code = seticc_cal(i_ctx_p, white, black, gamma, matrix, 3, rgbdict.value.saveid); if ( code < 0) return gs_rethrow(code, "setting CalRGB color space"); cc.pattern = 0x00; for (i=0;i<3;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); return code; }
null
0
static int setcalrgbspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { ref rgbdict; int code = 0; float gamma[3], white[3], black[3], matrix[9]; static const float dflt_gamma[3] = { 1.0, 1.0, 1.0 }; static const float dflt_black[3] = {0,0,0}, dflt_white[3] = {0,0,0}; static const float dflt_matrix[9] = {1,0,0,0,1,0,0,0,1}; int i; gs_client_color cc; *cont = 0; code = array_get(imemory, r, 1, &rgbdict); if (code < 0) return code; /* Get all the parts */ code = dict_floats_param( imemory, &rgbdict, "Gamma", 3, gamma, dflt_gamma ); if (code < 0) return code; if (gamma[0] <= 0 || gamma[1] <= 0 || gamma[2] <= 0) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &rgbdict, "BlackPoint", 3, black, dflt_black ); if (code < 0) return code; code = dict_floats_param( imemory, &rgbdict, "WhitePoint", 3, white, dflt_white ); if (code < 0) return code; if (white[0] <= 0 || white[1] != 1.0 || white[2] <= 0) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &rgbdict, "Matrix", 9, matrix, dflt_matrix ); if (code < 0) return code; code = seticc_cal(i_ctx_p, white, black, gamma, matrix, 3, rgbdict.value.saveid); if ( code < 0) return gs_rethrow(code, "setting CalRGB color space"); cc.pattern = 0x00; for (i=0;i<3;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,504
static int setcieaspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { int code = 0; ref CIEDict, *nocie; ulong dictkey; gs_md5_state_t md5; byte key[16]; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); if (nocie->value.boolval) return setgrayspace(i_ctx_p, r, stage, cont, 1); } *cont = 0; code = array_get(imemory, r, 1, &CIEDict); if (code < 0) return code; if ((*stage) > 0) { gs_client_color cc; cc.pattern = 0x00; cc.paint.values[0] = 0; code = gs_setcolor(igs, &cc); *stage = 0; return code; } gs_md5_init(&md5); /* If the hash (dictkey) is 0, we don't check for an existing * ICC profile dor this space. So if we get an error hashing * the space, we construct a new profile. */ dictkey = 0; if (hashcieaspace(i_ctx_p, r, &md5)) { /* Ideally we would use the whole md5 hash, but the ICC code only * expects a long. I'm 'slightly' concerned about collisions here * but I think its unlikely really. If it ever becomes a problem * we could add the hash bytes up, or modify the ICC cache to store * the full 16 byte hashs. */ gs_md5_finish(&md5, key); dictkey = *(ulong *)&key[sizeof(key) - sizeof(ulong)]; } else { gs_md5_finish(&md5, key); } code = cieaspace(i_ctx_p, &CIEDict, dictkey); (*stage)++; *cont = 1; return code; }
null
0
static int setcieaspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { int code = 0; ref CIEDict, *nocie; ulong dictkey; gs_md5_state_t md5; byte key[16]; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); if (nocie->value.boolval) return setgrayspace(i_ctx_p, r, stage, cont, 1); } *cont = 0; code = array_get(imemory, r, 1, &CIEDict); if (code < 0) return code; if ((*stage) > 0) { gs_client_color cc; cc.pattern = 0x00; cc.paint.values[0] = 0; code = gs_setcolor(igs, &cc); *stage = 0; return code; } gs_md5_init(&md5); /* If the hash (dictkey) is 0, we don't check for an existing * ICC profile dor this space. So if we get an error hashing * the space, we construct a new profile. */ dictkey = 0; if (hashcieaspace(i_ctx_p, r, &md5)) { /* Ideally we would use the whole md5 hash, but the ICC code only * expects a long. I'm 'slightly' concerned about collisions here * but I think its unlikely really. If it ever becomes a problem * we could add the hash bytes up, or modify the ICC cache to store * the full 16 byte hashs. */ gs_md5_finish(&md5, key); dictkey = *(ulong *)&key[sizeof(key) - sizeof(ulong)]; } else { gs_md5_finish(&md5, key); } code = cieaspace(i_ctx_p, &CIEDict, dictkey); (*stage)++; *cont = 1; return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,505
static int setciedefgspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { int code = 0; ref CIEDict, *nocie; ulong dictkey; gs_md5_state_t md5; byte key[16]; if (i_ctx_p->language_level < 3) return_error(gs_error_undefined); code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); if (nocie->value.boolval) return setcmykspace(i_ctx_p, r, stage, cont, 1); } *cont = 0; code = array_get(imemory, r, 1, &CIEDict); if (code < 0) return code; if ((*stage) > 0) { gs_client_color cc; int i; cc.pattern = 0x00; for (i=0;i<4;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); *stage = 0; return code; } gs_md5_init(&md5); /* If the hash (dictkey) is 0, we don't check for an existing * ICC profile dor this space. So if we get an error hashing * the space, we construct a new profile. */ dictkey = 0; if (hashciedefgspace(i_ctx_p, r, &md5)) { /* Ideally we would use the whole md5 hash, but the ICC code only * expects a long. I'm 'slightly' concerned about collisions here * but I think its unlikely really. If it ever becomes a problem * we could add the hash bytes up, or modify the ICC cache to store * the full 16 byte hashs. */ gs_md5_finish(&md5, key); dictkey = *(ulong *)&key[sizeof(key) - sizeof(ulong)]; } else { gs_md5_finish(&md5, key); } code = ciedefgspace(i_ctx_p, &CIEDict,dictkey); *cont = 1; (*stage)++; return code; }
null
0
static int setciedefgspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { int code = 0; ref CIEDict, *nocie; ulong dictkey; gs_md5_state_t md5; byte key[16]; if (i_ctx_p->language_level < 3) return_error(gs_error_undefined); code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); if (nocie->value.boolval) return setcmykspace(i_ctx_p, r, stage, cont, 1); } *cont = 0; code = array_get(imemory, r, 1, &CIEDict); if (code < 0) return code; if ((*stage) > 0) { gs_client_color cc; int i; cc.pattern = 0x00; for (i=0;i<4;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); *stage = 0; return code; } gs_md5_init(&md5); /* If the hash (dictkey) is 0, we don't check for an existing * ICC profile dor this space. So if we get an error hashing * the space, we construct a new profile. */ dictkey = 0; if (hashciedefgspace(i_ctx_p, r, &md5)) { /* Ideally we would use the whole md5 hash, but the ICC code only * expects a long. I'm 'slightly' concerned about collisions here * but I think its unlikely really. If it ever becomes a problem * we could add the hash bytes up, or modify the ICC cache to store * the full 16 byte hashs. */ gs_md5_finish(&md5, key); dictkey = *(ulong *)&key[sizeof(key) - sizeof(ulong)]; } else { gs_md5_finish(&md5, key); } code = ciedefgspace(i_ctx_p, &CIEDict,dictkey); *cont = 1; (*stage)++; return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,506
static int setciedefspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { int code = 0; ref CIEDict, *nocie; ulong dictkey; gs_md5_state_t md5; byte key[16]; if (i_ctx_p->language_level < 3) return_error(gs_error_undefined); code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); if (nocie->value.boolval) return setrgbspace(i_ctx_p, r, stage, cont, 1); } *cont = 0; code = array_get(imemory, r, 1, &CIEDict); if (code < 0) return code; if ((*stage) > 0) { gs_client_color cc; int i; cc.pattern = 0x00; for (i=0;i<3;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); *stage = 0; return code; } gs_md5_init(&md5); /* If the hash (dictkey) is 0, we don't check for an existing * ICC profile dor this space. So if we get an error hashing * the space, we construct a new profile. */ dictkey = 0; if (hashciedefspace(i_ctx_p, r, &md5)) { /* Ideally we would use the whole md5 hash, but the ICC code only * expects a long. I'm 'slightly' concerned about collisions here * but I think its unlikely really. If it ever becomes a problem * we could add the hash bytes up, or modify the ICC cache to store * the full 16 byte hashs. */ gs_md5_finish(&md5, key); dictkey = *(ulong *)&key[sizeof(key) - sizeof(ulong)]; } else { gs_md5_finish(&md5, key); } code = ciedefspace(i_ctx_p, &CIEDict, dictkey); *cont = 1; (*stage)++; return code; }
null
0
static int setciedefspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { int code = 0; ref CIEDict, *nocie; ulong dictkey; gs_md5_state_t md5; byte key[16]; if (i_ctx_p->language_level < 3) return_error(gs_error_undefined); code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); if (nocie->value.boolval) return setrgbspace(i_ctx_p, r, stage, cont, 1); } *cont = 0; code = array_get(imemory, r, 1, &CIEDict); if (code < 0) return code; if ((*stage) > 0) { gs_client_color cc; int i; cc.pattern = 0x00; for (i=0;i<3;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); *stage = 0; return code; } gs_md5_init(&md5); /* If the hash (dictkey) is 0, we don't check for an existing * ICC profile dor this space. So if we get an error hashing * the space, we construct a new profile. */ dictkey = 0; if (hashciedefspace(i_ctx_p, r, &md5)) { /* Ideally we would use the whole md5 hash, but the ICC code only * expects a long. I'm 'slightly' concerned about collisions here * but I think its unlikely really. If it ever becomes a problem * we could add the hash bytes up, or modify the ICC cache to store * the full 16 byte hashs. */ gs_md5_finish(&md5, key); dictkey = *(ulong *)&key[sizeof(key) - sizeof(ulong)]; } else { gs_md5_finish(&md5, key); } code = ciedefspace(i_ctx_p, &CIEDict, dictkey); *cont = 1; (*stage)++; return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,507
setcolor_cont(i_ctx_t *i_ctx_p) { ref arr, *parr = &arr; es_ptr ep = esp; int i=0, code = 0, usealternate, stage, stack_depth, CIESubst = 0, IsICC = 0; unsigned int depth; PS_colour_space_t *obj; stack_depth = (int)ep[-3].value.intval; depth = (unsigned int)ep[-2].value.intval; stage = (int)ep[-1].value.intval; /* If we get a continuation from a sub-procedure, we will want to come back * here afterward, to do any remaining spaces. We need to set up for that now. * so that our continuation is ahead of the sub-proc's continuation. */ check_estack(1); push_op_estack(setcolor_cont); while (code == 0) { ref_assign(&arr, ep); /* Run along the nested color spaces until we get to the first one * that we haven't yet processed (given by 'depth') */ for (i=0;i<=depth;i++) { code = get_space_object(i_ctx_p, parr, &obj); if (code < 0) return code; if (strcmp(obj->name, "ICCBased") == 0) IsICC = 1; if (i < (depth)) { if (!obj->alternateproc) { return_error(gs_error_typecheck); } code = obj->alternateproc(i_ctx_p, parr, &parr, &CIESubst); if (code < 0) return code; } } if (obj->runtransformproc) { code = obj->runtransformproc(i_ctx_p, &istate->colorspace[0].array, &usealternate, &stage, &stack_depth); make_int(&ep[-3], stack_depth); make_int(&ep[-1], stage); if (code != 0) { return code; } make_int(&ep[-2], ++depth); if (!usealternate) break; } else break; } /* Hack to work around broken PDF files in Bug696690 and Bug696120 * We want setcolor to actually exercise the link creation in case * the profile is broken, in whcih case we may choose to use a different * colour space altogether. */ if (IsICC && depth == 0) { code = gx_set_dev_color(i_ctx_p->pgs); if (code < 0) return code; } /* Remove our next continuation and our data */ obj->numcomponents(i_ctx_p, parr, &i); pop(i); esp -= 5; return o_pop_estack; }
null
0
setcolor_cont(i_ctx_t *i_ctx_p) { ref arr, *parr = &arr; es_ptr ep = esp; int i=0, code = 0, usealternate, stage, stack_depth, CIESubst = 0, IsICC = 0; unsigned int depth; PS_colour_space_t *obj; stack_depth = (int)ep[-3].value.intval; depth = (unsigned int)ep[-2].value.intval; stage = (int)ep[-1].value.intval; /* If we get a continuation from a sub-procedure, we will want to come back * here afterward, to do any remaining spaces. We need to set up for that now. * so that our continuation is ahead of the sub-proc's continuation. */ check_estack(1); push_op_estack(setcolor_cont); while (code == 0) { ref_assign(&arr, ep); /* Run along the nested color spaces until we get to the first one * that we haven't yet processed (given by 'depth') */ for (i=0;i<=depth;i++) { code = get_space_object(i_ctx_p, parr, &obj); if (code < 0) return code; if (strcmp(obj->name, "ICCBased") == 0) IsICC = 1; if (i < (depth)) { if (!obj->alternateproc) { return_error(gs_error_typecheck); } code = obj->alternateproc(i_ctx_p, parr, &parr, &CIESubst); if (code < 0) return code; } } if (obj->runtransformproc) { code = obj->runtransformproc(i_ctx_p, &istate->colorspace[0].array, &usealternate, &stage, &stack_depth); make_int(&ep[-3], stack_depth); make_int(&ep[-1], stage); if (code != 0) { return code; } make_int(&ep[-2], ++depth); if (!usealternate) break; } else break; } /* Hack to work around broken PDF files in Bug696690 and Bug696120 * We want setcolor to actually exercise the link creation in case * the profile is broken, in whcih case we may choose to use a different * colour space altogether. */ if (IsICC && depth == 0) { code = gx_set_dev_color(i_ctx_p->pgs); if (code < 0) return code; } /* Remove our next continuation and our data */ obj->numcomponents(i_ctx_p, parr, &i); pop(i); esp -= 5; return o_pop_estack; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,508
setcolorspace_cont(i_ctx_t *i_ctx_p) { ref arr, *parr = &arr; os_ptr op = osp; es_ptr ep = esp, pdepth, pstage, pCIESubst; int i, code = 0, stage, cont, CIESubst = 0; unsigned int depth; PS_colour_space_t *obj; pCIESubst = &ep[-3]; pdepth = &ep[-2]; pstage = &ep[-1]; CIESubst = (int)pCIESubst->value.intval; depth = (unsigned int)pdepth->value.intval; stage = (int)pstage->value.intval; /* If we get a continuation from a sub-procedure, we will want to come back * here afterward, to do any remaining stages. We need to set up for that now. * so that our continuation is ahead of the sub-proc's continuation. */ check_estack(1); push_op_estack(setcolorspace_cont); while (code == 0 && depth) { ref_assign(&arr, ep); /* Run along the nested color spaces until we get to the lowest one * that we haven't yet processed (given by 'depth') */ for (i = 0;i < depth;i++) { code = get_space_object(i_ctx_p, parr, &obj); if (code < 0) return code; if (i < (depth - 1)) { if (!obj->alternateproc) { return_error(gs_error_typecheck); } code = obj->alternateproc(i_ctx_p, parr, &parr, &CIESubst); if (code < 0) return code; } } code = obj->setproc(i_ctx_p, parr, &stage, &cont, CIESubst); make_int(pstage, stage); if (code != 0) { if (code < 0 && code != gs_error_stackoverflow) esp -= 5; return code; } if (!cont) { /* Completed that space, decrement the 'depth' */ make_int(pdepth, --depth); parr = &arr; } } if (code == 0) { /* Remove our next continuation and our data */ esp -= 5; op = osp; istate->colorspace[0].array = *op; /* Remove the colorspace array form the operand stack */ pop(1); code = o_pop_estack; } return code; }
null
0
setcolorspace_cont(i_ctx_t *i_ctx_p) { ref arr, *parr = &arr; os_ptr op = osp; es_ptr ep = esp, pdepth, pstage, pCIESubst; int i, code = 0, stage, cont, CIESubst = 0; unsigned int depth; PS_colour_space_t *obj; pCIESubst = &ep[-3]; pdepth = &ep[-2]; pstage = &ep[-1]; CIESubst = (int)pCIESubst->value.intval; depth = (unsigned int)pdepth->value.intval; stage = (int)pstage->value.intval; /* If we get a continuation from a sub-procedure, we will want to come back * here afterward, to do any remaining stages. We need to set up for that now. * so that our continuation is ahead of the sub-proc's continuation. */ check_estack(1); push_op_estack(setcolorspace_cont); while (code == 0 && depth) { ref_assign(&arr, ep); /* Run along the nested color spaces until we get to the lowest one * that we haven't yet processed (given by 'depth') */ for (i = 0;i < depth;i++) { code = get_space_object(i_ctx_p, parr, &obj); if (code < 0) return code; if (i < (depth - 1)) { if (!obj->alternateproc) { return_error(gs_error_typecheck); } code = obj->alternateproc(i_ctx_p, parr, &parr, &CIESubst); if (code < 0) return code; } } code = obj->setproc(i_ctx_p, parr, &stage, &cont, CIESubst); make_int(pstage, stage); if (code != 0) { if (code < 0 && code != gs_error_stackoverflow) esp -= 5; return code; } if (!cont) { /* Completed that space, decrement the 'depth' */ make_int(pdepth, --depth); parr = &arr; } } if (code == 0) { /* Remove our next continuation and our data */ esp -= 5; op = osp; istate->colorspace[0].array = *op; /* Remove the colorspace array form the operand stack */ pop(1); code = o_pop_estack; } return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,509
setcolorspace_nosubst(i_ctx_t * i_ctx_p) { os_ptr op = osp; es_ptr ep; int code, depth; /* 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; /* 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 (substituting) */ ep = esp += 1; make_int(ep, 1); /* 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; }
null
0
setcolorspace_nosubst(i_ctx_t * i_ctx_p) { os_ptr op = osp; es_ptr ep; int code, depth; /* 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; /* 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 (substituting) */ ep = esp += 1; make_int(ep, 1); /* 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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,510
static int setdevicenspace(i_ctx_t * i_ctx_p, ref *devicenspace, int *stage, int *cont, int CIESubst) { os_ptr op = osp; /* required by "push" macro */ int code = 0, num_components, i; ref namesarray, proc, sname, tname, sref; ref_colorspace cspace_old; gs_color_space *pcs; gs_color_space * pacs; gs_function_t *pfn = NULL; gs_separation_name *names; gs_client_color cc; if (i_ctx_p->language_level < 3) return_error(gs_error_undefined); *cont = 0; if ((*stage) == 2) { if (r_size(devicenspace) == 5) { /* We have a Colorants dictionary from a PDF file. We need to handle this by * temporarily setting each of the spaces in the dict, and attaching the * resulting space to the DeviceN array. This is complicated, because * each space must be fully set up, and may result in running tint transform * procedures and caching results. We need to handle this in yet another * layering of continuation procedures. */ ref *colorants; code = array_get(imemory, devicenspace, 4, &sref); if (code < 0) return code; if (!r_has_type(&sref, t_dictionary)) { *stage = 0; return 0; } if (dict_find_string(&sref, "Colorants", &colorants) <= 0) { *stage = 0; return 0; } if (!r_has_type(colorants, t_dictionary)) { *stage = 0; return 0; } *stage = 3; *cont = 1; check_estack(5); push_mark_estack(es_other, colour_cleanup); esp++; /* variable to hold index of the space we are dealing with */ make_int(esp, dict_first(colorants)); esp++; /* variable to hold processing step */ make_int(esp, 0); esp++; /* Store a pointer to the Colorants dictionary */ ref_assign(esp, colorants); push_op_estack(devicencolorants_cont); return o_push_estack; } else { *stage = 0; return 0; } } if ((*stage) == 3) { *stage = 0; return 0; } if ((*stage) == 0) { code = array_get(imemory, devicenspace, 3, &proc); if (code < 0) return code; pfn = ref_function(&proc); if (pfn == NULL) { /* Convert tint transform to a PostScript function */ code = convert_transform(i_ctx_p, devicenspace, &proc); if (code < 0) return code; if (code > 0) { *cont = 1; *stage = 1; return code; } /* We can only get here if the transform converted to a function * without requiring a continuation. Most likely this means its a * type 4 function. If so then it is still on the stack. */ op = osp; pfn = ref_function(op); pop (1); } } else { /* The function is returned on the operand stack */ op = osp; pfn = ref_function(op); pop (1); } *stage = 2; code = array_get(imemory, devicenspace, 1, &namesarray); if (code < 0) return code; num_components = r_size(&namesarray); /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); if (num_components == 1) { array_get(imemory, &namesarray, (long)0, &sname); switch (r_type(&sname)) { case t_string: tname = sname; break; case t_name: name_string_ref(imemory, &sname, &tname); break; default: return_error(gs_error_typecheck); break; } if (strncmp((const char *)tname.value.const_bytes, "All", 3) == 0 && r_size(&tname) == 3) { separation_type sep_type; /* Sigh, Acrobat allows this, even though its contra the spec. Convert to * a /Separation space and go on */ sep_type = SEP_ALL; /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); cspace_old = istate->colorspace[0]; /* Now set the current color space as Separation */ code = gs_cspace_new_Separation(&pcs, pacs, imemory); if (code < 0) return code; pcs->params.separation.sep_type = sep_type; pcs->params.separation.sep_name = name_index(imemory, &sname); pcs->params.separation.get_colorname_string = gs_get_colorname_string; code = array_get(imemory, &namesarray, (long)0, &sname); if (code < 0) return code; istate->colorspace[0].procs.special.separation.layer_name = sname; code = array_get(imemory, devicenspace, 3, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.separation.tint_transform = proc; if (code >= 0) code = gs_cspace_set_sepr_function(pcs, pfn); if (code >= 0) code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setseparationspace"); if (code < 0) { istate->colorspace[0] = cspace_old; return code; } cc.pattern = 0x00; cc.paint.values[0] = 1.0; code = gs_setcolor(igs, &cc); return code; } } code = gs_cspace_new_DeviceN(&pcs, num_components, pacs, imemory); if (code < 0) return code; names = pcs->params.device_n.names; pcs->params.device_n.get_colorname_string = gs_get_colorname_string; /* Pick up the names of the components */ { uint i; ref sname; for (i = 0; i < num_components; ++i) { array_get(imemory, &namesarray, (long)i, &sname); switch (r_type(&sname)) { case t_string: code = name_from_string(imemory, &sname, &sname); if (code < 0) { rc_decrement_cs(pcs, "setdevicenspace"); return code; } /* falls through */ case t_name: names[i] = name_index(imemory, &sname); break; default: rc_decrement_cs(pcs, "setdevicenspace"); return_error(gs_error_typecheck); } } } /* Now set the current color space as DeviceN */ cspace_old = istate->colorspace[0]; istate->colorspace[0].procs.special.device_n.layer_names = namesarray; code = array_get(imemory, devicenspace, 3, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.device_n.tint_transform = proc; code = gs_cspace_set_devn_function(pcs, pfn); if (code < 0) { return code; } code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setdevicenspace"); if (code < 0) { istate->colorspace[0] = cspace_old; return code; } cc.pattern = 0x00; for (i=0;i<num_components;i++) cc.paint.values[i] = 1.0; code = gs_setcolor(igs, &cc); *cont = 1; return code; }
null
0
static int setdevicenspace(i_ctx_t * i_ctx_p, ref *devicenspace, int *stage, int *cont, int CIESubst) { os_ptr op = osp; /* required by "push" macro */ int code = 0, num_components, i; ref namesarray, proc, sname, tname, sref; ref_colorspace cspace_old; gs_color_space *pcs; gs_color_space * pacs; gs_function_t *pfn = NULL; gs_separation_name *names; gs_client_color cc; if (i_ctx_p->language_level < 3) return_error(gs_error_undefined); *cont = 0; if ((*stage) == 2) { if (r_size(devicenspace) == 5) { /* We have a Colorants dictionary from a PDF file. We need to handle this by * temporarily setting each of the spaces in the dict, and attaching the * resulting space to the DeviceN array. This is complicated, because * each space must be fully set up, and may result in running tint transform * procedures and caching results. We need to handle this in yet another * layering of continuation procedures. */ ref *colorants; code = array_get(imemory, devicenspace, 4, &sref); if (code < 0) return code; if (!r_has_type(&sref, t_dictionary)) { *stage = 0; return 0; } if (dict_find_string(&sref, "Colorants", &colorants) <= 0) { *stage = 0; return 0; } if (!r_has_type(colorants, t_dictionary)) { *stage = 0; return 0; } *stage = 3; *cont = 1; check_estack(5); push_mark_estack(es_other, colour_cleanup); esp++; /* variable to hold index of the space we are dealing with */ make_int(esp, dict_first(colorants)); esp++; /* variable to hold processing step */ make_int(esp, 0); esp++; /* Store a pointer to the Colorants dictionary */ ref_assign(esp, colorants); push_op_estack(devicencolorants_cont); return o_push_estack; } else { *stage = 0; return 0; } } if ((*stage) == 3) { *stage = 0; return 0; } if ((*stage) == 0) { code = array_get(imemory, devicenspace, 3, &proc); if (code < 0) return code; pfn = ref_function(&proc); if (pfn == NULL) { /* Convert tint transform to a PostScript function */ code = convert_transform(i_ctx_p, devicenspace, &proc); if (code < 0) return code; if (code > 0) { *cont = 1; *stage = 1; return code; } /* We can only get here if the transform converted to a function * without requiring a continuation. Most likely this means its a * type 4 function. If so then it is still on the stack. */ op = osp; pfn = ref_function(op); pop (1); } } else { /* The function is returned on the operand stack */ op = osp; pfn = ref_function(op); pop (1); } *stage = 2; code = array_get(imemory, devicenspace, 1, &namesarray); if (code < 0) return code; num_components = r_size(&namesarray); /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); if (num_components == 1) { array_get(imemory, &namesarray, (long)0, &sname); switch (r_type(&sname)) { case t_string: tname = sname; break; case t_name: name_string_ref(imemory, &sname, &tname); break; default: return_error(gs_error_typecheck); break; } if (strncmp((const char *)tname.value.const_bytes, "All", 3) == 0 && r_size(&tname) == 3) { separation_type sep_type; /* Sigh, Acrobat allows this, even though its contra the spec. Convert to * a /Separation space and go on */ sep_type = SEP_ALL; /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); cspace_old = istate->colorspace[0]; /* Now set the current color space as Separation */ code = gs_cspace_new_Separation(&pcs, pacs, imemory); if (code < 0) return code; pcs->params.separation.sep_type = sep_type; pcs->params.separation.sep_name = name_index(imemory, &sname); pcs->params.separation.get_colorname_string = gs_get_colorname_string; code = array_get(imemory, &namesarray, (long)0, &sname); if (code < 0) return code; istate->colorspace[0].procs.special.separation.layer_name = sname; code = array_get(imemory, devicenspace, 3, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.separation.tint_transform = proc; if (code >= 0) code = gs_cspace_set_sepr_function(pcs, pfn); if (code >= 0) code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setseparationspace"); if (code < 0) { istate->colorspace[0] = cspace_old; return code; } cc.pattern = 0x00; cc.paint.values[0] = 1.0; code = gs_setcolor(igs, &cc); return code; } } code = gs_cspace_new_DeviceN(&pcs, num_components, pacs, imemory); if (code < 0) return code; names = pcs->params.device_n.names; pcs->params.device_n.get_colorname_string = gs_get_colorname_string; /* Pick up the names of the components */ { uint i; ref sname; for (i = 0; i < num_components; ++i) { array_get(imemory, &namesarray, (long)i, &sname); switch (r_type(&sname)) { case t_string: code = name_from_string(imemory, &sname, &sname); if (code < 0) { rc_decrement_cs(pcs, "setdevicenspace"); return code; } /* falls through */ case t_name: names[i] = name_index(imemory, &sname); break; default: rc_decrement_cs(pcs, "setdevicenspace"); return_error(gs_error_typecheck); } } } /* Now set the current color space as DeviceN */ cspace_old = istate->colorspace[0]; istate->colorspace[0].procs.special.device_n.layer_names = namesarray; code = array_get(imemory, devicenspace, 3, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.device_n.tint_transform = proc; code = gs_cspace_set_devn_function(pcs, pfn); if (code < 0) { return code; } code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setdevicenspace"); if (code < 0) { istate->colorspace[0] = cspace_old; return code; } cc.pattern = 0x00; for (i=0;i<num_components;i++) cc.paint.values[i] = 1.0; code = gs_setcolor(igs, &cc); *cont = 1; return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,511
static int setgrayspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { os_ptr op = osp; gs_color_space *pcs; int code=0; ref stref; do { switch (*stage) { case 0: if (istate->use_cie_color.value.boolval && !CIESubst) { byte *body; ref *nosubst; code = dict_find_string(systemdict, "NOSUBSTDEVICECOLORS", &nosubst); if (code != 0) { if (!r_has_type(nosubst, t_boolean)) return_error(gs_error_typecheck); } if (code != 0 && nosubst->value.boolval) { *stage = 4; *cont = 1; body = ialloc_string(32, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "/DefaultGray ..nosubstdevicetest",32); make_string(&stref, a_all | icurrent_space, 32, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } else { *stage = 2; *cont = 1; body = ialloc_string(47, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "{/DefaultGray /ColorSpace findresource} stopped",47); make_string(&stref, a_all | icurrent_space, 47, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } break; } /* fall through */ case 1: pcs = gs_cspace_new_DeviceGray(imemory); if (pcs == NULL) return_error(gs_error_VMerror); code = gs_setcolorspace(igs, pcs); if (code >= 0) { gs_client_color *pcc = gs_currentcolor_inline(igs); cs_adjust_color_count(igs, -1); /* not strictly necessary */ pcc->paint.values[0] = (0); pcc->pattern = 0; /* for GC */ gx_unset_dev_color(igs); } rc_decrement_only_cs(pcs, "zsetdevcspace"); *cont = 0; *stage = 0; break; case 2: if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); if (op->value.boolval) { /* Failed to find the /DefaultGray CSA, so give up and * just use DeviceGray */ pop(1); *stage = 1; break; } pop(1); *cont = 1; *stage = 3; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; break; case 3: /* We end up here after setting the DefaultGray space * We've finished setting the gray color space, so we * just exit now */ *cont = 0; *stage = 0; break; case 4: /* We come here if /UseCIEColor is true, and NOSUBSTDEVICECOLORS * is also true. We will have a boolean on the stack, if its true * then we need to set the space (also on the stack), invoke * .includecolorspace, and set /DeviceGray, otherwise we just need * to set DeviceGray. See gs_cspace.ps. */ if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); pop(1); *stage = 1; *cont = 1; if (op->value.boolval) { *stage = 5; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; } break; case 5: /* After stage 4 above, if we had to set a color space, we come * here. Now we need to use .includecolorspace to register the space * with any high-level devices which want it. */ *stage = 1; *cont = 1; code = zincludecolorspace(i_ctx_p); if (code != 0) return code; break; } } while (*stage); return code; }
null
0
static int setgrayspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { os_ptr op = osp; gs_color_space *pcs; int code=0; ref stref; do { switch (*stage) { case 0: if (istate->use_cie_color.value.boolval && !CIESubst) { byte *body; ref *nosubst; code = dict_find_string(systemdict, "NOSUBSTDEVICECOLORS", &nosubst); if (code != 0) { if (!r_has_type(nosubst, t_boolean)) return_error(gs_error_typecheck); } if (code != 0 && nosubst->value.boolval) { *stage = 4; *cont = 1; body = ialloc_string(32, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "/DefaultGray ..nosubstdevicetest",32); make_string(&stref, a_all | icurrent_space, 32, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } else { *stage = 2; *cont = 1; body = ialloc_string(47, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "{/DefaultGray /ColorSpace findresource} stopped",47); make_string(&stref, a_all | icurrent_space, 47, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } break; } /* fall through */ case 1: pcs = gs_cspace_new_DeviceGray(imemory); if (pcs == NULL) return_error(gs_error_VMerror); code = gs_setcolorspace(igs, pcs); if (code >= 0) { gs_client_color *pcc = gs_currentcolor_inline(igs); cs_adjust_color_count(igs, -1); /* not strictly necessary */ pcc->paint.values[0] = (0); pcc->pattern = 0; /* for GC */ gx_unset_dev_color(igs); } rc_decrement_only_cs(pcs, "zsetdevcspace"); *cont = 0; *stage = 0; break; case 2: if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); if (op->value.boolval) { /* Failed to find the /DefaultGray CSA, so give up and * just use DeviceGray */ pop(1); *stage = 1; break; } pop(1); *cont = 1; *stage = 3; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; break; case 3: /* We end up here after setting the DefaultGray space * We've finished setting the gray color space, so we * just exit now */ *cont = 0; *stage = 0; break; case 4: /* We come here if /UseCIEColor is true, and NOSUBSTDEVICECOLORS * is also true. We will have a boolean on the stack, if its true * then we need to set the space (also on the stack), invoke * .includecolorspace, and set /DeviceGray, otherwise we just need * to set DeviceGray. See gs_cspace.ps. */ if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); pop(1); *stage = 1; *cont = 1; if (op->value.boolval) { *stage = 5; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; } break; case 5: /* After stage 4 above, if we had to set a color space, we come * here. Now we need to use .includecolorspace to register the space * with any high-level devices which want it. */ *stage = 1; *cont = 1; code = zincludecolorspace(i_ctx_p); if (code != 0) return code; break; } } while (*stage); return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,512
static int seticcspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { os_ptr op = osp; ref ICCdict, *tempref, *altref=NULL, *nocie = NULL; int components, code; float range[8]; code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); } *cont = 0; do { switch(*stage) { case 0: (*stage)++; code = array_get(imemory, r, 1, &ICCdict); if (code < 0) return code; code = dict_find_string(&ICCdict, "N", &tempref); if (code < 0) return code; if (code == 0) return gs_note_error(gs_error_undefined); components = tempref->value.intval; if (components > count_of(range)/2) return_error(gs_error_rangecheck); /* Don't allow ICCBased spaces if NOCIE is true */ if (nocie && nocie->value.boolval) { code = dict_find_string(&ICCdict, "Alternate", &altref); /* Alternate is optional */ if (code > 0 && (altref != NULL) && (r_type(altref) != t_null)) { /* The PDF interpreter sets a null Alternate. If we have an * Alternate, and its not null, and NOCIE is true, then use the * Alternate instead of the ICC */ push(1); ref_assign(op, altref); /* If CIESubst, we are already substituting for CIE, so use nosubst * to prevent further substitution! */ return setcolorspace_nosubst(i_ctx_p); } else { /* There's no /Alternate (or it is null), set a default space * based on the number of components in the ICCBased space */ code = set_dev_space(i_ctx_p, components); if (code != 0) return code; *stage = 0; } } else { code = iccrange(i_ctx_p, r, (float *)&range); if (code < 0) return code; code = dict_find_string(&ICCdict, "DataSource", &tempref); if (code == 0) return gs_note_error(gs_error_undefined); /* Check for string based ICC and convert to a file */ if (r_has_type(tempref, t_string)){ uint n = r_size(tempref); ref rss; code = make_rss(i_ctx_p, &rss, tempref->value.const_bytes, n, r_space(tempref), 0L, n, false); if (code < 0) return code; ref_assign(tempref, &rss); } /* Make space on operand stack to pass the ICC dictionary */ push(1); ref_assign(op, &ICCdict); code = seticc(i_ctx_p, components, op, (float *)&range); if (code < 0) { code = dict_find_string(&ICCdict, "Alternate", &altref); /* Alternate is optional */ if (code > 0 && (altref != NULL) && (r_type(altref) != t_null)) { /* We have a /Alternate in the ICC space */ /* Our ICC dictionary still on operand stack, we can reuse the * slot on the stack to hold the alternate space. */ ref_assign(op, (ref *)altref); /* If CIESubst, we are already substituting for CIE, so use nosubst * to prevent further substitution! */ if (CIESubst) return setcolorspace_nosubst(i_ctx_p); else return zsetcolorspace(i_ctx_p); } else { /* We have no /Alternate in the ICC space, use hte /N key to * determine an 'appropriate' default space. */ code = set_dev_space(i_ctx_p, components); if (code != 0) return code; *stage = 0; } pop(1); } if (code != 0) return code; } break; case 1: /* All done, exit */ *stage = 0; code = 0; break; default: return_error (gs_error_rangecheck); break; } }while(*stage); return code; }
null
0
static int seticcspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { os_ptr op = osp; ref ICCdict, *tempref, *altref=NULL, *nocie = NULL; int components, code; float range[8]; code = dict_find_string(systemdict, "NOCIE", &nocie); if (code > 0) { if (!r_has_type(nocie, t_boolean)) return_error(gs_error_typecheck); } *cont = 0; do { switch(*stage) { case 0: (*stage)++; code = array_get(imemory, r, 1, &ICCdict); if (code < 0) return code; code = dict_find_string(&ICCdict, "N", &tempref); if (code < 0) return code; if (code == 0) return gs_note_error(gs_error_undefined); components = tempref->value.intval; if (components > count_of(range)/2) return_error(gs_error_rangecheck); /* Don't allow ICCBased spaces if NOCIE is true */ if (nocie && nocie->value.boolval) { code = dict_find_string(&ICCdict, "Alternate", &altref); /* Alternate is optional */ if (code > 0 && (altref != NULL) && (r_type(altref) != t_null)) { /* The PDF interpreter sets a null Alternate. If we have an * Alternate, and its not null, and NOCIE is true, then use the * Alternate instead of the ICC */ push(1); ref_assign(op, altref); /* If CIESubst, we are already substituting for CIE, so use nosubst * to prevent further substitution! */ return setcolorspace_nosubst(i_ctx_p); } else { /* There's no /Alternate (or it is null), set a default space * based on the number of components in the ICCBased space */ code = set_dev_space(i_ctx_p, components); if (code != 0) return code; *stage = 0; } } else { code = iccrange(i_ctx_p, r, (float *)&range); if (code < 0) return code; code = dict_find_string(&ICCdict, "DataSource", &tempref); if (code == 0) return gs_note_error(gs_error_undefined); /* Check for string based ICC and convert to a file */ if (r_has_type(tempref, t_string)){ uint n = r_size(tempref); ref rss; code = make_rss(i_ctx_p, &rss, tempref->value.const_bytes, n, r_space(tempref), 0L, n, false); if (code < 0) return code; ref_assign(tempref, &rss); } /* Make space on operand stack to pass the ICC dictionary */ push(1); ref_assign(op, &ICCdict); code = seticc(i_ctx_p, components, op, (float *)&range); if (code < 0) { code = dict_find_string(&ICCdict, "Alternate", &altref); /* Alternate is optional */ if (code > 0 && (altref != NULL) && (r_type(altref) != t_null)) { /* We have a /Alternate in the ICC space */ /* Our ICC dictionary still on operand stack, we can reuse the * slot on the stack to hold the alternate space. */ ref_assign(op, (ref *)altref); /* If CIESubst, we are already substituting for CIE, so use nosubst * to prevent further substitution! */ if (CIESubst) return setcolorspace_nosubst(i_ctx_p); else return zsetcolorspace(i_ctx_p); } else { /* We have no /Alternate in the ICC space, use hte /N key to * determine an 'appropriate' default space. */ code = set_dev_space(i_ctx_p, components); if (code != 0) return code; *stage = 0; } pop(1); } if (code != 0) return code; } break; case 1: /* All done, exit */ *stage = 0; code = 0; break; default: return_error (gs_error_rangecheck); break; } }while(*stage); return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,513
static int setindexedspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { ref *pproc = &istate->colorspace[0].procs.special.index_proc; int code = 0; uint edepth = ref_stack_count(&e_stack); ref_colorspace cspace_old; ref hival, lookup; gs_color_space *pcs; gs_color_space *pcs_base; gs_color_space_index base_type; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); *cont = 0; if (*stage == 1) { *stage = 0; return 0; } cspace_old = istate->colorspace[0]; pcs_base = gs_currentcolorspace(igs); base_type = gs_color_space_get_index(pcs_base); code = array_get(imemory, r, 3, &lookup); if (code < 0) return code; code = array_get(imemory, r, 2, &hival); if (code < 0) return code; if (r_has_type(&lookup, t_string)) { int num_values = (hival.value.intval + 1) * cs_num_components(pcs_base); byte *data_tmp; check_read(lookup); /* * The PDF and PS specifications state that the lookup table must have * the exact number of of data bytes needed. However we have found * PDF files from Amyuni with extra data bytes. Acrobat 6.0 accepts * these files without complaint, so we ignore the extra data. */ if (r_size(&lookup) < num_values) return_error(gs_error_rangecheck); /* If we have a named color profile and the base space is DeviceN or Separation use a different set of procedures to ensure the named color remapping code is used */ if (igs->icc_manager->device_named != NULL && (base_type == gs_color_space_index_Separation || base_type == gs_color_space_index_DeviceN)) pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed_Named); else pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed); if (!pcs) { return_error(gs_error_VMerror); } pcs->base_space = pcs_base; rc_increment_cs(pcs_base); data_tmp = (byte *) (pcs->params.indexed.lookup.table.data = ialloc_string (lookup.tas.rsize, "setindexedspace")); if (!data_tmp) { rc_decrement(pcs, "setindexedspace"); return_error(gs_error_VMerror); } memcpy(data_tmp, lookup.value.const_bytes, lookup.tas.rsize); pcs->params.indexed.lookup.table.size = num_values; pcs->params.indexed.use_proc = 0; make_null(pproc); } else { gs_indexed_map *map; /* * We have to call zcs_begin_map before moving the parameters, * since if the color space is a DeviceN or Separation space, * the memmove will overwrite its parameters. */ code = zcs_begin_map(i_ctx_p, &map, &lookup, (hival.value.intval + 1), pcs_base, indexed_cont); if (code < 0) return code; if (igs->icc_manager->device_named != NULL && (base_type == gs_color_space_index_Separation || base_type == gs_color_space_index_DeviceN)) pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed_Named); else pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed); pcs->base_space = pcs_base; rc_increment_cs(pcs_base); pcs->params.indexed.use_proc = 1; *pproc = lookup; map->proc.lookup_index = lookup_indexed_map; pcs->params.indexed.lookup.map = map; } pcs->params.indexed.hival = hival.value.intval; pcs->params.indexed.n_comps = cs_num_components(pcs_base); code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setindexedspace"); if (code < 0) { istate->colorspace[0] = cspace_old; ref_stack_pop_to(&e_stack, edepth); return code; } *stage = 0; if (ref_stack_count(&e_stack) == edepth) { return 0; } else { *cont = 1; *stage = 1; return o_push_estack; /* installation will load the caches */ } }
null
0
static int setindexedspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { ref *pproc = &istate->colorspace[0].procs.special.index_proc; int code = 0; uint edepth = ref_stack_count(&e_stack); ref_colorspace cspace_old; ref hival, lookup; gs_color_space *pcs; gs_color_space *pcs_base; gs_color_space_index base_type; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); *cont = 0; if (*stage == 1) { *stage = 0; return 0; } cspace_old = istate->colorspace[0]; pcs_base = gs_currentcolorspace(igs); base_type = gs_color_space_get_index(pcs_base); code = array_get(imemory, r, 3, &lookup); if (code < 0) return code; code = array_get(imemory, r, 2, &hival); if (code < 0) return code; if (r_has_type(&lookup, t_string)) { int num_values = (hival.value.intval + 1) * cs_num_components(pcs_base); byte *data_tmp; check_read(lookup); /* * The PDF and PS specifications state that the lookup table must have * the exact number of of data bytes needed. However we have found * PDF files from Amyuni with extra data bytes. Acrobat 6.0 accepts * these files without complaint, so we ignore the extra data. */ if (r_size(&lookup) < num_values) return_error(gs_error_rangecheck); /* If we have a named color profile and the base space is DeviceN or Separation use a different set of procedures to ensure the named color remapping code is used */ if (igs->icc_manager->device_named != NULL && (base_type == gs_color_space_index_Separation || base_type == gs_color_space_index_DeviceN)) pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed_Named); else pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed); if (!pcs) { return_error(gs_error_VMerror); } pcs->base_space = pcs_base; rc_increment_cs(pcs_base); data_tmp = (byte *) (pcs->params.indexed.lookup.table.data = ialloc_string (lookup.tas.rsize, "setindexedspace")); if (!data_tmp) { rc_decrement(pcs, "setindexedspace"); return_error(gs_error_VMerror); } memcpy(data_tmp, lookup.value.const_bytes, lookup.tas.rsize); pcs->params.indexed.lookup.table.size = num_values; pcs->params.indexed.use_proc = 0; make_null(pproc); } else { gs_indexed_map *map; /* * We have to call zcs_begin_map before moving the parameters, * since if the color space is a DeviceN or Separation space, * the memmove will overwrite its parameters. */ code = zcs_begin_map(i_ctx_p, &map, &lookup, (hival.value.intval + 1), pcs_base, indexed_cont); if (code < 0) return code; if (igs->icc_manager->device_named != NULL && (base_type == gs_color_space_index_Separation || base_type == gs_color_space_index_DeviceN)) pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed_Named); else pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Indexed); pcs->base_space = pcs_base; rc_increment_cs(pcs_base); pcs->params.indexed.use_proc = 1; *pproc = lookup; map->proc.lookup_index = lookup_indexed_map; pcs->params.indexed.lookup.map = map; } pcs->params.indexed.hival = hival.value.intval; pcs->params.indexed.n_comps = cs_num_components(pcs_base); code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setindexedspace"); if (code < 0) { istate->colorspace[0] = cspace_old; ref_stack_pop_to(&e_stack, edepth); return code; } *stage = 0; if (ref_stack_count(&e_stack) == edepth) { return 0; } else { *cont = 1; *stage = 1; return o_push_estack; /* installation will load the caches */ } }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,514
static int setlabspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { /* In this case, we will treat this as an ICC color space, with a CIELAB 16 bit profile */ ref labdict; int code = 0; float range_buff[4], white[3], black[3]; static const float dflt_range[4] = { -100, 100, -100, 100 }; static const float dflt_black[3] = {0,0,0}, dflt_white[3] = {0,0,0}; int i; gs_client_color cc; *cont = 0; code = array_get(imemory, r, 1, &labdict); if (code < 0) return code; /* Get all the parts */ code = dict_floats_param( imemory, &labdict, "Range", 4, range_buff, dflt_range ); if (code < 0) return code; for (i = 0; i < 4 && range_buff[i + 1] >= range_buff[i]; i += 2); if (i != 4) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &labdict, "BlackPoint", 3, black, dflt_black ); if (code < 0) return code; code = dict_floats_param( imemory, &labdict, "WhitePoint", 3, white, dflt_white ); if (code < 0) return code; if (white[0] <= 0 || white[1] != 1.0 || white[2] <= 0) return_error(gs_error_rangecheck); code = seticc_lab(i_ctx_p, white, black, range_buff); if ( code < 0) return gs_rethrow(code, "setting PDF lab color space"); cc.pattern = 0x00; for (i=0;i<3;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); return code; }
null
0
static int setlabspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { /* In this case, we will treat this as an ICC color space, with a CIELAB 16 bit profile */ ref labdict; int code = 0; float range_buff[4], white[3], black[3]; static const float dflt_range[4] = { -100, 100, -100, 100 }; static const float dflt_black[3] = {0,0,0}, dflt_white[3] = {0,0,0}; int i; gs_client_color cc; *cont = 0; code = array_get(imemory, r, 1, &labdict); if (code < 0) return code; /* Get all the parts */ code = dict_floats_param( imemory, &labdict, "Range", 4, range_buff, dflt_range ); if (code < 0) return code; for (i = 0; i < 4 && range_buff[i + 1] >= range_buff[i]; i += 2); if (i != 4) return_error(gs_error_rangecheck); code = dict_floats_param( imemory, &labdict, "BlackPoint", 3, black, dflt_black ); if (code < 0) return code; code = dict_floats_param( imemory, &labdict, "WhitePoint", 3, white, dflt_white ); if (code < 0) return code; if (white[0] <= 0 || white[1] != 1.0 || white[2] <= 0) return_error(gs_error_rangecheck); code = seticc_lab(i_ctx_p, white, black, range_buff); if ( code < 0) return gs_rethrow(code, "setting PDF lab color space"); cc.pattern = 0x00; for (i=0;i<3;i++) cc.paint.values[i] = 0; code = gs_setcolor(igs, &cc); return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,515
static int setpatternspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { gs_color_space *pcs; gs_color_space *pcs_base; uint edepth = ref_stack_count(&e_stack); int code = 0; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); *cont = 0; pcs_base = NULL; if (r_is_array(r)) { check_read(*r); switch (r_size(r)) { case 1: /* no base space */ pcs_base = NULL; break; default: return_error(gs_error_rangecheck); case 2: pcs_base = gs_currentcolorspace(igs); if (cs_num_components(pcs_base) < 0) /* i.e., Pattern space */ return_error(gs_error_rangecheck); } } pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Pattern); pcs->base_space = pcs_base; pcs->params.pattern.has_base_space = (pcs_base != NULL); rc_increment_cs(pcs_base); code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "zsetpatternspace"); if (code < 0) { ref_stack_pop_to(&e_stack, edepth); return code; } make_null(&istate->pattern[0]); /* PLRM: initial color value is a null object */ *stage = 0; return (ref_stack_count(&e_stack) == edepth ? 0 : o_push_estack); /* installation will load the caches */ }
null
0
static int setpatternspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { gs_color_space *pcs; gs_color_space *pcs_base; uint edepth = ref_stack_count(&e_stack); int code = 0; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); *cont = 0; pcs_base = NULL; if (r_is_array(r)) { check_read(*r); switch (r_size(r)) { case 1: /* no base space */ pcs_base = NULL; break; default: return_error(gs_error_rangecheck); case 2: pcs_base = gs_currentcolorspace(igs); if (cs_num_components(pcs_base) < 0) /* i.e., Pattern space */ return_error(gs_error_rangecheck); } } pcs = gs_cspace_alloc(imemory, &gs_color_space_type_Pattern); pcs->base_space = pcs_base; pcs->params.pattern.has_base_space = (pcs_base != NULL); rc_increment_cs(pcs_base); code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "zsetpatternspace"); if (code < 0) { ref_stack_pop_to(&e_stack, edepth); return code; } make_null(&istate->pattern[0]); /* PLRM: initial color value is a null object */ *stage = 0; return (ref_stack_count(&e_stack) == edepth ? 0 : o_push_estack); /* installation will load the caches */ }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,516
static int setrgbspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { os_ptr op = osp; gs_color_space *pcs; int code=0; ref stref; do { switch (*stage) { case 0: if (istate->use_cie_color.value.boolval && !CIESubst) { byte *body; ref *nosubst; code = dict_find_string(systemdict, "NOSUBSTDEVICECOLORS", &nosubst); if (code != 0) { if (!r_has_type(nosubst, t_boolean)) return_error(gs_error_typecheck); } if (code != 0 && nosubst->value.boolval) { *stage = 4; *cont = 1; body = ialloc_string(31, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "/DefaultRGB ..nosubstdevicetest",31); make_string(&stref, a_all | icurrent_space, 31, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } else { *stage = 2; *cont = 1; body = ialloc_string(46, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "{/DefaultRGB /ColorSpace findresource} stopped", 46); make_string(&stref, a_all | icurrent_space, 46, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } } /* fall through */ case 1: pcs = gs_cspace_new_DeviceRGB(imemory); if (pcs == NULL) return_error(gs_error_VMerror); code = gs_setcolorspace(igs, pcs); if (code >= 0) { gs_client_color *pcc = gs_currentcolor_inline(igs); cs_adjust_color_count(igs, -1); /* not strictly necessary */ pcc->paint.values[0] = 0; pcc->paint.values[1] = 0; pcc->paint.values[2] = 0; pcc->pattern = 0; /* for GC */ gx_unset_dev_color(igs); } rc_decrement_only_cs(pcs, "zsetdevcspace"); *cont = 0; *stage = 0; break; case 2: if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); if (op->value.boolval) { /* Failed to find the /DefaultRGB CSA, so give up and * just use DeviceRGB */ pop(1); *stage = 1; break; } pop(1); *stage = 3; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; break; case 3: /* We end up here after setting the DefaultGray CIE space * We've finished setting the gray color space, so we * just exit now */ *cont = 0; *stage = 0; break; case 4: /* We come here if /UseCIEColor is true, and NOSUBSTDEVICECOLORS * is also true. We will have a boolean on the stack, if its true * then we need to set the space (also on the stack), invoke * .includecolorspace, and set /DeviceGray, otherwise we just need * to set DeviceGray. See gs-cspace.ps. */ if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); pop(1); *stage = 1; *cont = 1; if (op->value.boolval) { *stage = 5; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; } break; case 5: /* After stage 4 above, if we had to set a color space, we come * here. Now we need to use .includecolorspace to register the space * with any high-level devices which want it. */ *stage = 1; *cont = 1; code = zincludecolorspace(i_ctx_p); if (code != 0) return code; break; } } while (*stage); return code; }
null
0
static int setrgbspace(i_ctx_t * i_ctx_p, ref *r, int *stage, int *cont, int CIESubst) { os_ptr op = osp; gs_color_space *pcs; int code=0; ref stref; do { switch (*stage) { case 0: if (istate->use_cie_color.value.boolval && !CIESubst) { byte *body; ref *nosubst; code = dict_find_string(systemdict, "NOSUBSTDEVICECOLORS", &nosubst); if (code != 0) { if (!r_has_type(nosubst, t_boolean)) return_error(gs_error_typecheck); } if (code != 0 && nosubst->value.boolval) { *stage = 4; *cont = 1; body = ialloc_string(31, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "/DefaultRGB ..nosubstdevicetest",31); make_string(&stref, a_all | icurrent_space, 31, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } else { *stage = 2; *cont = 1; body = ialloc_string(46, "string"); if (body == 0) return_error(gs_error_VMerror); memcpy(body, "{/DefaultRGB /ColorSpace findresource} stopped", 46); make_string(&stref, a_all | icurrent_space, 46, body); r_set_attrs(&stref, a_executable); esp++; ref_assign(esp, &stref); return o_push_estack; } } /* fall through */ case 1: pcs = gs_cspace_new_DeviceRGB(imemory); if (pcs == NULL) return_error(gs_error_VMerror); code = gs_setcolorspace(igs, pcs); if (code >= 0) { gs_client_color *pcc = gs_currentcolor_inline(igs); cs_adjust_color_count(igs, -1); /* not strictly necessary */ pcc->paint.values[0] = 0; pcc->paint.values[1] = 0; pcc->paint.values[2] = 0; pcc->pattern = 0; /* for GC */ gx_unset_dev_color(igs); } rc_decrement_only_cs(pcs, "zsetdevcspace"); *cont = 0; *stage = 0; break; case 2: if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); if (op->value.boolval) { /* Failed to find the /DefaultRGB CSA, so give up and * just use DeviceRGB */ pop(1); *stage = 1; break; } pop(1); *stage = 3; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; break; case 3: /* We end up here after setting the DefaultGray CIE space * We've finished setting the gray color space, so we * just exit now */ *cont = 0; *stage = 0; break; case 4: /* We come here if /UseCIEColor is true, and NOSUBSTDEVICECOLORS * is also true. We will have a boolean on the stack, if its true * then we need to set the space (also on the stack), invoke * .includecolorspace, and set /DeviceGray, otherwise we just need * to set DeviceGray. See gs-cspace.ps. */ if (!r_has_type(op, t_boolean)) return_error(gs_error_typecheck); pop(1); *stage = 1; *cont = 1; if (op->value.boolval) { *stage = 5; code = setcolorspace_nosubst(i_ctx_p); if (code != 0) return code; } break; case 5: /* After stage 4 above, if we had to set a color space, we come * here. Now we need to use .includecolorspace to register the space * with any high-level devices which want it. */ *stage = 1; *cont = 1; code = zincludecolorspace(i_ctx_p); if (code != 0) return code; break; } } while (*stage); return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,517
static int setseparationspace(i_ctx_t * i_ctx_p, ref *sepspace, int *stage, int *cont, int CIESubst) { os_ptr op = osp; /* required by "push" macro */ int code = 0; ref sname, proc; ref name_none, name_all; separation_type sep_type; ref_colorspace cspace_old; gs_color_space *pcs; gs_color_space * pacs; gs_function_t *pfn = NULL; gs_client_color cc; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); *cont = 0; if ((*stage) == 0) { code = array_get(imemory, sepspace, 3, &proc); if (code < 0) return code; /* Check to see if we already have a function (eg from a PDF file) */ pfn = ref_function(&proc); if (pfn == NULL) { /* Convert tint transform to a PostScript function */ code = convert_transform(i_ctx_p, sepspace, &proc); if (code < 0) return code; if (code > 0) { *cont = 1; (*stage)++; return code; } /* We can only get here if the transform converted to a function * without requiring a continuation. Most likely this means its a * type 4 function. If so then it is still on the stack. */ op = osp; pfn = ref_function(op); pop (1); } } else { /* The function is returned on the operand stack */ op = osp; pfn = ref_function(op); pop (1); } *stage = 0; if ((code = name_ref(imemory, (const byte *)"All", 3, &name_all, 0)) < 0) return code; if ((code = name_ref(imemory, (const byte *)"None", 4, &name_none, 0)) < 0) return code; /* 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_string)) { code = name_from_string(imemory, &sname, &sname); if (code < 0) return code; } sep_type = ( name_eq(&sname, &name_all) ? SEP_ALL : name_eq(&sname, &name_none) ? SEP_NONE : SEP_OTHER); /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); cspace_old = istate->colorspace[0]; /* Now set the current color space as Separation */ code = gs_cspace_new_Separation(&pcs, pacs, imemory); if (code < 0) return code; pcs->params.separation.sep_type = sep_type; pcs->params.separation.sep_name = name_index(imemory, &sname); pcs->params.separation.get_colorname_string = gs_get_colorname_string; code = array_get(imemory, sepspace, 1, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.separation.layer_name = proc; code = array_get(imemory, sepspace, 3, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.separation.tint_transform = proc; if (code >= 0) code = gs_cspace_set_sepr_function(pcs, pfn); if (code >= 0) code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setseparationspace"); if (code < 0) { istate->colorspace[0] = cspace_old; return code; } cc.pattern = 0x00; cc.paint.values[0] = 1.0; code = gs_setcolor(igs, &cc); return code; }
null
0
static int setseparationspace(i_ctx_t * i_ctx_p, ref *sepspace, int *stage, int *cont, int CIESubst) { os_ptr op = osp; /* required by "push" macro */ int code = 0; ref sname, proc; ref name_none, name_all; separation_type sep_type; ref_colorspace cspace_old; gs_color_space *pcs; gs_color_space * pacs; gs_function_t *pfn = NULL; gs_client_color cc; if (i_ctx_p->language_level < 2) return_error(gs_error_undefined); *cont = 0; if ((*stage) == 0) { code = array_get(imemory, sepspace, 3, &proc); if (code < 0) return code; /* Check to see if we already have a function (eg from a PDF file) */ pfn = ref_function(&proc); if (pfn == NULL) { /* Convert tint transform to a PostScript function */ code = convert_transform(i_ctx_p, sepspace, &proc); if (code < 0) return code; if (code > 0) { *cont = 1; (*stage)++; return code; } /* We can only get here if the transform converted to a function * without requiring a continuation. Most likely this means its a * type 4 function. If so then it is still on the stack. */ op = osp; pfn = ref_function(op); pop (1); } } else { /* The function is returned on the operand stack */ op = osp; pfn = ref_function(op); pop (1); } *stage = 0; if ((code = name_ref(imemory, (const byte *)"All", 3, &name_all, 0)) < 0) return code; if ((code = name_ref(imemory, (const byte *)"None", 4, &name_none, 0)) < 0) return code; /* 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_string)) { code = name_from_string(imemory, &sname, &sname); if (code < 0) return code; } sep_type = ( name_eq(&sname, &name_all) ? SEP_ALL : name_eq(&sname, &name_none) ? SEP_NONE : SEP_OTHER); /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); cspace_old = istate->colorspace[0]; /* Now set the current color space as Separation */ code = gs_cspace_new_Separation(&pcs, pacs, imemory); if (code < 0) return code; pcs->params.separation.sep_type = sep_type; pcs->params.separation.sep_name = name_index(imemory, &sname); pcs->params.separation.get_colorname_string = gs_get_colorname_string; code = array_get(imemory, sepspace, 1, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.separation.layer_name = proc; code = array_get(imemory, sepspace, 3, &proc); if (code < 0) return code; istate->colorspace[0].procs.special.separation.tint_transform = proc; if (code >= 0) code = gs_cspace_set_sepr_function(pcs, pfn); if (code >= 0) code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only_cs(pcs, "setseparationspace"); if (code < 0) { istate->colorspace[0] = cspace_old; return code; } cc.pattern = 0x00; cc.paint.values[0] = 1.0; code = gs_setcolor(igs, &cc); return code; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,518
setstrokecolor_cont(i_ctx_t * i_ctx_p) { return zswapcolors(i_ctx_p); }
null
0
setstrokecolor_cont(i_ctx_t * i_ctx_p) { return zswapcolors(i_ctx_p); }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,519
setstrokecolorspace_cont(i_ctx_t * i_ctx_p) { return zswapcolors(i_ctx_p); }
null
0
setstrokecolorspace_cont(i_ctx_t * i_ctx_p) { return zswapcolors(i_ctx_p); }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,520
static int threecomponent(i_ctx_t * i_ctx_p, ref *space, int *n) { *n = 3; return 0; }
null
0
static int threecomponent(i_ctx_t * i_ctx_p, ref *space, int *n) { *n = 3; return 0; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,521
static int truecompareproc(i_ctx_t *i_ctx_p, ref *space, ref *testspace) { return 1; }
null
0
static int truecompareproc(i_ctx_t *i_ctx_p, ref *space, ref *testspace) { return 1; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,522
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,523
static int validatecalgrayspace(i_ctx_t * i_ctx_p, ref **r) { int code=0; ref *space, calgraydict; 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, &calgraydict); if (code < 0) return code; check_type(calgraydict, t_dictionary); /* Check the white point, which is required */ /* We have to have a white point */ /* Check white point exists, and is an array of three numbers */ code = checkWhitePoint(i_ctx_p, &calgraydict); if (code != 0) return code; /* The rest are optional. Need to validate though */ code = checkBlackPoint(i_ctx_p, &calgraydict); if (code < 0) return code; /* Check Gamma values */ code = checkGamma(i_ctx_p, &calgraydict, 1); if (code < 0) return code; *r = 0; /* No nested space */ return 0; }
null
0
static int validatecalgrayspace(i_ctx_t * i_ctx_p, ref **r) { int code=0; ref *space, calgraydict; 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, &calgraydict); if (code < 0) return code; check_type(calgraydict, t_dictionary); /* Check the white point, which is required */ /* We have to have a white point */ /* Check white point exists, and is an array of three numbers */ code = checkWhitePoint(i_ctx_p, &calgraydict); if (code != 0) return code; /* The rest are optional. Need to validate though */ code = checkBlackPoint(i_ctx_p, &calgraydict); if (code < 0) return code; /* Check Gamma values */ code = checkGamma(i_ctx_p, &calgraydict, 1); if (code < 0) return code; *r = 0; /* No nested space */ return 0; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,524
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,525
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,526
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,527
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,528
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,529
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,530
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,531
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,532
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,533
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,534
zcolor_remap_one( i_ctx_t * i_ctx_p, const ref * pproc, gx_transfer_map * pmap, const gs_gstate * pgs, op_proc_t finish_proc ) { os_ptr op; /* * Detect the identity function, which is a common value for one or * more of these functions. */ if (r_size(pproc) == 0) { gx_set_identity_transfer(pmap); /* * Even though we don't actually push anything on the e-stack, all * clients do, so we return o_push_estack in this case. This is * needed so that clients' finishing procedures will get run. */ return o_push_estack; } op = osp += 4; make_real(op - 3, 0); make_int(op - 2, transfer_map_size - 1); make_real(op - 1, 1); *op = *pproc; ++esp; make_struct(esp, imemory_space((gs_ref_memory_t *) pgs->memory), pmap); push_op_estack(finish_proc); push_op_estack(zfor_samples); return o_push_estack; }
null
0
zcolor_remap_one( i_ctx_t * i_ctx_p, const ref * pproc, gx_transfer_map * pmap, const gs_gstate * pgs, op_proc_t finish_proc ) { os_ptr op; /* * Detect the identity function, which is a common value for one or * more of these functions. */ if (r_size(pproc) == 0) { gx_set_identity_transfer(pmap); /* * Even though we don't actually push anything on the e-stack, all * clients do, so we return o_push_estack in this case. This is * needed so that clients' finishing procedures will get run. */ return o_push_estack; } op = osp += 4; make_real(op - 3, 0); make_int(op - 2, transfer_map_size - 1); make_real(op - 1, 1); *op = *pproc; ++esp; make_struct(esp, imemory_space((gs_ref_memory_t *) pgs->memory), pmap); push_op_estack(finish_proc); push_op_estack(zfor_samples); return o_push_estack; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,535
zcolor_remap_one_finish(i_ctx_t *i_ctx_p) { return zcolor_remap_one_store(i_ctx_p, 0.0); }
null
0
zcolor_remap_one_finish(i_ctx_t *i_ctx_p) { return zcolor_remap_one_store(i_ctx_p, 0.0); }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,536
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,537
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,538
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,539
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,540
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,541
zsetfillcolor(i_ctx_t * i_ctx_p) { return zsetcolor(i_ctx_p); }
null
0
zsetfillcolor(i_ctx_t * i_ctx_p) { return zsetcolor(i_ctx_p); }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,542
zsetfillcolorspace(i_ctx_t * i_ctx_p) { return zsetcolorspace(i_ctx_p); }
null
0
zsetfillcolorspace(i_ctx_t * i_ctx_p) { return zsetcolorspace(i_ctx_p); }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,543
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,544
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; }
null
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; }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,545
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); }
null
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); }
@@ -283,8 +283,9 @@ zsetcolor(i_ctx_t * i_ctx_p) if (r_has_type(op, t_dictionary)) { ref *pImpl, pPatInst; - code = dict_find_string(op, "Implementation", &pImpl); - if (code != 0) { + 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;
CWE-704
null
null
2,546
access_check(i_ctx_t *i_ctx_p, int access, /* mask for attrs */ bool modify) /* if true, reduce access */ { os_ptr op = osp; ref *aop; switch (r_type(op)) { case t_dictionary: aop = dict_access_ref(op); if (modify) { if (!r_has_attrs(aop, access)) return_error(gs_error_invalidaccess); ref_save(op, aop, "access_check(modify)"); r_clear_attrs(aop, a_all); r_set_attrs(aop, access); dict_set_top(); return 0; } break; case t_array: case t_file: case t_string: case t_mixedarray: case t_shortarray: case t_astruct: case t_device:; if (modify) { if (!r_has_attrs(op, access)) return_error(gs_error_invalidaccess); r_clear_attrs(op, a_all); r_set_attrs(op, access); return 0; } aop = op; break; default: return_op_typecheck(op); } return (r_has_attrs(aop, access) ? 1 : 0); }
null
0
access_check(i_ctx_t *i_ctx_p, int access, /* mask for attrs */ bool modify) /* if true, reduce access */ { os_ptr op = osp; ref *aop; switch (r_type(op)) { case t_dictionary: aop = dict_access_ref(op); if (modify) { if (!r_has_attrs(aop, access)) return_error(gs_error_invalidaccess); ref_save(op, aop, "access_check(modify)"); r_clear_attrs(aop, a_all); r_set_attrs(aop, access); dict_set_top(); return 0; } break; case t_array: case t_file: case t_string: case t_mixedarray: case t_shortarray: case t_astruct: case t_device:; if (modify) { if (!r_has_attrs(op, access)) return_error(gs_error_invalidaccess); r_clear_attrs(op, a_all); r_set_attrs(op, access); return 0; } aop = op; break; default: return_op_typecheck(op); } return (r_has_attrs(aop, access) ? 1 : 0); }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,547
convert_to_string(const gs_memory_t *mem, os_ptr op1, os_ptr op) { uint len; const byte *pstr = 0; int code = obj_cvs(mem, op1, op->value.bytes, r_size(op), &len, &pstr); if (code < 0) { /* * Some common downloaded error handlers assume that * operator names don't exceed a certain fixed size. * To work around this bit of bad design, we implement * a special hack here: if we got a rangecheck, and * the object is an operator whose name begins with * %, ., or @, we just truncate the name. */ if (code == gs_error_rangecheck) switch (r_btype(op1)) { case t_oparray: case t_operator: if (pstr != 0) switch (*pstr) { case '%': case '.': case '@': len = r_size(op); memcpy(op->value.bytes, pstr, len); goto ok; } } return code; } ok: *op1 = *op; r_set_size(op1, len); return 0; }
null
0
convert_to_string(const gs_memory_t *mem, os_ptr op1, os_ptr op) { uint len; const byte *pstr = 0; int code = obj_cvs(mem, op1, op->value.bytes, r_size(op), &len, &pstr); if (code < 0) { /* * Some common downloaded error handlers assume that * operator names don't exceed a certain fixed size. * To work around this bit of bad design, we implement * a special hack here: if we got a rangecheck, and * the object is an operator whose name begins with * %, ., or @, we just truncate the name. */ if (code == gs_error_rangecheck) switch (r_btype(op1)) { case t_oparray: case t_operator: if (pstr != 0) switch (*pstr) { case '%': case '.': case '@': len = r_size(op); memcpy(op->value.bytes, pstr, len); goto ok; } } return code; } ok: *op1 = *op; r_set_size(op1, len); return 0; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,548
zcvlit(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref *aop; check_op(1); aop = ACCESS_REF(op); r_clear_attrs(aop, a_executable); return 0; }
null
0
zcvlit(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref *aop; check_op(1); aop = ACCESS_REF(op); r_clear_attrs(aop, a_executable); return 0; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,549
zcvn(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_read_type(*op, t_string); return name_from_string(imemory, op, op); }
null
0
zcvn(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_read_type(*op, t_string); return name_from_string(imemory, op, op); }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,550
zcvr(i_ctx_t *i_ctx_p) { os_ptr op = osp; switch (r_type(op)) { case t_integer: make_real(op, (float)op->value.intval); case t_real: return 0; default: return_op_typecheck(op); case t_string: { ref str, token; int code; ref_assign(&str, op); code = gs_scan_string_token(i_ctx_p, &str, &token); if (code > 0) /* anything other than a plain token */ code = gs_note_error(gs_error_syntaxerror); if (code < 0) return code; switch (r_type(&token)) { case t_integer: make_real(op, (float)token.value.intval); return 0; case t_real: *op = token; return 0; default: return_error(gs_error_typecheck); } } } }
null
0
zcvr(i_ctx_t *i_ctx_p) { os_ptr op = osp; switch (r_type(op)) { case t_integer: make_real(op, (float)op->value.intval); case t_real: return 0; default: return_op_typecheck(op); case t_string: { ref str, token; int code; ref_assign(&str, op); code = gs_scan_string_token(i_ctx_p, &str, &token); if (code > 0) /* anything other than a plain token */ code = gs_note_error(gs_error_syntaxerror); if (code < 0) return code; switch (r_type(&token)) { case t_integer: make_real(op, (float)token.value.intval); return 0; case t_real: *op = token; return 0; default: return_error(gs_error_typecheck); } } } }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,551
zcvrs(i_ctx_t *i_ctx_p) { os_ptr op = osp; int radix; check_type(op[-1], t_integer); if (op[-1].value.intval < 2 || op[-1].value.intval > 36) return_error(gs_error_rangecheck); radix = op[-1].value.intval; check_write_type(*op, t_string); if (radix == 10) { switch (r_type(op - 2)) { case t_integer: case t_real: { int code = convert_to_string(imemory, op - 2, op); if (code < 0) return code; pop(2); return 0; } case t__invalid: return_error(gs_error_stackunderflow); default: return_error(gs_error_rangecheck); /* CET 24-05 wants rangecheck */ } } else { uint ival; byte digits[sizeof(ulong) * 8]; byte *endp = &digits[countof(digits)]; byte *dp = endp; switch (r_type(op - 2)) { case t_integer: ival = (uint) op[-2].value.intval; break; case t_real: { float fval = op[-2].value.realval; if (!REAL_CAN_BE_INT(fval)) return_error(gs_error_rangecheck); ival = (ulong) (long)fval; } break; case t__invalid: return_error(gs_error_stackunderflow); default: return_error(gs_error_rangecheck); /* CET 24-05 wants rangecheck */ } do { int dit = ival % radix; *--dp = dit + (dit < 10 ? '0' : ('A' - 10)); ival /= radix; } while (ival); if (endp - dp > r_size(op)) return_error(gs_error_rangecheck); memcpy(op->value.bytes, dp, (uint) (endp - dp)); r_set_size(op, endp - dp); } op[-2] = *op; pop(2); return 0; }
null
0
zcvrs(i_ctx_t *i_ctx_p) { os_ptr op = osp; int radix; check_type(op[-1], t_integer); if (op[-1].value.intval < 2 || op[-1].value.intval > 36) return_error(gs_error_rangecheck); radix = op[-1].value.intval; check_write_type(*op, t_string); if (radix == 10) { switch (r_type(op - 2)) { case t_integer: case t_real: { int code = convert_to_string(imemory, op - 2, op); if (code < 0) return code; pop(2); return 0; } case t__invalid: return_error(gs_error_stackunderflow); default: return_error(gs_error_rangecheck); /* CET 24-05 wants rangecheck */ } } else { uint ival; byte digits[sizeof(ulong) * 8]; byte *endp = &digits[countof(digits)]; byte *dp = endp; switch (r_type(op - 2)) { case t_integer: ival = (uint) op[-2].value.intval; break; case t_real: { float fval = op[-2].value.realval; if (!REAL_CAN_BE_INT(fval)) return_error(gs_error_rangecheck); ival = (ulong) (long)fval; } break; case t__invalid: return_error(gs_error_stackunderflow); default: return_error(gs_error_rangecheck); /* CET 24-05 wants rangecheck */ } do { int dit = ival % radix; *--dp = dit + (dit < 10 ? '0' : ('A' - 10)); ival /= radix; } while (ival); if (endp - dp > r_size(op)) return_error(gs_error_rangecheck); memcpy(op->value.bytes, dp, (uint) (endp - dp)); r_set_size(op, endp - dp); } op[-2] = *op; pop(2); return 0; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,552
zcvs(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; check_write_type(*op, t_string); check_op(2); code = convert_to_string(imemory, op - 1, op); if (code >= 0) pop(1); return code; }
null
0
zcvs(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; check_write_type(*op, t_string); check_op(2); code = convert_to_string(imemory, op - 1, op); if (code >= 0) pop(1); return code; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,553
zexecuteonly(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_op(1); if (r_has_type(op, t_dictionary)) return_error(gs_error_typecheck); return access_check(i_ctx_p, a_execute, true); }
null
0
zexecuteonly(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_op(1); if (r_has_type(op, t_dictionary)) return_error(gs_error_typecheck); return access_check(i_ctx_p, a_execute, true); }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,554
znoaccess(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_op(1); if (r_has_type(op, t_dictionary)) { ref *aop = dict_access_ref(op); /* CPSI throws invalidaccess when seting noaccess to a readonly dictionary (CET 13-13-6) : */ if (!r_has_attrs(aop, a_write)) { if (!r_has_attrs(aop, a_read) && !r_has_attrs(aop, a_execute)) { /* Already noaccess - do nothing (CET 24-09-1). */ return 0; } return_error(gs_error_invalidaccess); } /* Don't allow removing read access to permanent dictionaries. */ if (dict_is_permanent_on_dstack(op)) return_error(gs_error_invalidaccess); } return access_check(i_ctx_p, 0, true); }
null
0
znoaccess(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_op(1); if (r_has_type(op, t_dictionary)) { ref *aop = dict_access_ref(op); /* CPSI throws invalidaccess when seting noaccess to a readonly dictionary (CET 13-13-6) : */ if (!r_has_attrs(aop, a_write)) { if (!r_has_attrs(aop, a_read) && !r_has_attrs(aop, a_execute)) { /* Already noaccess - do nothing (CET 24-09-1). */ return 0; } return_error(gs_error_invalidaccess); } /* Don't allow removing read access to permanent dictionaries. */ if (dict_is_permanent_on_dstack(op)) return_error(gs_error_invalidaccess); } return access_check(i_ctx_p, 0, true); }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,555
zrcheck(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code = access_check(i_ctx_p, a_read, false); if (code >= 0) make_bool(op, code), code = 0; return code; }
null
0
zrcheck(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code = access_check(i_ctx_p, a_read, false); if (code >= 0) make_bool(op, code), code = 0; return code; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,556
zreadonly(i_ctx_t *i_ctx_p) { return access_check(i_ctx_p, a_readonly, true); }
null
0
zreadonly(i_ctx_t *i_ctx_p) { return access_check(i_ctx_p, a_readonly, true); }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,557
ztypenames(i_ctx_t *i_ctx_p) { os_ptr op = osp; static const char *const tnames[] = { REF_TYPE_NAME_STRINGS }; int i; check_ostack(t_next_index); for (i = 0; i < t_next_index; i++) { ref *const rtnp = op + 1 + i; if (i >= countof(tnames) || tnames[i] == 0) make_null(rtnp); else { int code = name_enter_string(imemory, tnames[i], rtnp); if (code < 0) return code; r_set_attrs(rtnp, a_executable); } } osp += t_next_index; return 0; }
null
0
ztypenames(i_ctx_t *i_ctx_p) { os_ptr op = osp; static const char *const tnames[] = { REF_TYPE_NAME_STRINGS }; int i; check_ostack(t_next_index); for (i = 0; i < t_next_index; i++) { ref *const rtnp = op + 1 + i; if (i >= countof(tnames) || tnames[i] == 0) make_null(rtnp); else { int code = name_enter_string(imemory, tnames[i], rtnp); if (code < 0) return code; r_set_attrs(rtnp, a_executable); } } osp += t_next_index; return 0; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,558
zwcheck(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code = access_check(i_ctx_p, a_write, false); if (code >= 0) make_bool(op, code), code = 0; return code; }
null
0
zwcheck(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code = access_check(i_ctx_p, a_write, false); if (code >= 0) make_bool(op, code), code = 0; return code; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,559
zxcheck(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_op(1); make_bool(op, (r_has_attr(ACCESS_REF(op), a_executable) ? 1 : 0)); return 0; }
null
0
zxcheck(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_op(1); make_bool(op, (r_has_attr(ACCESS_REF(op), a_executable) ? 1 : 0)); return 0; }
@@ -76,7 +76,7 @@ ztype(i_ctx_t *i_ctx_p) /* Must be either a stack underflow or a t_[a]struct. */ check_op(2); { /* Get the type name from the structure. */ - if (op[-1].value.pstruct != 0x00) { + if ((r_has_type(&op[-1], t_struct) || r_has_type(&op[-1], t_astruct)) && op[-1].value.pstruct != 0x00) { const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct));
CWE-704
null
null
2,560
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; }
Overflow
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; }
@@ -6611,6 +6611,7 @@ static int zsetstrokecolor(i_ctx_t * i_ctx_p) { int code; + es_ptr iesp = esp; /* preserve exec stack in case of error */ code = zswapcolors(i_ctx_p); if (code < 0) @@ -6627,6 +6628,9 @@ zsetstrokecolor(i_ctx_t * i_ctx_p) if (code >= 0) return o_push_estack; + /* Something went wrong, swap back to the non-stroking colour and restore the exec stack */ + esp = iesp; + (void)zswapcolors(i_ctx_p); return code; } static int @@ -6638,6 +6642,7 @@ static int zsetstrokecolorspace(i_ctx_t * i_ctx_p) { int code; + es_ptr iesp = esp; /* preserve exec stack in case of error */ code = zswapcolors(i_ctx_p); if (code < 0) @@ -6653,6 +6658,9 @@ zsetstrokecolorspace(i_ctx_t * i_ctx_p) if (code >= 0) return o_push_estack; + /* Something went wrong, swap back to the non-stroking space and restore the exec stack */ + esp = iesp; + (void)zswapcolors(i_ctx_p); return code; }
CWE-119
null
null
2,561
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; }
Overflow
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; }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,562
fd_read_line (int fd) { return fd_read_hunk (fd, line_terminator, 128, FD_READ_LINE_MAX); }
Overflow
0
fd_read_line (int fd) { return fd_read_hunk (fd, line_terminator, 128, FD_READ_LINE_MAX); }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,563
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); }
Overflow
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); }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,564
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; }
Overflow
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; }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,565
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); }
Overflow
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); }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,566
limit_bandwidth_reset (void) { xzero (limit_data); }
Overflow
0
limit_bandwidth_reset (void) { xzero (limit_data); }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,567
no_proxy_match (const char *host, const char **no_proxy) { if (!no_proxy) return false; else return sufmatch (no_proxy, host); }
Overflow
0
no_proxy_match (const char *host, const char **no_proxy) { if (!no_proxy) return false; else return sufmatch (no_proxy, host); }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,568
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; }
Overflow
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; }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,569
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; }
Overflow
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; }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,570
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; }
Overflow
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; }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,571
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); } } }
Overflow
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); } } }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,572
write_data (FILE *out, FILE *out2, const char *buf, int bufsize, wgint *skip, wgint *written) { if (out == NULL && out2 == NULL) return 1; if (*skip > bufsize) { *skip -= bufsize; return 1; } if (*skip) { buf += *skip; bufsize -= *skip; *skip = 0; if (bufsize == 0) return 1; } if (out != NULL) fwrite (buf, 1, bufsize, out); if (out2 != NULL) fwrite (buf, 1, bufsize, out2); *written += bufsize; /* Immediately flush the downloaded data. This should not hinder performance: fast downloads will arrive in large 16K chunks (which stdio would write out immediately anyway), and slow downloads wouldn't be limited by disk speed. */ /* 2005-04-20 SMS. Perhaps it shouldn't hinder performance, but it sure does, at least on VMS (more than 2X). Rather than speculate on what it should or shouldn't do, it might make more sense to test it. Even better, it might be nice to explain what possible benefit it could offer, as it appears to be a clear invitation to poor performance with no actual justification. (Also, why 16K? Anyone test other values?) */ #ifndef __VMS if (out != NULL) fflush (out); if (out2 != NULL) fflush (out2); #endif /* ndef __VMS */ if (out != NULL && ferror (out)) return -1; else if (out2 != NULL && ferror (out2)) return -2; else return 0; }
Overflow
0
write_data (FILE *out, FILE *out2, const char *buf, int bufsize, wgint *skip, wgint *written) { if (out == NULL && out2 == NULL) return 1; if (*skip > bufsize) { *skip -= bufsize; return 1; } if (*skip) { buf += *skip; bufsize -= *skip; *skip = 0; if (bufsize == 0) return 1; } if (out != NULL) fwrite (buf, 1, bufsize, out); if (out2 != NULL) fwrite (buf, 1, bufsize, out2); *written += bufsize; /* Immediately flush the downloaded data. This should not hinder performance: fast downloads will arrive in large 16K chunks (which stdio would write out immediately anyway), and slow downloads wouldn't be limited by disk speed. */ /* 2005-04-20 SMS. Perhaps it shouldn't hinder performance, but it sure does, at least on VMS (more than 2X). Rather than speculate on what it should or shouldn't do, it might make more sense to test it. Even better, it might be nice to explain what possible benefit it could offer, as it appears to be a clear invitation to poor performance with no actual justification. (Also, why 16K? Anyone test other values?) */ #ifndef __VMS if (out != NULL) fflush (out); if (out2 != NULL) fflush (out2); #endif /* ndef __VMS */ if (out != NULL && ferror (out)) return -1; else if (out2 != NULL && ferror (out2)) return -2; else return 0; }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,573
zalloc (voidpf opaque, unsigned int items, unsigned int size) { (void) opaque; return (voidpf) xcalloc (items, size); }
Overflow
0
zalloc (voidpf opaque, unsigned int items, unsigned int size) { (void) opaque; return (voidpf) xcalloc (items, size); }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,574
zfree (voidpf opaque, voidpf address) { (void) opaque; xfree (address); }
Overflow
0
zfree (voidpf opaque, voidpf address) { (void) opaque; xfree (address); }
@@ -378,6 +378,12 @@ fd_read_body (const char *downloaded_filename, int fd, FILE *out, wgint toread, remaining_chunk_size = strtol (line, &endl, 16); xfree (line); + if (remaining_chunk_size < 0) + { + ret = -1; + break; + } + if (remaining_chunk_size == 0) { ret = 0;
CWE-119
null
null
2,575
void aes_crypt_cbc( aes_context *ctx, int mode, int length, unsigned char iv[16], const unsigned char *input, unsigned char *output ) { int i; unsigned char temp[16]; #if defined(XYSSL_PADLOCK_C) && defined(XYSSL_HAVE_X86) if( padlock_supports( PADLOCK_ACE ) ) { if( padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 ) return; } #endif if( mode == AES_DECRYPT ) { while( length > 0 ) { memcpy( temp, input, 16 ); aes_crypt_ecb( ctx, mode, input, output ); for( i = 0; i < 16; i++ ) output[i] = (unsigned char)( output[i] ^ iv[i] ); memcpy( iv, temp, 16 ); input += 16; output += 16; length -= 16; } } else { while( length > 0 ) { for( i = 0; i < 16; i++ ) output[i] = (unsigned char)( input[i] ^ iv[i] ); aes_crypt_ecb( ctx, mode, output, output ); memcpy( iv, output, 16 ); input += 16; output += 16; length -= 16; } } }
Exec Code Overflow
0
void aes_crypt_cbc( aes_context *ctx, int mode, int length, unsigned char iv[16], const unsigned char *input, unsigned char *output ) { int i; unsigned char temp[16]; #if defined(XYSSL_PADLOCK_C) && defined(XYSSL_HAVE_X86) if( padlock_supports( PADLOCK_ACE ) ) { if( padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 ) return; } #endif if( mode == AES_DECRYPT ) { while( length > 0 ) { memcpy( temp, input, 16 ); aes_crypt_ecb( ctx, mode, input, output ); for( i = 0; i < 16; i++ ) output[i] = (unsigned char)( output[i] ^ iv[i] ); memcpy( iv, temp, 16 ); input += 16; output += 16; length -= 16; } } else { while( length > 0 ) { for( i = 0; i < 16; i++ ) output[i] = (unsigned char)( input[i] ^ iv[i] ); aes_crypt_ecb( ctx, mode, output, output ); memcpy( iv, output, 16 ); input += 16; output += 16; length -= 16; } } }
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx, } #endif + if (ctx == NULL || ctx->rk == NULL) + return; + RK = ctx->rk; GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
CWE-119
null
null
2,576
void aes_crypt_cfb( aes_context *ctx, int mode, int length, int *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output ) { int c, n = *iv_off; if( mode == AES_DECRYPT ) { while( length-- ) { if( n == 0 ) aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); c = *input++; *output++ = (unsigned char)( c ^ iv[n] ); iv[n] = (unsigned char) c; n = (n + 1) & 0x0F; } } else { while( length-- ) { if( n == 0 ) aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); n = (n + 1) & 0x0F; } } *iv_off = n; }
Exec Code Overflow
0
void aes_crypt_cfb( aes_context *ctx, int mode, int length, int *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output ) { int c, n = *iv_off; if( mode == AES_DECRYPT ) { while( length-- ) { if( n == 0 ) aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); c = *input++; *output++ = (unsigned char)( c ^ iv[n] ); iv[n] = (unsigned char) c; n = (n + 1) & 0x0F; } } else { while( length-- ) { if( n == 0 ) aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); n = (n + 1) & 0x0F; } } *iv_off = n; }
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx, } #endif + if (ctx == NULL || ctx->rk == NULL) + return; + RK = ctx->rk; GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
CWE-119
null
null
2,577
static void aes_gen_tables( void ) { int i, x, y, z; int pow[256]; int log[256]; /* * compute pow and log tables over GF(2^8) */ for( i = 0, x = 1; i < 256; i++ ) { pow[i] = x; log[x] = i; x = ( x ^ XTIME( x ) ) & 0xFF; } /* * calculate the round constants */ for( i = 0, x = 1; i < 10; i++ ) { RCON[i] = (unsigned long) x; x = XTIME( x ) & 0xFF; } /* * generate the forward and reverse S-boxes */ FSb[0x00] = 0x63; RSb[0x63] = 0x00; for( i = 1; i < 256; i++ ) { x = pow[255 - log[i]]; y = x; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y ^ 0x63; FSb[i] = (unsigned char) x; RSb[x] = (unsigned char) i; } /* * generate the forward and reverse tables */ for( i = 0; i < 256; i++ ) { x = FSb[i]; y = XTIME( x ) & 0xFF; z = ( y ^ x ) & 0xFF; FT0[i] = ( (unsigned long) y ) ^ ( (unsigned long) x << 8 ) ^ ( (unsigned long) x << 16 ) ^ ( (unsigned long) z << 24 ); FT1[i] = ROTL8( FT0[i] ); FT2[i] = ROTL8( FT1[i] ); FT3[i] = ROTL8( FT2[i] ); x = RSb[i]; RT0[i] = ( (unsigned long) MUL( 0x0E, x ) ) ^ ( (unsigned long) MUL( 0x09, x ) << 8 ) ^ ( (unsigned long) MUL( 0x0D, x ) << 16 ) ^ ( (unsigned long) MUL( 0x0B, x ) << 24 ); RT1[i] = ROTL8( RT0[i] ); RT2[i] = ROTL8( RT1[i] ); RT3[i] = ROTL8( RT2[i] ); } }
Exec Code Overflow
0
static void aes_gen_tables( void ) { int i, x, y, z; int pow[256]; int log[256]; /* * compute pow and log tables over GF(2^8) */ for( i = 0, x = 1; i < 256; i++ ) { pow[i] = x; log[x] = i; x = ( x ^ XTIME( x ) ) & 0xFF; } /* * calculate the round constants */ for( i = 0, x = 1; i < 10; i++ ) { RCON[i] = (unsigned long) x; x = XTIME( x ) & 0xFF; } /* * generate the forward and reverse S-boxes */ FSb[0x00] = 0x63; RSb[0x63] = 0x00; for( i = 1; i < 256; i++ ) { x = pow[255 - log[i]]; y = x; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF; x ^= y ^ 0x63; FSb[i] = (unsigned char) x; RSb[x] = (unsigned char) i; } /* * generate the forward and reverse tables */ for( i = 0; i < 256; i++ ) { x = FSb[i]; y = XTIME( x ) & 0xFF; z = ( y ^ x ) & 0xFF; FT0[i] = ( (unsigned long) y ) ^ ( (unsigned long) x << 8 ) ^ ( (unsigned long) x << 16 ) ^ ( (unsigned long) z << 24 ); FT1[i] = ROTL8( FT0[i] ); FT2[i] = ROTL8( FT1[i] ); FT3[i] = ROTL8( FT2[i] ); x = RSb[i]; RT0[i] = ( (unsigned long) MUL( 0x0E, x ) ) ^ ( (unsigned long) MUL( 0x09, x ) << 8 ) ^ ( (unsigned long) MUL( 0x0D, x ) << 16 ) ^ ( (unsigned long) MUL( 0x0B, x ) << 24 ); RT1[i] = ROTL8( RT0[i] ); RT2[i] = ROTL8( RT1[i] ); RT3[i] = ROTL8( RT2[i] ); } }
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx, } #endif + if (ctx == NULL || ctx->rk == NULL) + return; + RK = ctx->rk; GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
CWE-119
null
null
2,578
int aes_self_test( int verbose ) { int i, j, u, v, offset; unsigned char key[32]; unsigned char buf[16]; unsigned char prv[16]; unsigned char iv[16]; aes_context ctx; memset( key, 0, 32 ); /* * ECB mode */ for( i = 0; i < 6; i++ ) { u = i >> 1; v = i & 1; if( verbose != 0 ) printf( " AES-ECB-%3d (%s): ", 128 + u * 64, ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( buf, 0, 16 ); if( v == AES_DECRYPT ) { aes_setkey_dec( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_ecb( &ctx, v, buf, buf ); if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } else { aes_setkey_enc( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_ecb( &ctx, v, buf, buf ); if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) printf( "passed\n" ); } if( verbose != 0 ) printf( "\n" ); /* * CBC mode */ for( i = 0; i < 6; i++ ) { u = i >> 1; v = i & 1; if( verbose != 0 ) printf( " AES-CBC-%3d (%s): ", 128 + u * 64, ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( iv , 0, 16 ); memset( prv, 0, 16 ); memset( buf, 0, 16 ); if( v == AES_DECRYPT ) { aes_setkey_dec( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } else { aes_setkey_enc( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) { unsigned char tmp[16]; aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); memcpy( tmp, prv, 16 ); memcpy( prv, buf, 16 ); memcpy( buf, tmp, 16 ); } if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) printf( "passed\n" ); } if( verbose != 0 ) printf( "\n" ); /* * CFB mode */ for( i = 0; i < 6; i++ ) { u = i >> 1; v = i & 1; if( verbose != 0 ) printf( " AES-CFB-%3d (%s): ", 128 + u * 64, ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( iv , 0, 16 ); memset( buf, 0, 16 ); offset = 0; if( v == AES_DECRYPT ) { aes_setkey_dec( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); if( memcmp( buf, aes_test_cfb_dec[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } else { aes_setkey_enc( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); if( memcmp( buf, aes_test_cfb_enc[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) printf( "passed\n" ); } if( verbose != 0 ) printf( "\n" ); return( 0 ); }
Exec Code Overflow
0
int aes_self_test( int verbose ) { int i, j, u, v, offset; unsigned char key[32]; unsigned char buf[16]; unsigned char prv[16]; unsigned char iv[16]; aes_context ctx; memset( key, 0, 32 ); /* * ECB mode */ for( i = 0; i < 6; i++ ) { u = i >> 1; v = i & 1; if( verbose != 0 ) printf( " AES-ECB-%3d (%s): ", 128 + u * 64, ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( buf, 0, 16 ); if( v == AES_DECRYPT ) { aes_setkey_dec( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_ecb( &ctx, v, buf, buf ); if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } else { aes_setkey_enc( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_ecb( &ctx, v, buf, buf ); if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) printf( "passed\n" ); } if( verbose != 0 ) printf( "\n" ); /* * CBC mode */ for( i = 0; i < 6; i++ ) { u = i >> 1; v = i & 1; if( verbose != 0 ) printf( " AES-CBC-%3d (%s): ", 128 + u * 64, ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( iv , 0, 16 ); memset( prv, 0, 16 ); memset( buf, 0, 16 ); if( v == AES_DECRYPT ) { aes_setkey_dec( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } else { aes_setkey_enc( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) { unsigned char tmp[16]; aes_crypt_cbc( &ctx, v, 16, iv, buf, buf ); memcpy( tmp, prv, 16 ); memcpy( prv, buf, 16 ); memcpy( buf, tmp, 16 ); } if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) printf( "passed\n" ); } if( verbose != 0 ) printf( "\n" ); /* * CFB mode */ for( i = 0; i < 6; i++ ) { u = i >> 1; v = i & 1; if( verbose != 0 ) printf( " AES-CFB-%3d (%s): ", 128 + u * 64, ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( iv , 0, 16 ); memset( buf, 0, 16 ); offset = 0; if( v == AES_DECRYPT ) { aes_setkey_dec( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); if( memcmp( buf, aes_test_cfb_dec[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } else { aes_setkey_enc( &ctx, key, 128 + u * 64 ); for( j = 0; j < 10000; j++ ) aes_crypt_cfb( &ctx, v, 16, &offset, iv, buf, buf ); if( memcmp( buf, aes_test_cfb_enc[u], 16 ) != 0 ) { if( verbose != 0 ) printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) printf( "passed\n" ); } if( verbose != 0 ) printf( "\n" ); return( 0 ); }
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx, } #endif + if (ctx == NULL || ctx->rk == NULL) + return; + RK = ctx->rk; GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
CWE-119
null
null
2,579
void aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize ) { int i, j; aes_context cty; unsigned long *RK; unsigned long *SK; switch( keysize ) { case 128: ctx->nr = 10; break; case 192: ctx->nr = 12; break; case 256: ctx->nr = 14; break; default : return; } #if defined(PADLOCK_ALIGN16) ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); #else ctx->rk = RK = ctx->buf; #endif aes_setkey_enc( &cty, key, keysize ); SK = cty.rk + cty.nr * 4; *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; for( i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8 ) { for( j = 0; j < 4; j++, SK++ ) { *RK++ = RT0[ FSb[ ( *SK ) & 0xFF ] ] ^ RT1[ FSb[ ( *SK >> 8 ) & 0xFF ] ] ^ RT2[ FSb[ ( *SK >> 16 ) & 0xFF ] ] ^ RT3[ FSb[ ( *SK >> 24 ) & 0xFF ] ]; } } *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; memset( &cty, 0, sizeof( aes_context ) ); }
Exec Code Overflow
0
void aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize ) { int i, j; aes_context cty; unsigned long *RK; unsigned long *SK; switch( keysize ) { case 128: ctx->nr = 10; break; case 192: ctx->nr = 12; break; case 256: ctx->nr = 14; break; default : return; } #if defined(PADLOCK_ALIGN16) ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); #else ctx->rk = RK = ctx->buf; #endif aes_setkey_enc( &cty, key, keysize ); SK = cty.rk + cty.nr * 4; *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; for( i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8 ) { for( j = 0; j < 4; j++, SK++ ) { *RK++ = RT0[ FSb[ ( *SK ) & 0xFF ] ] ^ RT1[ FSb[ ( *SK >> 8 ) & 0xFF ] ] ^ RT2[ FSb[ ( *SK >> 16 ) & 0xFF ] ] ^ RT3[ FSb[ ( *SK >> 24 ) & 0xFF ] ]; } } *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; *RK++ = *SK++; memset( &cty, 0, sizeof( aes_context ) ); }
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx, } #endif + if (ctx == NULL || ctx->rk == NULL) + return; + RK = ctx->rk; GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
CWE-119
null
null
2,580
void aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize ) { int i; unsigned long *RK; #if !defined(XYSSL_AES_ROM_TABLES) if( aes_init_done == 0 ) { aes_gen_tables(); aes_init_done = 1; } #endif switch( keysize ) { case 128: ctx->nr = 10; break; case 192: ctx->nr = 12; break; case 256: ctx->nr = 14; break; default : return; } #if defined(PADLOCK_ALIGN16) ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); #else ctx->rk = RK = ctx->buf; #endif for( i = 0; i < (keysize >> 5); i++ ) { GET_ULONG_LE( RK[i], key, i << 2 ); } switch( ctx->nr ) { case 10: for( i = 0; i < 10; i++, RK += 4 ) { RK[4] = RK[0] ^ RCON[i] ^ ( FSb[ ( RK[3] >> 8 ) & 0xFF ] ) ^ ( FSb[ ( RK[3] >> 16 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[3] >> 24 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[3] ) & 0xFF ]) << 24 ); RK[5] = RK[1] ^ RK[4]; RK[6] = RK[2] ^ RK[5]; RK[7] = RK[3] ^ RK[6]; } break; case 12: for( i = 0; i < 8; i++, RK += 6 ) { RK[6] = RK[0] ^ RCON[i] ^ ( FSb[ ( RK[5] >> 8 ) & 0xFF ] ) ^ ( FSb[ ( RK[5] >> 16 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[5] >> 24 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[5] ) & 0xFF ]) << 24 ); RK[7] = RK[1] ^ RK[6]; RK[8] = RK[2] ^ RK[7]; RK[9] = RK[3] ^ RK[8]; RK[10] = RK[4] ^ RK[9]; RK[11] = RK[5] ^ RK[10]; } break; case 14: for( i = 0; i < 7; i++, RK += 8 ) { RK[8] = RK[0] ^ RCON[i] ^ ( FSb[ ( RK[7] >> 8 ) & 0xFF ] ) ^ ( FSb[ ( RK[7] >> 16 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[7] >> 24 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[7] ) & 0xFF ]) << 24 ); RK[9] = RK[1] ^ RK[8]; RK[10] = RK[2] ^ RK[9]; RK[11] = RK[3] ^ RK[10]; RK[12] = RK[4] ^ ( FSb[ ( RK[11] ) & 0xFF ] ) ^ ( FSb[ ( RK[11] >> 8 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[11] >> 16 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[11] >> 24 ) & 0xFF ]) << 24 ); RK[13] = RK[5] ^ RK[12]; RK[14] = RK[6] ^ RK[13]; RK[15] = RK[7] ^ RK[14]; } break; default: break; } }
Exec Code Overflow
0
void aes_setkey_enc( aes_context *ctx, const unsigned char *key, int keysize ) { int i; unsigned long *RK; #if !defined(XYSSL_AES_ROM_TABLES) if( aes_init_done == 0 ) { aes_gen_tables(); aes_init_done = 1; } #endif switch( keysize ) { case 128: ctx->nr = 10; break; case 192: ctx->nr = 12; break; case 256: ctx->nr = 14; break; default : return; } #if defined(PADLOCK_ALIGN16) ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf ); #else ctx->rk = RK = ctx->buf; #endif for( i = 0; i < (keysize >> 5); i++ ) { GET_ULONG_LE( RK[i], key, i << 2 ); } switch( ctx->nr ) { case 10: for( i = 0; i < 10; i++, RK += 4 ) { RK[4] = RK[0] ^ RCON[i] ^ ( FSb[ ( RK[3] >> 8 ) & 0xFF ] ) ^ ( FSb[ ( RK[3] >> 16 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[3] >> 24 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[3] ) & 0xFF ]) << 24 ); RK[5] = RK[1] ^ RK[4]; RK[6] = RK[2] ^ RK[5]; RK[7] = RK[3] ^ RK[6]; } break; case 12: for( i = 0; i < 8; i++, RK += 6 ) { RK[6] = RK[0] ^ RCON[i] ^ ( FSb[ ( RK[5] >> 8 ) & 0xFF ] ) ^ ( FSb[ ( RK[5] >> 16 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[5] >> 24 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[5] ) & 0xFF ]) << 24 ); RK[7] = RK[1] ^ RK[6]; RK[8] = RK[2] ^ RK[7]; RK[9] = RK[3] ^ RK[8]; RK[10] = RK[4] ^ RK[9]; RK[11] = RK[5] ^ RK[10]; } break; case 14: for( i = 0; i < 7; i++, RK += 8 ) { RK[8] = RK[0] ^ RCON[i] ^ ( FSb[ ( RK[7] >> 8 ) & 0xFF ] ) ^ ( FSb[ ( RK[7] >> 16 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[7] >> 24 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[7] ) & 0xFF ]) << 24 ); RK[9] = RK[1] ^ RK[8]; RK[10] = RK[2] ^ RK[9]; RK[11] = RK[3] ^ RK[10]; RK[12] = RK[4] ^ ( FSb[ ( RK[11] ) & 0xFF ] ) ^ ( FSb[ ( RK[11] >> 8 ) & 0xFF ] << 8 ) ^ ( FSb[ ( RK[11] >> 16 ) & 0xFF ] << 16 ) ^ ( ((unsigned int)FSb[ ( RK[11] >> 24 ) & 0xFF ]) << 24 ); RK[13] = RK[5] ^ RK[12]; RK[14] = RK[6] ^ RK[13]; RK[15] = RK[7] ^ RK[14]; } break; default: break; } }
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx, } #endif + if (ctx == NULL || ctx->rk == NULL) + return; + RK = ctx->rk; GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
CWE-119
null
null
2,581
int main(int argc, char *argv[]) { return aes_self_test(1); }
Exec Code Overflow
0
int main(int argc, char *argv[]) { return aes_self_test(1); }
@@ -662,6 +662,9 @@ void aes_crypt_ecb( aes_context *ctx, } #endif + if (ctx == NULL || ctx->rk == NULL) + return; + RK = ctx->rk; GET_ULONG_LE( X0, input, 0 ); X0 ^= *RK++;
CWE-119
null
null
2,582
s_aes_release(stream_state *ss) { stream_aes_state *const state = (stream_aes_state *) ss; if (state->ctx != NULL) gs_free_object(state->memory, state->ctx, "aes context structure"); }
Exec Code Overflow
0
s_aes_release(stream_state *ss) { stream_aes_state *const state = (stream_aes_state *) ss; if (state->ctx != NULL) gs_free_object(state->memory, state->ctx, "aes context structure"); }
@@ -120,6 +120,7 @@ s_aes_process(stream_state * ss, stream_cursor_read * pr, gs_throw(gs_error_VMerror, "could not allocate aes context"); return ERRC; } + memset(state->ctx, 0x00, sizeof(aes_context)); if (state->keylength < 1 || state->keylength > SAES_MAX_KEYLENGTH) { gs_throw1(gs_error_rangecheck, "invalid aes key length (%d bytes)", state->keylength);
CWE-119
null
null
2,583
s_aes_set_key(stream_aes_state * state, const unsigned char *key, int keylength) { int code = 0; if ( (keylength < 1) || (keylength > SAES_MAX_KEYLENGTH) ) return_error(gs_error_rangecheck); if (key == NULL) return_error(gs_error_invalidaccess); /* we can't set the key here because the interpreter's filter implementation wants to duplicate our state after the zfaes.c binding calls us. So stash it now and handle it in our process method. */ memcpy(state->key, key, keylength); state->keylength = keylength; if (code) { return gs_throw(gs_error_rangecheck, "could not set AES key"); } /* return successfully */ return 0; }
Exec Code Overflow
0
s_aes_set_key(stream_aes_state * state, const unsigned char *key, int keylength) { int code = 0; if ( (keylength < 1) || (keylength > SAES_MAX_KEYLENGTH) ) return_error(gs_error_rangecheck); if (key == NULL) return_error(gs_error_invalidaccess); /* we can't set the key here because the interpreter's filter implementation wants to duplicate our state after the zfaes.c binding calls us. So stash it now and handle it in our process method. */ memcpy(state->key, key, keylength); state->keylength = keylength; if (code) { return gs_throw(gs_error_rangecheck, "could not set AES key"); } /* return successfully */ return 0; }
@@ -120,6 +120,7 @@ s_aes_process(stream_state * ss, stream_cursor_read * pr, gs_throw(gs_error_VMerror, "could not allocate aes context"); return ERRC; } + memset(state->ctx, 0x00, sizeof(aes_context)); if (state->keylength < 1 || state->keylength > SAES_MAX_KEYLENGTH) { gs_throw1(gs_error_rangecheck, "invalid aes key length (%d bytes)", state->keylength);
CWE-119
null
null
2,584
s_aes_set_padding(stream_aes_state *state, int use_padding) { state->use_padding = use_padding; }
Exec Code Overflow
0
s_aes_set_padding(stream_aes_state *state, int use_padding) { state->use_padding = use_padding; }
@@ -120,6 +120,7 @@ s_aes_process(stream_state * ss, stream_cursor_read * pr, gs_throw(gs_error_VMerror, "could not allocate aes context"); return ERRC; } + memset(state->ctx, 0x00, sizeof(aes_context)); if (state->keylength < 1 || state->keylength > SAES_MAX_KEYLENGTH) { gs_throw1(gs_error_rangecheck, "invalid aes key length (%d bytes)", state->keylength);
CWE-119
null
null
2,585
gdev_pdf_get_param(gx_device *dev, char *Param, void *list) { gx_device_pdf *pdev = (gx_device_pdf *)dev; const gs_param_item_t *pi; gs_param_list * plist = (gs_param_list *)list; int code = 0; for (pi = pdf_param_items; pi->key != 0; ++pi) { if (strcmp(pi->key, Param) == 0) { const char *key = pi->key; const void *pvalue = (const void *)((const char *)pdev + pi->offset); int size = xfer_item_sizes[pi->type]; gs_param_typed_value typed; memcpy(&typed.value, pvalue, size); typed.type = pi->type; code = (*plist->procs->xmit_typed) (plist, key, &typed); return code; } } if (strcmp(Param, "CoreDistVersion") == 0) { return(param_write_int(plist, "CoreDistVersion", &CoreDistVersion)); } if (strcmp(Param, "CompatibilityLevel") == 0) { float f = pdev->CompatibilityLevel; return(param_write_float(plist, "CompatibilityLevel", &f)); } if (strcmp(Param, "ForOPDFRead") == 0) { return(param_write_bool(plist, "ForOPDFRead", &pdev->ForOPDFRead)); } if (!pdev->is_ps2write) { if (strcmp(Param, "pdfmark") == 0){ return(param_write_null(plist, "pdfmark")); } if (strcmp(Param, "DSC") == 0){ return(param_write_null(plist, "DSC")); } } return gdev_psdf_get_param(dev, Param, list); }
Exec Code
0
gdev_pdf_get_param(gx_device *dev, char *Param, void *list) { gx_device_pdf *pdev = (gx_device_pdf *)dev; const gs_param_item_t *pi; gs_param_list * plist = (gs_param_list *)list; int code = 0; for (pi = pdf_param_items; pi->key != 0; ++pi) { if (strcmp(pi->key, Param) == 0) { const char *key = pi->key; const void *pvalue = (const void *)((const char *)pdev + pi->offset); int size = xfer_item_sizes[pi->type]; gs_param_typed_value typed; memcpy(&typed.value, pvalue, size); typed.type = pi->type; code = (*plist->procs->xmit_typed) (plist, key, &typed); return code; } } if (strcmp(Param, "CoreDistVersion") == 0) { return(param_write_int(plist, "CoreDistVersion", &CoreDistVersion)); } if (strcmp(Param, "CompatibilityLevel") == 0) { float f = pdev->CompatibilityLevel; return(param_write_float(plist, "CompatibilityLevel", &f)); } if (strcmp(Param, "ForOPDFRead") == 0) { return(param_write_bool(plist, "ForOPDFRead", &pdev->ForOPDFRead)); } if (!pdev->is_ps2write) { if (strcmp(Param, "pdfmark") == 0){ return(param_write_null(plist, "pdfmark")); } if (strcmp(Param, "DSC") == 0){ return(param_write_null(plist, "DSC")); } } return gdev_psdf_get_param(dev, Param, list); }
@@ -364,7 +364,7 @@ gdev_pdf_put_params_impl(gx_device * dev, const gx_device_pdf * save_dev, gs_par * LockDistillerParams is read again, and reset if necessary, in * psdf_put_params. */ - ecode = param_read_bool(plist, "LockDistillerParams", &locked); + ecode = param_read_bool(plist, (param_name = "LockDistillerParams"), &locked); if (ecode < 0) param_signal_error(plist, param_name, ecode);
CWE-704
null
null
2,586
gdev_pdf_put_params(gx_device * dev, gs_param_list * plist) { int code; gx_device_pdf *pdev = (gx_device_pdf *) dev; gs_memory_t *mem = gs_memory_stable(pdev->memory); gx_device_pdf *save_dev = gs_malloc(mem, sizeof(gx_device_pdf), 1, "saved gx_device_pdf"); if (!save_dev) return_error(gs_error_VMerror); memcpy(save_dev, pdev, sizeof(gx_device_pdf)); code = gdev_pdf_put_params_impl(dev, save_dev, plist); gs_free(mem, save_dev, sizeof(gx_device_pdf), 1, "saved gx_device_pdf"); return code; }
Exec Code
0
gdev_pdf_put_params(gx_device * dev, gs_param_list * plist) { int code; gx_device_pdf *pdev = (gx_device_pdf *) dev; gs_memory_t *mem = gs_memory_stable(pdev->memory); gx_device_pdf *save_dev = gs_malloc(mem, sizeof(gx_device_pdf), 1, "saved gx_device_pdf"); if (!save_dev) return_error(gs_error_VMerror); memcpy(save_dev, pdev, sizeof(gx_device_pdf)); code = gdev_pdf_put_params_impl(dev, save_dev, plist); gs_free(mem, save_dev, sizeof(gx_device_pdf), 1, "saved gx_device_pdf"); return code; }
@@ -364,7 +364,7 @@ gdev_pdf_put_params_impl(gx_device * dev, const gx_device_pdf * save_dev, gs_par * LockDistillerParams is read again, and reset if necessary, in * psdf_put_params. */ - ecode = param_read_bool(plist, "LockDistillerParams", &locked); + ecode = param_read_bool(plist, (param_name = "LockDistillerParams"), &locked); if (ecode < 0) param_signal_error(plist, param_name, ecode);
CWE-704
null
null
2,587
static int unescape_octals(gx_device_pdf * pdev, char *src, int size) { char *start, *dest; start = src; dest = src; while(size) { if (size > 4 && src[0] == '\\' && src[1] == '\\' && src[2] > 0x29 && src[2] < 0x35 && src[3] > 0x29 &&src[3] < 0x38 && src[4] > 0x29 && src[4] < 0x38) { src++; size--; } else { *dest++ = *src++; size--; } } return (dest - start); }
Exec Code
0
static int unescape_octals(gx_device_pdf * pdev, char *src, int size) { char *start, *dest; start = src; dest = src; while(size) { if (size > 4 && src[0] == '\\' && src[1] == '\\' && src[2] > 0x29 && src[2] < 0x35 && src[3] > 0x29 &&src[3] < 0x38 && src[4] > 0x29 && src[4] < 0x38) { src++; size--; } else { *dest++ = *src++; size--; } } return (dest - start); }
@@ -364,7 +364,7 @@ gdev_pdf_put_params_impl(gx_device * dev, const gx_device_pdf * save_dev, gs_par * LockDistillerParams is read again, and reset if necessary, in * psdf_put_params. */ - ecode = param_read_bool(plist, "LockDistillerParams", &locked); + ecode = param_read_bool(plist, (param_name = "LockDistillerParams"), &locked); if (ecode < 0) param_signal_error(plist, param_name, ecode);
CWE-704
null
null
2,588
array_indexed_param_list_read(dict_param_list * plist, const ref * parray, const ref * ppolicies, bool require_all, gs_ref_memory_t *ref_memory) { iparam_list *const iplist = (iparam_list *) plist; int code; check_read_type(*parray, t_array); plist->u.r.read = array_indexed_param_read; plist->dict = *parray; code = ref_param_read_init(iplist, r_size(parray), ppolicies, require_all, ref_memory); plist->int_keys = true; return code; }
Exec Code
0
array_indexed_param_list_read(dict_param_list * plist, const ref * parray, const ref * ppolicies, bool require_all, gs_ref_memory_t *ref_memory) { iparam_list *const iplist = (iparam_list *) plist; int code; check_read_type(*parray, t_array); plist->u.r.read = array_indexed_param_read; plist->dict = *parray; code = ref_param_read_init(iplist, r_size(parray), ppolicies, require_all, ref_memory); plist->int_keys = true; return code; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,589
array_indexed_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { ref *const arr = &((dict_param_list *) plist)->dict; check_type(*pkey, t_integer); if (pkey->value.intval < 0 || pkey->value.intval >= r_size(arr)) return 1; ploc->pvalue = arr->value.refs + pkey->value.intval; ploc->presult = &plist->results[pkey->value.intval]; *ploc->presult = 1; return 0; }
Exec Code
0
array_indexed_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { ref *const arr = &((dict_param_list *) plist)->dict; check_type(*pkey, t_integer); if (pkey->value.intval < 0 || pkey->value.intval >= r_size(arr)) return 1; ploc->pvalue = arr->value.refs + pkey->value.intval; ploc->presult = &plist->results[pkey->value.intval]; *ploc->presult = 1; return 0; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,590
array_new_indexed_param_write(iparam_list * iplist, const ref * pkey, const ref * pvalue) { const ref *const arr = &((dict_param_list *)iplist)->dict; ref *eltp; if (!r_has_type(pkey, t_integer)) return_error(gs_error_typecheck); check_int_ltu(*pkey, r_size(arr)); store_check_dest(arr, pvalue); eltp = arr->value.refs + pkey->value.intval; /* ref_assign_new(eltp, pvalue); */ ref_assign(eltp, pvalue); r_set_attrs(eltp, imemory_new_mask(iplist->ref_memory)); return 0; }
Exec Code
0
array_new_indexed_param_write(iparam_list * iplist, const ref * pkey, const ref * pvalue) { const ref *const arr = &((dict_param_list *)iplist)->dict; ref *eltp; if (!r_has_type(pkey, t_integer)) return_error(gs_error_typecheck); check_int_ltu(*pkey, r_size(arr)); store_check_dest(arr, pvalue); eltp = arr->value.refs + pkey->value.intval; /* ref_assign_new(eltp, pvalue); */ ref_assign(eltp, pvalue); r_set_attrs(eltp, imemory_new_mask(iplist->ref_memory)); return 0; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,591
array_new_indexed_plist_write(dict_param_list * plist, ref * parray, const ref * pwanted, gs_ref_memory_t *imem) { check_array(*parray); check_write(*parray); plist->u.w.write = array_new_indexed_param_write; ref_param_write_init((iparam_list *) plist, pwanted, imem); plist->dict = *parray; plist->int_keys = true; return 0; }
Exec Code
0
array_new_indexed_plist_write(dict_param_list * plist, ref * parray, const ref * pwanted, gs_ref_memory_t *imem) { check_array(*parray); check_write(*parray); plist->u.w.write = array_new_indexed_param_write; ref_param_write_init((iparam_list *) plist, pwanted, imem); plist->dict = *parray; plist->int_keys = true; return 0; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,592
array_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum, gs_param_key_t * key, ref_type * type) { int index = penum->intval; ref *bot = ((array_param_list *) plist)->bot; ref *ptr = bot + index; ref *top = ((array_param_list *) plist)->top; for (; ptr < top; ptr += 2) { index += 2; if (r_has_type(ptr, t_name)) { int code = ref_to_key(ptr, key, plist); *type = r_type(ptr); penum->intval = index; return code; } } return 1; }
Exec Code
0
array_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum, gs_param_key_t * key, ref_type * type) { int index = penum->intval; ref *bot = ((array_param_list *) plist)->bot; ref *ptr = bot + index; ref *top = ((array_param_list *) plist)->top; for (; ptr < top; ptr += 2) { index += 2; if (r_has_type(ptr, t_name)) { int code = ref_to_key(ptr, key, plist); *type = r_type(ptr); penum->intval = index; return code; } } return 1; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,593
array_param_list_read(array_param_list * plist, ref * bot, uint count, const ref * ppolicies, bool require_all, gs_ref_memory_t *imem) { iparam_list *const iplist = (iparam_list *) plist; if (count & 1) return_error(gs_error_rangecheck); plist->u.r.read = array_param_read; plist->enumerate = array_param_enumerate; plist->bot = bot; plist->top = bot + count; return ref_param_read_init(iplist, count, ppolicies, require_all, imem); }
Exec Code
0
array_param_list_read(array_param_list * plist, ref * bot, uint count, const ref * ppolicies, bool require_all, gs_ref_memory_t *imem) { iparam_list *const iplist = (iparam_list *) plist; if (count & 1) return_error(gs_error_rangecheck); plist->u.r.read = array_param_read; plist->enumerate = array_param_enumerate; plist->bot = bot; plist->top = bot + count; return ref_param_read_init(iplist, count, ppolicies, require_all, imem); }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,594
array_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { ref *bot = ((array_param_list *) plist)->bot; ref *ptr = bot; ref *top = ((array_param_list *) plist)->top; for (; ptr < top; ptr += 2) { if (r_has_type(ptr, t_name) && name_eq(ptr, pkey)) { ploc->pvalue = ptr + 1; ploc->presult = &plist->results[ptr - bot]; *ploc->presult = 1; return 0; } } return 1; }
Exec Code
0
array_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { ref *bot = ((array_param_list *) plist)->bot; ref *ptr = bot; ref *top = ((array_param_list *) plist)->top; for (; ptr < top; ptr += 2) { if (r_has_type(ptr, t_name) && name_eq(ptr, pkey)) { ploc->pvalue = ptr + 1; ploc->presult = &plist->results[ptr - bot]; *ploc->presult = 1; return 0; } } return 1; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,595
dict_param_list_read(dict_param_list * plist, const ref * pdict, const ref * ppolicies, bool require_all, gs_ref_memory_t *imem) { iparam_list *const iplist = (iparam_list *) plist; uint count; if (pdict == 0) { plist->u.r.read = empty_param_read; count = 0; } else { check_dict_read(*pdict); plist->u.r.read = dict_param_read; plist->dict = *pdict; count = dict_max_index(pdict) + 1; } plist->enumerate = dict_param_enumerate; return ref_param_read_init(iplist, count, ppolicies, require_all, imem); }
Exec Code
0
dict_param_list_read(dict_param_list * plist, const ref * pdict, const ref * ppolicies, bool require_all, gs_ref_memory_t *imem) { iparam_list *const iplist = (iparam_list *) plist; uint count; if (pdict == 0) { plist->u.r.read = empty_param_read; count = 0; } else { check_dict_read(*pdict); plist->u.r.read = dict_param_read; plist->dict = *pdict; count = dict_max_index(pdict) + 1; } plist->enumerate = dict_param_enumerate; return ref_param_read_init(iplist, count, ppolicies, require_all, imem); }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,596
dict_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { ref const *spdict = &((dict_param_list *) plist)->dict; int code = dict_find(spdict, pkey, &ploc->pvalue); if (code != 1) return 1; ploc->presult = &plist->results[dict_value_index(spdict, ploc->pvalue)]; *ploc->presult = 1; return 0; }
Exec Code
0
dict_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { ref const *spdict = &((dict_param_list *) plist)->dict; int code = dict_find(spdict, pkey, &ploc->pvalue); if (code != 1) return 1; ploc->presult = &plist->results[dict_value_index(spdict, ploc->pvalue)]; *ploc->presult = 1; return 0; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,597
dict_param_write(iparam_list * plist, const ref * pkey, const ref * pvalue) { int code = dict_put(&((dict_param_list *) plist)->dict, pkey, pvalue, NULL); return min(code, 0); }
Exec Code
0
dict_param_write(iparam_list * plist, const ref * pkey, const ref * pvalue) { int code = dict_put(&((dict_param_list *) plist)->dict, pkey, pvalue, NULL); return min(code, 0); }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,598
empty_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { return 1; }
Exec Code
0
empty_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc) { return 1; }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null
2,599
ref_array_param_requested(const iparam_list *iplist, gs_param_name pkey, ref *pvalue, uint size, client_name_t cname) { int code; if (!ref_param_requested((const gs_param_list *)iplist, pkey)) return 0; code = gs_alloc_ref_array(iplist->ref_memory, pvalue, a_all, size, cname); return (code < 0 ? code : 1); }
Exec Code
0
ref_array_param_requested(const iparam_list *iplist, gs_param_name pkey, ref *pvalue, uint size, client_name_t cname) { int code; if (!ref_param_requested((const gs_param_list *)iplist, pkey)) return 0; code = gs_alloc_ref_array(iplist->ref_memory, pvalue, a_all, size, cname); return (code < 0 ? code : 1); }
@@ -822,10 +822,11 @@ static int ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code) { iparam_list *const iplist = (iparam_list *) plist; - iparam_loc loc; + iparam_loc loc = {0}; - ref_param_read(iplist, pkey, &loc, -1); /* can't fail */ - *loc.presult = code; + ref_param_read(iplist, pkey, &loc, -1); + if (loc.presult) + *loc.presult = code; switch (ref_param_read_get_policy(plist, pkey)) { case gs_param_policy_ignore: return 0;
CWE-704
null
null