summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-07-02 22:42:57 +0200
committerHaru <haru@dotalux.com>2016-07-02 22:42:57 +0200
commit6fbc00f9454d33caf79f89708cab9e46ec996eeb (patch)
treec9f2e98ac3e005b87d2a617515c15920585086a5 /src
parentca57b7b09063f40447fb37abe041116f4353b760 (diff)
downloadhercules-6fbc00f9454d33caf79f89708cab9e46ec996eeb.tar.gz
hercules-6fbc00f9454d33caf79f89708cab9e46ec996eeb.tar.bz2
hercules-6fbc00f9454d33caf79f89708cab9e46ec996eeb.tar.xz
hercules-6fbc00f9454d33caf79f89708cab9e46ec996eeb.zip
Fixed a rare crash in the db2sql plugin
- Fixes a crash that would occur when an item_db2 inherited item was missing Script, OnEquipScript or OnUnequipScript while its item_db counterpart had it. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/db2sql.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/plugins/db2sql.c b/src/plugins/db2sql.c
index 351962e26..3495e4abb 100644
--- a/src/plugins/db2sql.c
+++ b/src/plugins/db2sql.c
@@ -78,6 +78,7 @@ int (*mob_read_db_sub) (struct config_setting_t *it, int n, const char *source);
*/
void hstr(const char *str)
{
+ nullpo_retv(str);
if (strlen(str) > tosql.buf[3].len) {
tosql.buf[3].len = tosql.buf[3].len + strlen(str) + 1000;
RECREATE(tosql.buf[3].p,char,tosql.buf[3].len);
@@ -378,8 +379,7 @@ int itemdb2sql_sub(struct config_setting_t *entry, int n, const char *source)
}
// script
- if (it->script) {
- libconfig->setting_lookup_string(entry, "Script", &bonus);
+ if (it->script && libconfig->setting_lookup_string(entry, "Script", &bonus)) {
hstr(bonus);
str = tosql.buf[3].p;
if (strlen(str) > tosql.buf[0].len) {
@@ -387,12 +387,13 @@ int itemdb2sql_sub(struct config_setting_t *entry, int n, const char *source)
RECREATE(tosql.buf[0].p,char,tosql.buf[0].len);
}
SQL->EscapeString(NULL, tosql.buf[0].p, str);
+ StrBuf->Printf(&buf, "'%s',", tosql.buf[0].p);
+ } else {
+ StrBuf->AppendStr(&buf, "'',");
}
- StrBuf->Printf(&buf, "'%s',", it->script?tosql.buf[0].p:"");
// equip_script
- if (it->equip_script) {
- libconfig->setting_lookup_string(entry, "OnEquipScript", &bonus);
+ if (it->equip_script && libconfig->setting_lookup_string(entry, "OnEquipScript", &bonus)) {
hstr(bonus);
str = tosql.buf[3].p;
if (strlen(str) > tosql.buf[1].len) {
@@ -400,12 +401,13 @@ int itemdb2sql_sub(struct config_setting_t *entry, int n, const char *source)
RECREATE(tosql.buf[1].p,char,tosql.buf[1].len);
}
SQL->EscapeString(NULL, tosql.buf[1].p, str);
+ StrBuf->Printf(&buf, "'%s',", tosql.buf[1].p);
+ } else {
+ StrBuf->AppendStr(&buf, "'',");
}
- StrBuf->Printf(&buf, "'%s',", it->equip_script?tosql.buf[1].p:"");
// unequip_script
- if (it->unequip_script) {
- libconfig->setting_lookup_string(entry, "OnUnequipScript", &bonus);
+ if (it->unequip_script && libconfig->setting_lookup_string(entry, "OnUnequipScript", &bonus)) {
hstr(bonus);
str = tosql.buf[3].p;
if (strlen(str) > tosql.buf[2].len) {
@@ -413,8 +415,10 @@ int itemdb2sql_sub(struct config_setting_t *entry, int n, const char *source)
RECREATE(tosql.buf[2].p,char,tosql.buf[2].len);
}
SQL->EscapeString(NULL, tosql.buf[2].p, str);
+ StrBuf->Printf(&buf, "'%s'", tosql.buf[2].p);
+ } else {
+ StrBuf->AppendStr(&buf, "''");
}
- StrBuf->Printf(&buf, "'%s'", it->unequip_script?tosql.buf[2].p:"");
fprintf(tosql.fp, "REPLACE INTO `%s` VALUES (%s);\n", tosql.db_name, StrBuf->Value(&buf));