summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2010-03-12 20:05:21 +0100
committerSergei Golubchik <sergii@pisem.net>2010-03-12 20:05:21 +0100
commit71b3e46b0160936596195682a731703900fb4fff (patch)
tree936d6745468395c3462b136b5a997f67dc88ccdc
parentedfd875fc1620964d68c9acbd3d36213f1c1663a (diff)
downloadmariadb-git-71b3e46b0160936596195682a731703900fb4fff.tar.gz
1. don't crash on failing to load a plugin with newer MYSQL_PLUGIN_INTERFACE_VERSION
2. don't copy st_mysql_plugin structure unnecessary (sizeof hasn't changed)
-rw-r--r--sql/sql_plugin.cc56
-rw-r--r--sql/sql_plugin.h3
2 files changed, 32 insertions, 27 deletions
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 04d1abdeec4..b33d3c0b3ff 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -333,7 +333,7 @@ static inline void free_plugin_mem(struct st_plugin_dl *p)
dlclose(p->handle);
#endif
my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
- if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
+ if (p->allocated)
my_free((uchar*)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
}
@@ -454,33 +454,37 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
#endif
}
- for (i= 0;
- ((struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
- i++)
- /* no op */;
-
- cur= (struct st_mysql_plugin*)
- my_malloc(i*sizeof(struct st_mysql_plugin), MYF(MY_ZEROFILL|MY_WME));
- if (!cur)
+ if (sizeof_st_plugin != sizeof(st_mysql_plugin))
{
- free_plugin_mem(&plugin_dl);
- if (report & REPORT_TO_USER)
- my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
- if (report & REPORT_TO_LOG)
- sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
- DBUG_RETURN(0);
- }
- /*
- All st_plugin fields not initialized in the plugin explicitly, are
- set to 0. It matches C standard behaviour for struct initializers that
- have less values than the struct definition.
- */
- for (i=0;
- (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
- i++)
- memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
+ for (i= 0;
+ ((struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
+ i++)
+ /* no op */;
+
+ cur= (struct st_mysql_plugin*)
+ my_malloc((i+1)*sizeof(struct st_mysql_plugin), MYF(MY_ZEROFILL|MY_WME));
+ if (!cur)
+ {
+ free_plugin_mem(&plugin_dl);
+ if (report & REPORT_TO_USER)
+ my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
+ if (report & REPORT_TO_LOG)
+ sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
+ DBUG_RETURN(0);
+ }
+ /*
+ All st_plugin fields not initialized in the plugin explicitly, are
+ set to 0. It matches C standard behaviour for struct initializers that
+ have less values than the struct definition.
+ */
+ for (i=0;
+ (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
+ i++)
+ memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
- sym= cur;
+ sym= cur;
+ plugin_dl.allocated= true;
+ }
}
plugin_dl.plugins= (struct st_mysql_plugin *)sym;
diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h
index 54ef38b3734..79ee296ac64 100644
--- a/sql/sql_plugin.h
+++ b/sql/sql_plugin.h
@@ -63,7 +63,8 @@ struct st_plugin_dl
LEX_STRING dl;
void *handle;
struct st_mysql_plugin *plugins;
- int version;
+ int version;
+ bool allocated;
uint ref_count; /* number of plugins loaded from the library */
};