Bug 2596: Crash durch leeres Banner

https://bugs.eressea.de/view.php?id=2596
This commit is contained in:
Enno Rehling 2019-07-14 09:26:32 +02:00
parent cb517c45a1
commit 0281ebc44b
5 changed files with 84 additions and 2 deletions

View File

@ -4391,6 +4391,13 @@
<arg name="command" type="order"/>
</type>
</message>
<message name="error125" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error84" section="errors">
<type>
<arg name="unit" type="unit"/>

View File

@ -689,6 +689,9 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit kan
msgid "error85"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Es wurde keine Emailadresse angegeben.\""
msgid "error125"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Es wurde kein Banner angegeben.\""
msgid "starvation"
msgstr "\"$unit($unit) verliert in $region($region) $int($dead) von $int($add($live,$dead)) Personen durch Unterernährung.\""

View File

@ -689,6 +689,9 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit cannot
msgid "error85"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - No email address was supplied.\""
msgid "error125"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - No banner text was supplied.\""
msgid "starvation"
msgstr "\"$unit($unit) loses $int($dead) of $int($add($live,$dead)) people due to starvation in $region($region).\""

View File

@ -2167,8 +2167,13 @@ int banner_cmd(unit * u, struct order *ord)
init_order_depr(ord);
s = getstrtoken();
faction_setbanner(u->faction, s);
ADDMSG(&u->faction->msgs, msg_message("changebanner", "value", s));
if (!s || !s[0]) {
cmistake(u, ord, 125, MSG_EVENT);
}
else {
faction_setbanner(u->faction, s);
ADDMSG(&u->faction->msgs, msg_message("changebanner", "value", s));
}
return 0;
}

View File

@ -1248,6 +1248,68 @@ static void test_ally_cmd_errors(CuTest *tc) {
test_teardown();
}
static void test_banner_cmd(CuTest *tc) {
unit *u;
faction *f;
order *ord;
test_setup();
mt_create_error(125);
mt_create_va(mt_new("changebanner", NULL), "value:string", MT_NEW_END);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
ord = create_order(K_BANNER, f->locale, "Hodor!");
banner_cmd(u, ord);
CuAssertStrEquals(tc, "Hodor!", faction_getbanner(f));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "changebanner"));
free_order(ord);
test_clear_messages(f);
ord = create_order(K_BANNER, f->locale, NULL);
banner_cmd(u, ord);
CuAssertStrEquals(tc, "Hodor!", faction_getbanner(f));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error125"));
free_order(ord);
test_clear_messages(f);
test_teardown();
}
static void test_email_cmd(CuTest *tc) {
unit *u;
faction *f;
order *ord;
test_setup();
mt_create_error(85);
mt_create_va(mt_new("changemail", NULL), "value:string", MT_NEW_END);
mt_create_va(mt_new("changemail_invalid", NULL), "value:string", MT_NEW_END);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
ord = create_order(K_EMAIL, f->locale, "hodor@example.com");
email_cmd(u, ord);
CuAssertStrEquals(tc, "hodor@example.com", f->email);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "changemail"));
free_order(ord);
test_clear_messages(f);
ord = create_order(K_EMAIL, f->locale, "example.com");
email_cmd(u, ord);
CuAssertStrEquals(tc, "hodor@example.com", f->email);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "changemail_invalid"));
free_order(ord);
test_clear_messages(f);
ord = create_order(K_EMAIL, f->locale, NULL);
email_cmd(u, ord);
CuAssertStrEquals(tc, "hodor@example.com", f->email);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error85"));
free_order(ord);
test_clear_messages(f);
test_teardown();
}
static void test_name_cmd(CuTest *tc) {
unit *u;
faction *f;
@ -2046,6 +2108,8 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_nmr_warnings);
SUITE_ADD_TEST(suite, test_ally_cmd);
SUITE_ADD_TEST(suite, test_name_cmd);
SUITE_ADD_TEST(suite, test_banner_cmd);
SUITE_ADD_TEST(suite, test_email_cmd);
SUITE_ADD_TEST(suite, test_name_cmd_2274);
SUITE_ADD_TEST(suite, test_name_unit);
SUITE_ADD_TEST(suite, test_name_region);