mirror of https://github.com/GNOME/gimp.git
libgimpbase: replace strcpy/strcat with g_strconcat in gimpmetadata
We were using fixed size buffer with strcpy/strcat, which gave warnings in coverity. Even though in our case there was no chance of buffer overflow, let's replace this by using g_strconcat, which allocates memory for the string which we free after use. Also get rid of a few unneeded memset's for strdata.
This commit is contained in:
parent
8ab345d1e4
commit
00901276f2
|
@ -310,10 +310,10 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata,
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
char timestr[256];
|
char timestr[256];
|
||||||
char tzstr[7];
|
char tzstr[7];
|
||||||
gchar iid_data[256];
|
|
||||||
gchar strdata[1024];
|
gchar strdata[1024];
|
||||||
gchar tagstr[1024];
|
gchar tagstr[1024];
|
||||||
gchar *uuid;
|
gchar *uuid;
|
||||||
|
gchar *str;
|
||||||
gchar *did;
|
gchar *did;
|
||||||
gchar *odid;
|
gchar *odid;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -345,28 +345,27 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata,
|
||||||
/* Update new Instance ID */
|
/* Update new Instance ID */
|
||||||
uuid = gimp_metadata_get_guid ();
|
uuid = gimp_metadata_get_guid ();
|
||||||
|
|
||||||
strcpy (iid_data, "xmp.iid:");
|
str = g_strconcat ("xmp.iid:", uuid, NULL);
|
||||||
strcat (iid_data, uuid);
|
|
||||||
|
|
||||||
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
||||||
tags[0], iid_data, NULL);
|
tags[0], str, NULL);
|
||||||
g_free (uuid);
|
g_free (uuid);
|
||||||
|
g_free (str);
|
||||||
|
|
||||||
/* Update new Document ID if none found */
|
/* Update new Document ID if none found */
|
||||||
did = gexiv2_metadata_try_get_tag_interpreted_string (GEXIV2_METADATA (metadata),
|
did = gexiv2_metadata_try_get_tag_interpreted_string (GEXIV2_METADATA (metadata),
|
||||||
tags[1], NULL);
|
tags[1], NULL);
|
||||||
if (! did || ! strlen (did))
|
if (! did || ! strlen (did))
|
||||||
{
|
{
|
||||||
gchar did_data[256];
|
gchar *did_data;
|
||||||
|
gchar *uuid = gimp_metadata_get_guid ();
|
||||||
|
|
||||||
uuid = gimp_metadata_get_guid ();
|
did_data = g_strconcat ("gimp:docid:gimp:", uuid, NULL);
|
||||||
|
|
||||||
strcpy (did_data, "gimp:docid:gimp:");
|
|
||||||
strcat (did_data, uuid);
|
|
||||||
|
|
||||||
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
||||||
tags[1], did_data, NULL);
|
tags[1], did_data, NULL);
|
||||||
g_free (uuid);
|
g_free (uuid);
|
||||||
|
g_free (did_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update new Original Document ID if none found */
|
/* Update new Original Document ID if none found */
|
||||||
|
@ -374,15 +373,15 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata,
|
||||||
tags[2], NULL);
|
tags[2], NULL);
|
||||||
if (! odid || ! strlen (odid))
|
if (! odid || ! strlen (odid))
|
||||||
{
|
{
|
||||||
gchar did_data[256];
|
gchar *did_data;
|
||||||
gchar *uuid = gimp_metadata_get_guid ();
|
gchar *uuid = gimp_metadata_get_guid ();
|
||||||
|
|
||||||
strcpy (did_data, "xmp.did:");
|
did_data = g_strconcat ("xmp.did:", uuid, NULL);
|
||||||
strcat (did_data, uuid);
|
|
||||||
|
|
||||||
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
||||||
tags[2], did_data, NULL);
|
tags[2], did_data, NULL);
|
||||||
g_free (uuid);
|
g_free (uuid);
|
||||||
|
g_free (did_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle Xmp.xmpMM.History */
|
/* Handle Xmp.xmpMM.History */
|
||||||
|
@ -418,7 +417,6 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata,
|
||||||
id_count = found + 1;
|
id_count = found + 1;
|
||||||
|
|
||||||
memset (tagstr, 0, sizeof (tagstr));
|
memset (tagstr, 0, sizeof (tagstr));
|
||||||
memset (strdata, 0, sizeof (strdata));
|
|
||||||
|
|
||||||
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
||||||
tags[3], id_count, history_tags[0]);
|
tags[3], id_count, history_tags[0]);
|
||||||
|
@ -453,7 +451,6 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata,
|
||||||
g_free(uuid);
|
g_free(uuid);
|
||||||
|
|
||||||
memset (tagstr, 0, sizeof (tagstr));
|
memset (tagstr, 0, sizeof (tagstr));
|
||||||
memset (strdata, 0, sizeof (strdata));
|
|
||||||
|
|
||||||
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
||||||
tags[3], id_count, history_tags[2]);
|
tags[3], id_count, history_tags[2]);
|
||||||
|
@ -483,7 +480,6 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata,
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
|
|
||||||
memset (tagstr, 0, sizeof (tagstr));
|
memset (tagstr, 0, sizeof (tagstr));
|
||||||
memset (strdata, 0, sizeof (strdata));
|
|
||||||
|
|
||||||
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
||||||
tags[3], id_count, history_tags[3]);
|
tags[3], id_count, history_tags[3]);
|
||||||
|
@ -511,16 +507,15 @@ gimp_metadata_add_xmp_history (GimpMetadata *metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
memset (tagstr, 0, sizeof (tagstr));
|
memset (tagstr, 0, sizeof (tagstr));
|
||||||
memset (strdata, 0, sizeof (strdata));
|
|
||||||
|
|
||||||
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
g_snprintf (tagstr, sizeof (tagstr), "%s[%d]%s",
|
||||||
tags[3], id_count, history_tags[4]);
|
tags[3], id_count, history_tags[4]);
|
||||||
|
|
||||||
strcpy (strdata, "/");
|
str = g_strconcat ("/", state_status, NULL);
|
||||||
strcat (strdata, state_status);
|
|
||||||
|
|
||||||
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
gexiv2_metadata_try_set_tag_string (GEXIV2_METADATA (metadata),
|
||||||
tagstr, strdata, &error);
|
tagstr, str, &error);
|
||||||
|
g_free (str);
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
g_printerr ("%s: failed to set metadata '%s': %s\n",
|
g_printerr ("%s: failed to set metadata '%s': %s\n",
|
||||||
|
|
Loading…
Reference in New Issue