mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-16 04:28:05 +02:00
[girepository] Actually verify header of loaded typelibs in g_irepository_require
Take a GError * for typelib loading code, validate the header. This fixes bizarre errors from gjs where g_irepository_require would happily load old typelibs.
This commit is contained in:
parent
a01e97f46f
commit
4bf5ef6bd7
@ -29,45 +29,6 @@
|
|||||||
#include "girepository.h"
|
#include "girepository.h"
|
||||||
#include "gitypelib-internal.h"
|
#include "gitypelib-internal.h"
|
||||||
|
|
||||||
static const guchar *
|
|
||||||
load_typelib (const gchar *filename,
|
|
||||||
GModule **dlhandle,
|
|
||||||
gsize *len)
|
|
||||||
{
|
|
||||||
guchar *typelib;
|
|
||||||
gsize *typelib_size;
|
|
||||||
GModule *handle;
|
|
||||||
|
|
||||||
handle = g_module_open (filename, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY);
|
|
||||||
if (handle == NULL)
|
|
||||||
{
|
|
||||||
g_printerr ("Could not load typelib from '%s': %s\n",
|
|
||||||
filename, g_module_error ());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_module_symbol (handle, "_G_TYPELIB", (gpointer *) &typelib))
|
|
||||||
{
|
|
||||||
g_printerr ("Could not load typelib from '%s': %s\n",
|
|
||||||
filename, g_module_error ());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_module_symbol (handle, "_G_TYPELIB_SIZE", (gpointer *) &typelib_size))
|
|
||||||
{
|
|
||||||
g_printerr ("Could not load typelib from '%s': %s\n",
|
|
||||||
filename, g_module_error ());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*len = *typelib_size;
|
|
||||||
|
|
||||||
if (dlhandle)
|
|
||||||
*dlhandle = handle;
|
|
||||||
|
|
||||||
return typelib;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -114,62 +75,31 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
for (i = 0; input[i]; i++)
|
for (i = 0; input[i]; i++)
|
||||||
{
|
{
|
||||||
GModule *dlhandle = NULL;
|
GError *error = NULL;
|
||||||
const guchar *typelib;
|
|
||||||
gsize len;
|
|
||||||
const char *namespace;
|
const char *namespace;
|
||||||
|
GMappedFile *mfile;
|
||||||
|
GTypelib *typelib;
|
||||||
|
|
||||||
if (!shlib)
|
mfile = g_mapped_file_new (input[i], FALSE, &error);
|
||||||
{
|
if (!mfile)
|
||||||
if (!g_file_get_contents (input[i], (gchar **)&typelib, &len, &error))
|
g_error ("failed to read '%s': %s", input[i], error->message);
|
||||||
{
|
|
||||||
g_fprintf (stderr, "failed to read '%s': %s\n",
|
|
||||||
input[i], error->message);
|
|
||||||
g_clear_error (&error);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
typelib = load_typelib (input[i], &dlhandle, &len);
|
|
||||||
if (!typelib)
|
|
||||||
{
|
|
||||||
g_fprintf (stderr, "failed to load typelib from '%s'\n",
|
|
||||||
input[i]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input[i + 1] && output)
|
if (input[i + 1] && output)
|
||||||
needs_prefix = TRUE;
|
needs_prefix = TRUE;
|
||||||
else
|
else
|
||||||
needs_prefix = FALSE;
|
needs_prefix = FALSE;
|
||||||
|
|
||||||
data = g_typelib_new_from_const_memory (typelib, len);
|
typelib = g_typelib_new_from_mapped_file (mfile, &error);
|
||||||
{
|
if (!typelib)
|
||||||
GError *error = NULL;
|
g_error ("failed to create typelib '%s': %s", input[i], error->message);
|
||||||
if (!g_typelib_validate (data, &error)) {
|
|
||||||
g_printerr ("typelib not valid: %s\n", error->message);
|
namespace = g_irepository_load_typelib (g_irepository_get_default (), typelib, 0,
|
||||||
g_clear_error (&error);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
namespace = g_irepository_load_typelib (g_irepository_get_default (), data, 0,
|
|
||||||
&error);
|
&error);
|
||||||
if (namespace == NULL)
|
if (namespace == NULL)
|
||||||
{
|
g_error ("failed to load typelib: %s", error->message);
|
||||||
g_printerr ("failed to load typelib: %s\n", error->message);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gir_writer_write (output, namespace, needs_prefix, show_all);
|
gir_writer_write (output, namespace, needs_prefix, show_all);
|
||||||
|
|
||||||
if (dlhandle)
|
|
||||||
{
|
|
||||||
g_module_close (dlhandle);
|
|
||||||
dlhandle = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* when writing to stdout, stop after the first module */
|
/* when writing to stdout, stop after the first module */
|
||||||
if (input[i + 1] && !output)
|
if (input[i + 1] && !output)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user