use my_strdup2() in all text object copies(txt_ptr, prop_ptr, floater_ptr, ...) to better handle corrupted input data

This commit is contained in:
stefan schippers 2023-10-09 13:39:45 +02:00
parent 94bccc08d9
commit b56ee2c998
4 changed files with 21 additions and 21 deletions

View File

@ -116,7 +116,7 @@ const char *get_text_floater(int i)
txt_ptr = xctx->text[i].floater_ptr;
} else {
/* cache floater translated text to avoid re-evaluating every time schematic is drawn */
my_strdup(_ALLOC_ID_, &xctx->text[i].floater_ptr, translate(inst, xctx->text[i].txt_ptr));
my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, translate(inst, xctx->text[i].txt_ptr));
txt_ptr = xctx->text[i].floater_ptr;
}
dbg(1, "floater: %s\n",txt_ptr);
@ -124,7 +124,7 @@ const char *get_text_floater(int i)
/* do just a tcl substitution if floater does not reference an existing instance
* (but name=something attribute must be present) and text matches tcleval(...) */
if(strstr(txt_ptr, "tcleval(") == txt_ptr) {
my_strdup(_ALLOC_ID_, &xctx->text[i].floater_ptr, tcl_hook2(xctx->text[i].txt_ptr));
my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, tcl_hook2(xctx->text[i].txt_ptr));
txt_ptr = xctx->text[i].floater_ptr;
}
}
@ -1685,11 +1685,11 @@ void copy_symbol(xSymbol *dest_sym, xSymbol *src_sym)
dest_sym->text[j].font = NULL;
dest_sym->text[j].floater_instname = NULL;
dest_sym->text[j].floater_ptr = NULL;
my_strdup(_ALLOC_ID_, &dest_sym->text[j].prop_ptr, src_sym->text[j].prop_ptr);
my_strdup(_ALLOC_ID_, &dest_sym->text[j].floater_ptr, src_sym->text[j].floater_ptr);
my_strdup2(_ALLOC_ID_, &dest_sym->text[j].prop_ptr, src_sym->text[j].prop_ptr);
my_strdup2(_ALLOC_ID_, &dest_sym->text[j].floater_ptr, src_sym->text[j].floater_ptr);
dbg(1, "copy_symbol1(): allocating sym %d text %d\n", dest_sym - xctx->sym, j);
my_strdup(_ALLOC_ID_, &dest_sym->text[j].txt_ptr, src_sym->text[j].txt_ptr);
my_strdup(_ALLOC_ID_, &dest_sym->text[j].font, src_sym->text[j].font);
my_strdup2(_ALLOC_ID_, &dest_sym->text[j].txt_ptr, src_sym->text[j].txt_ptr);
my_strdup2(_ALLOC_ID_, &dest_sym->text[j].font, src_sym->text[j].font);
my_strdup2(_ALLOC_ID_, &dest_sym->text[j].floater_instname, src_sym->text[j].floater_instname);
}
}
@ -2789,7 +2789,7 @@ void change_layer()
else if(type==xTEXT && xctx->text[n].sel==SELECTED) {
if(xctx->rectcolor != xctx->text[n].layer) {
char *p;
my_strdup(_ALLOC_ID_, &xctx->text[n].prop_ptr,
my_strdup2(_ALLOC_ID_, &xctx->text[n].prop_ptr,
subst_token(xctx->text[n].prop_ptr, "layer", dtoa(xctx->rectcolor) ));
xctx->text[n].layer = xctx->rectcolor;
p = xctx->text[n].prop_ptr;
@ -3283,7 +3283,7 @@ int create_text(int draw_text, double x, double y, int rot, int flip, const char
t->floater_ptr = NULL;
t->font=NULL;
t->floater_instname=NULL;
my_strdup(_ALLOC_ID_, &t->txt_ptr, txt);
my_strdup2(_ALLOC_ID_, &t->txt_ptr, txt);
t->x0=x;
t->y0=y;
t->rot=(short int) rot;

View File

@ -1264,7 +1264,7 @@ static int edit_text_property(int x)
}
}
}
my_strdup(_ALLOC_ID_, &xctx->text[sel].txt_ptr, (char *) tclgetvar("retval"));
my_strdup2(_ALLOC_ID_, &xctx->text[sel].txt_ptr, (char *) tclgetvar("retval"));
}
if(x==0 && props_changed) {
if(oldprop && preserve)

View File

@ -362,11 +362,11 @@ void mem_push_undo(void)
xctx->uslot[slot].tptr[i].font = NULL;
xctx->uslot[slot].tptr[i].floater_instname = NULL;
xctx->uslot[slot].tptr[i].floater_ptr = NULL;
my_strdup(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].prop_ptr, xctx->text[i].prop_ptr);
my_strdup(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].txt_ptr, xctx->text[i].txt_ptr);
my_strdup(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].font, xctx->text[i].font);
my_strdup2(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].prop_ptr, xctx->text[i].prop_ptr);
my_strdup2(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].txt_ptr, xctx->text[i].txt_ptr);
my_strdup2(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].font, xctx->text[i].font);
my_strdup2(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].floater_instname, xctx->text[i].floater_instname);
my_strdup(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].floater_ptr, xctx->text[i].floater_ptr);
my_strdup2(_ALLOC_ID_, &xctx->uslot[slot].tptr[i].floater_ptr, xctx->text[i].floater_ptr);
}
/* wires */
@ -527,11 +527,11 @@ void mem_pop_undo(int redo, int set_modify_status)
xctx->text[i].floater_instname = NULL;
xctx->text[i].floater_ptr = NULL;
xctx->text[i].prop_ptr = NULL;
my_strdup(_ALLOC_ID_, &xctx->text[i].prop_ptr, xctx->uslot[slot].tptr[i].prop_ptr);
my_strdup(_ALLOC_ID_, &xctx->text[i].txt_ptr, xctx->uslot[slot].tptr[i].txt_ptr);
my_strdup(_ALLOC_ID_, &xctx->text[i].font, xctx->uslot[slot].tptr[i].font);
my_strdup2(_ALLOC_ID_, &xctx->text[i].prop_ptr, xctx->uslot[slot].tptr[i].prop_ptr);
my_strdup2(_ALLOC_ID_, &xctx->text[i].txt_ptr, xctx->uslot[slot].tptr[i].txt_ptr);
my_strdup2(_ALLOC_ID_, &xctx->text[i].font, xctx->uslot[slot].tptr[i].font);
my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_instname, xctx->uslot[slot].tptr[i].floater_instname);
my_strdup(_ALLOC_ID_, &xctx->text[i].floater_ptr, xctx->uslot[slot].tptr[i].floater_ptr);
my_strdup2(_ALLOC_ID_, &xctx->text[i].floater_ptr, xctx->uslot[slot].tptr[i].floater_ptr);
}
/* wires */

View File

@ -961,7 +961,7 @@ void copy_objects(int what)
xctx->text[n].x0, xctx->text[n].y0, xctx->rx1,xctx->ry1);
}
xctx->text[xctx->texts].txt_ptr=NULL;
my_strdup(_ALLOC_ID_, &xctx->text[xctx->texts].txt_ptr,xctx->text[n].txt_ptr);
my_strdup2(_ALLOC_ID_, &xctx->text[xctx->texts].txt_ptr,xctx->text[n].txt_ptr);
xctx->text[n].sel=0;
dbg(2, "copy_objects(): current str=%s\n",
xctx->text[xctx->texts].txt_ptr);
@ -976,9 +976,9 @@ void copy_objects(int what)
xctx->text[xctx->texts].font=NULL;
xctx->text[xctx->texts].floater_instname=NULL;
xctx->text[xctx->texts].floater_ptr=NULL;
my_strdup(_ALLOC_ID_, &xctx->text[xctx->texts].prop_ptr, xctx->text[n].prop_ptr);
my_strdup(_ALLOC_ID_, &xctx->text[xctx->texts].floater_ptr, xctx->text[n].floater_ptr);
my_strdup(_ALLOC_ID_, &xctx->text[xctx->texts].floater_instname, xctx->text[n].floater_instname);
my_strdup2(_ALLOC_ID_, &xctx->text[xctx->texts].prop_ptr, xctx->text[n].prop_ptr);
my_strdup2(_ALLOC_ID_, &xctx->text[xctx->texts].floater_ptr, xctx->text[n].floater_ptr);
my_strdup2(_ALLOC_ID_, &xctx->text[xctx->texts].floater_instname, xctx->text[n].floater_instname);
set_text_flags(&xctx->text[xctx->texts]);
xctx->text[xctx->texts].xscale=xctx->text[n].xscale;
xctx->text[xctx->texts].yscale=xctx->text[n].yscale;