From 6fbc00f9454d33caf79f89708cab9e46ec996eeb Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 2 Jul 2016 22:42:57 +0200 Subject: 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 --- src/plugins/db2sql.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/plugins/db2sql.c') 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)); -- cgit v1.2.3-60-g2f50