Commit e753735a authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

plug-ins/gimpressionist/brush.c plug-ins/gimpressionist/gimp.c

2004-01-27  Sven Neumann  <sven@gimp.org>

	* plug-ins/gimpressionist/brush.c
	* plug-ins/gimpressionist/gimp.c
	* plug-ins/gimpressionist/gimpressionist.[ch]
	* plug-ins/gimpressionist/paper.c
	* plug-ins/gimpressionist/presets.c: fixed a crash (bug #132027),
	got rid of some possible buffer overflows and fixed platform issues
	like hardcoding '/' as the path separator.
parent 4801e3ac
2004-01-27 Sven Neumann <sven@gimp.org>
* plug-ins/gimpressionist/brush.c
* plug-ins/gimpressionist/gimp.c
* plug-ins/gimpressionist/gimpressionist.[ch]
* plug-ins/gimpressionist/paper.c
* plug-ins/gimpressionist/presets.c: fixed a crash (bug #132027),
got rid of some possible buffer overflows and fixed platform issues
like hardcoding '/' as the path separator.
2004-01-26 Michael Natterer <mitch@gimp.org>
 
* app/gui/image-menu.c (image_menu_entries): use
......@@ -188,7 +188,7 @@ savebrush (GtkWidget *wg,
{
static GtkWidget *window = NULL;
GList *thispath = parsepath ();
gchar path[200];
gchar *path;
if(! brushppm.col)
{
......@@ -196,16 +196,18 @@ savebrush (GtkWidget *wg,
return;
}
sprintf (path, "%s/Brushes/", (char *)thispath->data);
window = gtk_file_selection_new (_("Save Brush"));
gtk_window_set_transient_for (GTK_WINDOW (window),
GTK_WINDOW (gtk_widget_get_toplevel (wg)));
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE);
path = g_build_filename ((char *)thispath->data, "Brushes", "", NULL);
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), path);
g_free (path);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
......@@ -224,13 +226,14 @@ static gboolean validdrawable(gint32 imageid, gint32 drawableid, gpointer data)
void reloadbrush(char *fn, ppm_t *p)
{
static char lastfn[200] = "";
static char lastfn[256] = "";
static ppm_t cache = {0,0,NULL};
if(strcmp(fn, lastfn)) {
strncpy(lastfn, fn, 199);
loadppm(fn, &cache);
}
if(strcmp(fn, lastfn))
{
g_strlcpy (lastfn, fn, sizeof (lastfn));
loadppm (fn, &cache);
}
copyppm(&cache, p);
pcvals.colorbrushes = colorfile(fn);
}
......@@ -301,16 +304,17 @@ static gboolean brushdontupdate = FALSE;
static void selectbrush(GtkTreeSelection *selection, gpointer data)
{
GtkTreeIter iter;
GtkTreeIter iter;
GtkTreeModel *model;
char fname[200];
if (brushdontupdate) return;
if (brushfile == 0) {
updatebrushprev(NULL);
if (brushdontupdate)
return;
}
if (brushfile == 0)
{
updatebrushprev (NULL);
return;
}
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
......@@ -323,12 +327,18 @@ static void selectbrush(GtkTreeSelection *selection, gpointer data)
gtk_adjustment_set_value(GTK_ADJUSTMENT(brushaspectadjust), 0.0);
brushdontupdate = FALSE;
sprintf(fname, "Brushes/%s", brush);
strcpy(pcvals.selectedbrush, fname);
if (brush)
{
gchar *fname = g_build_filename ("Brushes", brush, NULL);
g_strlcpy (pcvals.selectedbrush,
fname, sizeof (pcvals.selectedbrush));
updatebrushprev(fname);
updatebrushprev (fname);
g_free (brush);
g_free (fname);
g_free (brush);
}
}
}
......
......@@ -172,10 +172,9 @@ run (const gchar *name,
{
gimpressionist_main();
gimp_displays_flush ();
if (run_mode == GIMP_RUN_INTERACTIVE)
gimp_set_data(PLUG_IN_NAME, &pcvals, sizeof(gimpressionist_vals_t));
}
else if (status == GIMP_PDB_SUCCESS)
{
......@@ -185,7 +184,7 @@ run (const gchar *name,
g_rand_free (gr);
values[0].data.d_status = status;
gimp_drawable_detach(drawable);
}
......
......@@ -83,6 +83,8 @@ findfile (const gchar *fn)
GList *thispath;
gchar *filename;
g_return_val_if_fail (fn != NULL, NULL);
if (!rcpath)
rcpath = parsepath ();
......
......@@ -3,78 +3,77 @@
#define PLUG_IN_VERSION "v1.0, November 2003"
#define HELP_ID "plug-in-gimppressionist"
#ifndef DEFAULTPATH
#define DEFAULTPATH "~/.gimp/gimpressionist:/usr/local/share/gimp/gimpressionist"
#endif
#define PREVIEWSIZE 150
#define MAXORIENTVECT 50
#define MAXSIZEVECT 50
#define PREVIEWSIZE 150
#define MAXORIENTVECT 50
#define MAXSIZEVECT 50
/* Type declaration and definitions */
typedef struct vector {
typedef struct vector
{
double x, y;
double dir;
double dx, dy;
double str;
int type;
int type;
} vector_t;
typedef struct smvector {
typedef struct smvector
{
double x, y;
double siz;
double str;
} smvector_t;
typedef struct {
int orientnum;
double orientfirst;
double orientlast;
int orienttype;
double brushrelief;
double brushscale;
double brushdensity;
double brushgamma;
int generalbgtype;
double generaldarkedge;
double paperrelief;
double paperscale;
int paperinvert;
int run;
char selectedbrush[100];
char selectedpaper[100];
GimpRGB color;
int generalpaintedges;
int placetype;
vector_t orientvector[MAXORIENTVECT];
int numorientvector;
int placecenter;
double brushaspect;
double orientangoff;
double orientstrexp;
int generaltileable;
int paperoverlay;
int orientvoronoi;
int colorbrushes;
int generaldropshadow;
double generalshadowdarkness;
int sizenum;
double sizefirst;
double sizelast;
int sizetype;
double devthresh;
typedef struct
{
int orientnum;
double orientfirst;
double orientlast;
int orienttype;
double brushrelief;
double brushscale;
double brushdensity;
double brushgamma;
int generalbgtype;
double generaldarkedge;
double paperrelief;
double paperscale;
int paperinvert;
int run;
char selectedbrush[200];
char selectedpaper[200];
GimpRGB color;
int generalpaintedges;
int placetype;
vector_t orientvector[MAXORIENTVECT];
int numorientvector;
int placecenter;
double brushaspect;
double orientangoff;
double orientstrexp;
int generaltileable;
int paperoverlay;
int orientvoronoi;
int colorbrushes;
int generaldropshadow;
double generalshadowdarkness;
int sizenum;
double sizefirst;
double sizelast;
int sizetype;
double devthresh;
smvector_t sizevector[MAXSIZEVECT];
int numsizevector;
double sizestrexp;
int sizevoronoi;
int numsizevector;
double sizestrexp;
int sizevoronoi;
int generalshadowdepth;
int generalshadowblur;
int generalshadowdepth;
int generalshadowblur;
int colortype;
double colornoise;
int colortype;
double colornoise;
} gimpressionist_vals_t;
/* Globals */
......@@ -170,7 +169,7 @@ void placechange(int num);
void colorchange(int num);
void generalbgchange(GtkWidget *wg, void *d, int num);
GtkWidget *createonecolumnlist(GtkWidget *parent,
GtkWidget *createonecolumnlist(GtkWidget *parent,
void (*changed_cb)
(GtkTreeSelection *selection, gpointer data));
......
......@@ -61,9 +61,8 @@ static void updatepaperprev(char *fn)
static void selectpaper(GtkTreeSelection *selection, gpointer data)
{
GtkTreeIter iter;
GtkTreeIter iter;
GtkTreeModel *model;
char fname[200];
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
......@@ -71,11 +70,18 @@ static void selectpaper(GtkTreeSelection *selection, gpointer data)
gtk_tree_model_get (model, &iter, 0, &paper, -1);
sprintf(fname, "Paper/%s", paper);
strcpy(pcvals.selectedpaper, fname);
updatepaperprev(fname);
if (paper)
{
gchar *fname = g_build_filename ("Paper", paper, NULL);
g_strlcpy (pcvals.selectedpaper,
fname, sizeof (pcvals.selectedpaper));
updatepaperprev (fname);
g_free (paper);
g_free (fname);
g_free (paper);
}
}
}
......
......@@ -134,17 +134,19 @@ static void setsizevector(char *str)
}
static void parsedesc(char *str, char *d)
static void parsedesc(char *str, char *d, gssize d_len)
{
gchar *dest = g_strcompress (str);
strcpy (d, dest);
g_strlcpy (d, dest, d_len);
g_free (dest);
}
static void setval(char *key, char *val)
{
if(!strcmp(key, "desc"))
parsedesc(val, presetdesc);
parsedesc(val, presetdesc, sizeof (presetdesc));
else if(!strcmp(key, "orientnum"))
pcvals.orientnum = atoi(val);
else if(!strcmp(key, "orientfirst"))
......@@ -211,9 +213,9 @@ static void setval(char *key, char *val)
pcvals.placecenter = atoi(val);
else if(!strcmp(key, "selectedbrush"))
strncpy(pcvals.selectedbrush, val, 99);
g_strlcpy (pcvals.selectedbrush, val, sizeof (pcvals.selectedbrush));
else if(!strcmp(key, "selectedpaper"))
strncpy(pcvals.selectedpaper, val, 99);
g_strlcpy (pcvals.selectedpaper, val, sizeof (pcvals.selectedpaper));
else if(!strcmp(key, "color")){
char *c = parsergbstring(val);
......@@ -283,18 +285,25 @@ static void applypreset(GtkWidget *w, GtkTreeSelection *selection)
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
char fname[200];
gchar *preset;
gtk_tree_model_get (model, &iter, 0, &preset, -1);
if (strcmp(preset, factory_defaults))
if (strcmp (preset, factory_defaults))
{
sprintf(fname, "Presets/%s", preset);
strcpy(fname, findfile(fname));
loadpreset(fname);
gchar *rel = g_build_filename ("Presets", preset, NULL);
gchar *abs = findfile (rel);
g_free (rel);
if (abs)
{
loadpreset (abs);
g_free (abs);
}
}
restorevals();
restorevals ();
g_free (preset);
}
......@@ -307,18 +316,27 @@ static void deletepreset(GtkWidget *w, GtkTreeSelection *selection)
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
char fname[200];
gchar *preset;
gtk_tree_model_get (model, &iter, 0, &preset, -1);
sprintf(fname, "Presets/%s", preset);
strcpy(fname, findfile(fname));
if (preset)
{
gchar *rel = g_build_filename ("Presets", preset, NULL);
gchar *abs = findfile (rel);
unlink(fname);
presetsrefresh();
g_free (rel);
g_free (preset);
if (abs)
{
unlink (abs);
g_free (abs);
}
presetsrefresh ();
g_free (preset);
}
}
}
......@@ -332,7 +350,7 @@ static void presetdesccallback(GtkTextBuffer *buffer, gpointer data)
gtk_text_buffer_get_bounds (buffer, &start, &end);
str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
dest = g_strescape (str, NULL);
strcpy (presetdesc, dest);
g_strlcpy (presetdesc, dest, sizeof (presetdesc));
g_free (dest);
g_free (str);
}
......@@ -411,30 +429,33 @@ create_savepreset (void)
static void savepreset(void)
{
const gchar *l;
static char fname[200];
FILE *f;
gchar *fname;
FILE *f;
GList *thispath;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gchar vbuf[6][G_ASCII_DTOSTR_BUF_SIZE];
guchar color[3];
int i;
gint i;
l = gtk_entry_get_text(GTK_ENTRY(presetnameentry));
thispath = parsepath();
storevals();
l = gtk_entry_get_text (GTK_ENTRY (presetnameentry));
thispath = parsepath ();
storevals ();
if(!thispath) {
fprintf(stderr, "Internal error: (savepreset) thispath == NULL");
return;
}
if (!thispath)
{
g_printerr ("Internal error: (savepreset) thispath == NULL");
return;
}
sprintf(fname, "%s/Presets/%s", (char *)thispath->data, l);
fname = g_build_filename ((char *)thispath->data, "Presets", l, NULL);
f = fopen (fname, "wt");
if (!f)
{
g_printerr ("Error opening file \"%s\" for writing!%c\n", fname, 7);
return;
}
f = fopen(fname, "wt");
if(!f) {
fprintf(stderr, "Error opening file \"%s\" for writing!%c\n", fname, 7);
return;
}
fprintf(f, "%s\n", PRESETMAGIC);
fprintf(f, "desc=%s\n", presetdesc);
fprintf(f, "orientnum=%d\n", pcvals.orientnum);
......@@ -528,40 +549,51 @@ static void savepreset(void)
fprintf(f, "colornoise=%s\n",
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", pcvals.colornoise));
fclose(f);
presetsrefresh();
reselect(presetlist, fname);
fclose (f);
presetsrefresh ();
reselect (presetlist, fname);
g_free (fname);
}
static void readdesc(char *fn)
static void readdesc(const char *fn)
{
char *tmp, fname[200];
char *tmp;
char *fname;
FILE *f;
sprintf(fname, "Presets/%s", fn);
tmp = findfile(fname);
if (!tmp) {
gtk_label_set_text(GTK_LABEL(presetdesclabel), "");
return;
}
strcpy(fname, tmp);
fname = g_build_filename ("Presets", fn, NULL);
tmp = findfile (fname);
g_free (fname);
if (!tmp)
{
gtk_label_set_text (GTK_LABEL (presetdesclabel), "");
return;
}
fname = tmp;
f = fopen(fname, "rt");
if(f) {
char line[4096];
char tmplabel[4096];
while(!feof(f)) {
fgets(line, 4095, f);
if(!strncmp(line, "desc=", 5)) {
parsedesc(line+5, tmplabel);
gtk_label_set_text(GTK_LABEL(presetdesclabel), tmplabel);
fclose(f);
return;
}
if (f)
{
char line[4096];
char tmplabel[4096];
while(!feof(f))
{
fgets(line, 4095, f);
if (!strncmp (line, "desc=", 5))
{
parsedesc (line + 5, tmplabel, sizeof (tmplabel));
gtk_label_set_text (GTK_LABEL (presetdesclabel), tmplabel);
fclose (f);
return;
}
}
fclose (f);
}
fclose(f);
}
gtk_label_set_text(GTK_LABEL(presetdesclabel), "");
gtk_label_set_text (GTK_LABEL (presetdesclabel), "");
}
static void selectpreset(GtkTreeSelection *selection, gpointer data)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment