From ba9c1cc16cb8f696a50d0ae928b6e8a19086405b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 12 Sep 2015 23:42:44 +0300 Subject: Add missing checks into atcommand.c --- src/map/atcommand.c | 1026 ++++++++++++++++++++++++++------------------------- src/map/atcommand.h | 5 +- 2 files changed, 527 insertions(+), 504 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 105f3304c..dceb8716a 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -67,6 +67,7 @@ static char atcmd_player_name[NAME_LENGTH]; struct atcmd_binding_data* get_atcommandbind_byname(const char* name) { int i = 0; + nullpo_retr(NULL, name); if( *name == atcommand->at_symbol || *name == atcommand->char_symbol ) name++; // for backwards compatibility @@ -76,18 +77,16 @@ struct atcmd_binding_data* get_atcommandbind_byname(const char* name) { } const char* atcommand_msgsd(struct map_session_data *sd, int msg_number) { - if( !(msg_number >= 0 && msg_number < MAX_MSG) ) - return "??"; - if( !sd || sd->lang_id >= atcommand->max_message_table || !atcommand->msg_table[sd->lang_id][msg_number] ) + Assert_retr("??", msg_number >= 0 && msg_number < MAX_MSG); + if (!sd || sd->lang_id >= atcommand->max_message_table || !atcommand->msg_table[sd->lang_id][msg_number]) return atcommand->msg_table[0][msg_number]; return atcommand->msg_table[sd->lang_id][msg_number]; } const char* atcommand_msgfd(int fd, int msg_number) { struct map_session_data *sd = sockt->session_is_valid(fd) ? sockt->session[fd]->session_data : NULL; - if( !(msg_number >= 0 && msg_number < MAX_MSG) ) - return "??"; - if( !sd || sd->lang_id >= atcommand->max_message_table || !atcommand->msg_table[sd->lang_id][msg_number] ) + Assert_retr("??", msg_number >= 0 && msg_number < MAX_MSG); + if (!sd || sd->lang_id >= atcommand->max_message_table || !atcommand->msg_table[sd->lang_id][msg_number]) return atcommand->msg_table[0][msg_number]; return atcommand->msg_table[sd->lang_id][msg_number]; } @@ -96,13 +95,12 @@ const char* atcommand_msgfd(int fd, int msg_number) { // Return the message string of the specified number by [Yor] //----------------------------------------------------------- const char* atcommand_msg(int msg_number) { - if (msg_number >= 0 && msg_number < MAX_MSG) { - if(atcommand->msg_table[map->default_lang_id][msg_number] != NULL && atcommand->msg_table[map->default_lang_id][msg_number][0] != '\0') - return atcommand->msg_table[map->default_lang_id][msg_number]; - - if(atcommand->msg_table[0][msg_number] != NULL && atcommand->msg_table[0][msg_number][0] != '\0') - return atcommand->msg_table[0][msg_number]; - } + Assert_retr("??", msg_number >= 0 && msg_number < MAX_MSG); + if (atcommand->msg_table[map->default_lang_id][msg_number] != NULL && atcommand->msg_table[map->default_lang_id][msg_number][0] != '\0') + return atcommand->msg_table[map->default_lang_id][msg_number]; + + if(atcommand->msg_table[0][msg_number] != NULL && atcommand->msg_table[0][msg_number][0] != '\0') + return atcommand->msg_table[0][msg_number]; return "??"; } @@ -120,6 +118,7 @@ bool msg_config_read(const char *cfg_name, bool allow_override) { FILE *fp; static int called = 1; + nullpo_retr(false, cfg_name); if ((fp = fopen(cfg_name, "r")) == NULL) { ShowError("Messages file not found: %s\n", cfg_name); return false; @@ -135,7 +134,7 @@ bool msg_config_read(const char *cfg_name, bool allow_override) { continue; if (strcmpi(w1, "import") == 0) { - msg_config_read(w2, true); + atcommand->msg_read(w2, true); } else { msg_number = atoi(w1); if (msg_number >= 0 && msg_number < MAX_MSG) { @@ -210,7 +209,7 @@ ACMD(send) long num; // read message type as hex number (without the 0x) - if (!message || !*message + if (!*message || !((sscanf(message, "len %x", &type)==1 && (len=1)) || sscanf(message, "%x", &type)==1) ) { @@ -223,7 +222,7 @@ ACMD(send) #define PARSE_ERROR(error,p) do {\ clif->message(fd, (error));\ - sprintf(atcmd_output, ">%s", (p));\ + safesnprintf(atcmd_output, sizeof(atcmd_output), ">%s", (p));\ clif->message(fd, atcmd_output);\ } while(0) //define PARSE_ERROR @@ -250,7 +249,7 @@ ACMD(send) int off = 2; if (len) { // show packet length - sprintf(atcmd_output, msg_fd(fd,904), type, packet_db[type].len); // Packet 0x%x length: %d + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,904), type, packet_db[type].len); // Packet 0x%x length: %d clif->message(fd, atcmd_output); return true; } @@ -258,7 +257,7 @@ ACMD(send) len=packet_db[type].len; if (len == 0) { // unknown packet - ERROR - sprintf(atcmd_output, msg_fd(fd,905), type); // Unknown packet: 0x%x + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,905), type); // Unknown packet: 0x%x clif->message(fd, atcmd_output); return false; } else if (len == -1) { @@ -438,9 +437,9 @@ ACMD(mapmove) { memset(map_name, '\0', sizeof(map_name)); - if (!message || !*message || - (sscanf(message, "%15s %hd %hd", map_name, &x, &y) < 3 && - sscanf(message, "%15[^,],%hd,%hd", map_name, &x, &y) < 1)) { + if (!*message || + (sscanf(message, "%15s %5hd %5hd", map_name, &x, &y) < 3 && + sscanf(message, "%15[^,],%5hd,%5hd", map_name, &x, &y) < 1)) { clif->message(fd, msg_fd(fd,909)); // Please enter a map (usage: @warp/@rura/@mapmove ). return false; } @@ -490,7 +489,7 @@ ACMD(where) { memset(atcmd_player_name, '\0', sizeof atcmd_player_name); - if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { + if (!*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { clif->message(fd, msg_fd(fd,910)); // Please enter a player name (usage: @where ). return false; } @@ -516,7 +515,7 @@ ACMD(where) { ACMD(jumpto) { struct map_session_data *pl_sd = NULL; - if (!message || !*message) { + if (!*message) { clif->message(fd, msg_fd(fd,911)); // Please enter a player name (usage: @jumpto/@warpto/@goto ). return false; } @@ -547,7 +546,7 @@ ACMD(jumpto) { } pc->setpos(sd, pl_sd->mapindex, pl_sd->bl.x, pl_sd->bl.y, CLR_TELEPORT); - sprintf(atcmd_output, msg_fd(fd,4), pl_sd->status.name); // Jumped to %s + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,4), pl_sd->status.name); // Jumped to %s clif->message(fd, atcmd_output); return true; @@ -562,7 +561,7 @@ ACMD(jump) memset(atcmd_output, '\0', sizeof(atcmd_output)); - sscanf(message, "%hd %hd", &x, &y); + sscanf(message, "%5hd %5hd", &x, &y); if (map->list[sd->bl.m].flag.noteleport && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) { clif->message(fd, msg_fd(fd,248)); // You are not authorized to warp from your current map. @@ -581,13 +580,13 @@ ACMD(jump) x = y = 0; //Invalid cell, use random spot. } - if( x && y && sd->bl.x == x && sd->bl.y == y ) { + if (x && y && sd->bl.x == x && sd->bl.y == y) { clif->message(fd, msg_fd(fd,253)); // You already are at your destination! return false; } pc->setpos(sd, sd->mapindex, x, y, CLR_TELEPORT); - sprintf(atcmd_output, msg_fd(fd,5), sd->bl.x, sd->bl.y); // Jumped to %d %d + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,5), sd->bl.x, sd->bl.y); // Jumped to %d %d clif->message(fd, atcmd_output); return true; } @@ -735,18 +734,18 @@ ACMD(whogm) if (pl_level > level) { if (pc_isinvisible(pl_sd)) continue; - sprintf(atcmd_output, msg_fd(fd,913), pl_sd->status.name); // Name: %s (GM) + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,913), pl_sd->status.name); // Name: %s (GM) clif->message(fd, atcmd_output); count++; continue; } - sprintf(atcmd_output, msg_fd(fd,914), // Name: %s (GM:%d) | Location: %s %d %d + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,914), // Name: %s (GM:%d) | Location: %s %d %d pl_sd->status.name, pl_level, mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y); clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,915), // BLvl: %d | Job: %s (Lvl: %d) + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,915), // BLvl: %d | Job: %s (Lvl: %d) pl_sd->status.base_level, pc->job_name(pl_sd->status.class_), pl_sd->status.job_level); clif->message(fd, atcmd_output); @@ -754,7 +753,7 @@ ACMD(whogm) p = party->search(pl_sd->status.party_id); g = pl_sd->guild; - sprintf(atcmd_output,msg_fd(fd,916), // Party: '%s' | Guild: '%s' + safesnprintf(atcmd_output, sizeof(atcmd_output),msg_fd(fd,916), // Party: '%s' | Guild: '%s' p?p->party.name:msg_fd(fd,917), g?g->name:msg_fd(fd,917)); // None. clif->message(fd, atcmd_output); @@ -767,7 +766,7 @@ ACMD(whogm) else if (count == 1) clif->message(fd, msg_fd(fd,151)); // 1 GM found. else { - sprintf(atcmd_output, msg_fd(fd,152), count); // %d GMs found. + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,152), count); // %d GMs found. clif->message(fd, atcmd_output); } @@ -821,8 +820,8 @@ ACMD(speed) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%d", &speed) < 1) { - sprintf(atcmd_output, msg_fd(fd,918), MIN_WALK_SPEED, MAX_WALK_SPEED); // Please enter a speed value (usage: @speed <%d-%d>). + if (!*message || sscanf(message, "%12d", &speed) < 1) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,918), MIN_WALK_SPEED, MAX_WALK_SPEED); // Please enter a speed value (usage: @speed <%d-%d>). clif->message(fd, atcmd_output); return false; } @@ -903,7 +902,7 @@ ACMD(option) { int param1 = 0, param2 = 0, param3 = 0; - if (!message || !*message || sscanf(message, "%d %d %d", ¶m1, ¶m2, ¶m3) < 1 || param1 < 0 || param2 < 0 || param3 < 0) + if (!*message || sscanf(message, "%12d %12d %12d", ¶m1, ¶m2, ¶m3) < 1 || param1 < 0 || param2 < 0 || param3 < 0) {// failed to match the parameters so inform the user of the options const char* text; @@ -976,7 +975,7 @@ ACMD(jobchange) { int job = 0, upper = 0; const char* text; - if (!message || !*message || sscanf(message, "%d %d", &job, &upper) < 1) { + if (!*message || sscanf(message, "%12d %12d", &job, &upper) < 1) { upper = 0; if( message ) { @@ -1070,7 +1069,7 @@ ACMD(kami) memset(atcmd_output, '\0', sizeof(atcmd_output)); if(*(info->command + 4) != 'c' && *(info->command + 4) != 'C') { - if (!message || !*message) { + if (!*message) { clif->message(fd, msg_fd(fd,980)); // Please enter a message (usage: @kami ). return false; } @@ -1081,7 +1080,7 @@ ACMD(kami) else intif->broadcast(atcmd_output, strlen(atcmd_output) + 1, (*(info->command + 4) == 'b' || *(info->command + 4) == 'B') ? BC_BLUE : BC_YELLOW); } else { - if(!message || !*message || (sscanf(message, "%u %199[^\n]", &color, atcmd_output) < 2)) { + if(!*message || (sscanf(message, "%10u %199[^\n]", &color, atcmd_output) < 2)) { clif->message(fd, msg_fd(fd,981)); // Please enter color and message (usage: @kamic ). return false; } @@ -1102,7 +1101,7 @@ ACMD(heal) { int hp = 0, sp = 0; // [Valaris] thanks to fov - sscanf(message, "%d %d", &hp, &sp); + sscanf(message, "%12d %12d", &hp, &sp); // some overflow checks if( hp == INT_MIN ) hp++; @@ -1166,15 +1165,15 @@ ACMD(item) memset(item_name, '\0', sizeof(item_name)); - if (!strcmpi(info->command,"itembound") && (!message || !*message || ( - sscanf(message, "\"%99[^\"]\" %d %d", item_name, &number, &bound) < 2 && - sscanf(message, "%99s %d %d", item_name, &number, &bound) < 2 + if (!strcmpi(info->command,"itembound") && (!*message || ( + sscanf(message, "\"%99[^\"]\" %12d %12d", item_name, &number, &bound) < 2 && + sscanf(message, "%99s %12d %12d", item_name, &number, &bound) < 2 ))) { clif->message(fd, msg_fd(fd,295)); // Please enter an item name or ID (usage: @itembound ). return false; - } else if (!message || !*message - || ( sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 - && sscanf(message, "%99s %d", item_name, &number) < 1 + } else if (!*message + || ( sscanf(message, "\"%99[^\"]\" %12d", item_name, &number) < 1 + && sscanf(message, "%99s %12d", item_name, &number) < 1 )) { clif->message(fd, msg_fd(fd,983)); // Please enter an item name or ID (usage: @item ). return false; @@ -1257,15 +1256,15 @@ ACMD(item2) memset(item_name, '\0', sizeof(item_name)); - if (!strcmpi(info->command,"itembound2") && (!message || !*message || ( - sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 && - sscanf(message, "%99s %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))) { + if (!strcmpi(info->command,"itembound2") && (!*message || ( + sscanf(message, "\"%99[^\"]\" %12d %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 && + sscanf(message, "%99s %12d %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))) { clif->message(fd, msg_fd(fd,296)); // Please enter all parameters (usage: @itembound2 clif->message(fd, msg_fd(fd,297)); // ). return false; - } else if ( !message || !*message - || ( sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 - && sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 + } else if (!*message + || ( sscanf(message, "\"%99[^\"]\" %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 + && sscanf(message, "%99s %12d %12d %12d %12d %12d %12d %12d %12d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 )) { clif->message(fd, msg_fd(fd,984)); // Please enter all parameters (usage: @item2 clif->message(fd, msg_fd(fd,985)); // ). @@ -1361,7 +1360,7 @@ ACMD(baselevelup) { int level=0, i=0, status_point=0; - if (!message || !*message || !(level = atoi(message))) { + if (!*message || !(level = atoi(message))) { clif->message(fd, msg_fd(fd,986)); // Please enter a level adjustment (usage: @lvup/@blevel/@baselvlup ). return false; } @@ -1420,7 +1419,7 @@ ACMD(joblevelup) { int level=0; - if (!message || !*message || !(level = atoi(message))) { + if (!*message || !(level = atoi(message))) { clif->message(fd, msg_fd(fd,987)); // Please enter a level adjustment (usage: @joblvup/@jlevel/@joblvlup ). return false; } @@ -1470,7 +1469,7 @@ ACMD(help) { char *default_command = "help"; AtCommandInfo *tinfo = NULL; - if (!message || !*message) { + if (!*message) { command_name = default_command; // If no command_name specified, display help for @help. } else { if (*message == atcommand->at_symbol || *message == atcommand->char_symbol) @@ -1479,7 +1478,7 @@ ACMD(help) { } if (!atcommand->can_use2(sd, command_name, COMMAND_ATCOMMAND)) { - sprintf(atcmd_output, msg_fd(fd,153), message); // "%s is Unknown Command" + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,153), message); // "%s is Unknown Command" clif->message(fd, atcmd_output); atcommand->get_suggestions(sd, command_name, true); return false; @@ -1488,13 +1487,13 @@ ACMD(help) { tinfo = atcommand->get_info_byname(atcommand->check_alias(command_name)); if ( !tinfo || tinfo->help == NULL ) { - sprintf(atcmd_output, msg_fd(fd,988), atcommand->at_symbol, command_name); // There is no help for %c%s. + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,988), atcommand->at_symbol, command_name); // There is no help for %c%s. clif->message(fd, atcmd_output); atcommand->get_suggestions(sd, command_name, true); return false; } - sprintf(atcmd_output, msg_fd(fd,989), atcommand->at_symbol, command_name); // Help for command %c%s: + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,989), atcommand->at_symbol, command_name); // Help for command %c%s: clif->message(fd, atcmd_output); { // Display aliases @@ -1530,6 +1529,7 @@ ACMD(help) { int atcommand_stopattack(struct block_list *bl,va_list ap) { struct unit_data *ud = unit->bl2ud(bl); + nullpo_ret(bl); int id = va_arg(ap, int); if (ud && ud->attacktimer != INVALID_TIMER && (!id || id == ud->target)) { @@ -1538,12 +1538,14 @@ int atcommand_stopattack(struct block_list *bl,va_list ap) } return 0; } + /*========================================== * *------------------------------------------*/ int atcommand_pvpoff_sub(struct block_list *bl,va_list ap) { TBL_PC* sd = (TBL_PC*)bl; + nullpo_ret(bl); clif->pvpset(sd, 0, 0, 2); if (sd->pvp_timer != INVALID_TIMER) { timer->delete(sd->pvp_timer, pc->calc_pvprank_timer); @@ -1578,6 +1580,7 @@ ACMD(pvpoff) int atcommand_pvpon_sub(struct block_list *bl,va_list ap) { TBL_PC* sd = (TBL_PC*)bl; + nullpo_ret(bl); if (sd->pvp_timer == INVALID_TIMER) { sd->pvp_timer = timer->add(timer->gettick() + 200, pc->calc_pvprank_timer, sd->bl.id, 0); sd->pvp_rank = 0; @@ -1658,8 +1661,8 @@ ACMD(model) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%d %d %d", &hair_style, &hair_color, &cloth_color) < 1) { - sprintf(atcmd_output, msg_fd(fd,991), // Please enter at least one value (usage: @model ). + if (!*message || sscanf(message, "%12d %12d %12d", &hair_style, &hair_color, &cloth_color) < 1) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,991), // Please enter at least one value (usage: @model ). MIN_HAIR_STYLE, MAX_HAIR_STYLE, MIN_HAIR_COLOR, MAX_HAIR_COLOR, MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); clif->message(fd, atcmd_output); return false; @@ -1689,8 +1692,8 @@ ACMD(dye) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%d", &cloth_color) < 1) { - sprintf(atcmd_output, msg_fd(fd,992), MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); // Please enter a clothes color (usage: @dye/@ccolor ). + if (!*message || sscanf(message, "%12d", &cloth_color) < 1) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,992), MIN_CLOTH_COLOR, MAX_CLOTH_COLOR); // Please enter a clothes color (usage: @dye/@ccolor ). clif->message(fd, atcmd_output); return false; } @@ -1715,8 +1718,8 @@ ACMD(hair_style) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%d", &hair_style) < 1) { - sprintf(atcmd_output, msg_fd(fd,993), MIN_HAIR_STYLE, MAX_HAIR_STYLE); // Please enter a hair style (usage: @hairstyle/@hstyle ). + if (!*message || sscanf(message, "%12d", &hair_style) < 1) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,993), MIN_HAIR_STYLE, MAX_HAIR_STYLE); // Please enter a hair style (usage: @hairstyle/@hstyle ). clif->message(fd, atcmd_output); return false; } @@ -1741,8 +1744,8 @@ ACMD(hair_color) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%d", &hair_color) < 1) { - sprintf(atcmd_output, msg_fd(fd,994), MIN_HAIR_COLOR, MAX_HAIR_COLOR); // Please enter a hair color (usage: @haircolor/@hcolor ). + if (!*message || sscanf(message, "%12d", &hair_color) < 1) { + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,994), MIN_HAIR_COLOR, MAX_HAIR_COLOR); // Please enter a hair color (usage: @haircolor/@hcolor ). clif->message(fd, atcmd_output); return false; } @@ -1815,7 +1818,7 @@ ACMD(go) { memset(map_name, '\0', sizeof(map_name)); memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%11s", map_name) < 1) { + if (!*message || sscanf(message, "%11s", map_name) < 1) { // no value matched so send the list of locations const char* text; @@ -1824,7 +1827,7 @@ ACMD(go) { clif->message(fd, msg_fd(fd,38)); // Invalid location number, or name. - if( text ) {// send the text to the client + if (text) { // send the text to the client clif->messageln( fd, text ); } @@ -1915,18 +1918,18 @@ ACMD(monster) memset(monster, '\0', sizeof(monster)); memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message) { + if (!*message) { clif->message(fd, msg_fd(fd,80)); // Please specify a display name or monster name/id. return false; } - if (sscanf(message, "\"%23[^\"]\" %23s %d", name, monster, &number) > 1 || - sscanf(message, "%23s \"%23[^\"]\" %d", monster, name, &number) > 1) { + if (sscanf(message, "\"%23[^\"]\" %23s %12d", name, monster, &number) > 1 || + sscanf(message, "%23s \"%23[^\"]\" %12d", monster, name, &number) > 1) { //All data can be left as it is. - } else if ((count=sscanf(message, "%23s %d %23s", monster, &number, name)) > 1) { + } else if ((count=sscanf(message, "%23s %12d %23s", monster, &number, name)) > 1) { //Here, it is possible name was not given and we are using monster for it. if (count < 3) //Blank mob's name. name[0] = '\0'; - } else if (sscanf(message, "%23s %23s %d", name, monster, &number) > 1) { + } else if (sscanf(message, "%23s %23s %12d", name, monster, &number) > 1) { //All data can be left as it is. } else if (sscanf(message, "%23s", monster) > 0) { //As before, name may be already filled. @@ -1947,7 +1950,7 @@ ACMD(monster) if (number <= 0) number = 1; - if( !name[0] ) + if (!name[0]) strcpy(name, "--ja--"); // If value of atcommand_spawn_quantity_limit directive is greater than or equal to 1 and quantity of monsters is greater than value of the directive @@ -1977,7 +1980,7 @@ ACMD(monster) if (number == count) clif->message(fd, msg_fd(fd,39)); // All monster summoned! else { - sprintf(atcmd_output, msg_fd(fd,240), count); // %d monster(s) summoned! + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,240), count); // %d monster(s) summoned! clif->message(fd, atcmd_output); } else { @@ -1993,12 +1996,10 @@ ACMD(monster) *------------------------------------------*/ int atkillmonster_sub(struct block_list *bl, va_list ap) { - struct mob_data *md; - int flag; - - nullpo_ret(md=(struct mob_data *)bl); - flag = va_arg(ap, int); + struct mob_data *md = (struct mob_data *)bl; + int flag = va_arg(ap, int); + nullpo_ret(bl); if (md->guardian_data) return 0; //Do not touch WoE mobs! @@ -2015,9 +2016,9 @@ ACMD(killmonster) { memset(map_name, '\0', sizeof(map_name)); - if (!message || !*message || sscanf(message, "%15s", map_name) < 1) + if (!*message || sscanf(message, "%15s", map_name) < 1) { map_id = sd->bl.m; - else { + } else { if ((map_id = map->mapname2mapid(map_name)) < 0) map_id = sd->bl.m; } @@ -2041,27 +2042,27 @@ ACMD(refine) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%d %d", &position, &refine) < 2) { + if (!*message || sscanf(message, "%12d %12d", &position, &refine) < 2) { clif->message(fd, msg_fd(fd,996)); // Please enter a position and an amount (usage: @refine <+/- amount>). - sprintf(atcmd_output, msg_fd(fd,997), EQP_HEAD_LOW); // %d: Lower Headgear + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,997), EQP_HEAD_LOW); // %d: Lower Headgear clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,998), EQP_HAND_R); // %d: Right Hand + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,998), EQP_HAND_R); // %d: Right Hand clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,999), EQP_GARMENT); // %d: Garment + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,999), EQP_GARMENT); // %d: Garment clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,1000), EQP_ACC_L); // %d: Left Accessory + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1000), EQP_ACC_L); // %d: Left Accessory clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,1001), EQP_ARMOR); // %d: Body Armor + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1001), EQP_ARMOR); // %d: Body Armor clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,1002), EQP_HAND_L); // %d: Left Hand + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1002), EQP_HAND_L); // %d: Left Hand clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,1003), EQP_SHOES); // %d: Shoes + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1003), EQP_SHOES); // %d: Shoes clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,1004), EQP_ACC_R); // %d: Right Accessory + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1004), EQP_ACC_R); // %d: Right Accessory clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,1005), EQP_HEAD_TOP); // %d: Top Headgear + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1005), EQP_HEAD_TOP); // %d: Top Headgear clif->message(fd, atcmd_output); - sprintf(atcmd_output, msg_fd(fd,1006), EQP_HEAD_MID); // %d: Mid Headgear + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1006), EQP_HEAD_MID); // %d: Mid Headgear clif->message(fd, atcmd_output); return false; } @@ -2103,7 +2104,7 @@ ACMD(refine) else if (count == 1) clif->message(fd, msg_fd(fd,167)); // 1 item has been refined. else { - sprintf(atcmd_output, msg_fd(fd,168), count); // %d items have been refined. + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,168), count); // %d items have been refined. clif->message(fd, atcmd_output); } @@ -2123,9 +2124,9 @@ ACMD(produce) memset(atcmd_output, '\0', sizeof(atcmd_output)); memset(item_name, '\0', sizeof(item_name)); - if (!message || !*message || ( - sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 && - sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1 + if (!*message || ( + sscanf(message, "\"%99[^\"]\" %12d %12d", item_name, &attribute, &star) < 1 && + sscanf(message, "%99s %12d %12d", item_name, &attribute, &star) < 1 )) { clif->message(fd, msg_fd(fd,1007)); // Please enter at least one item name/ID (usage: @produce <# of very's>). return false; @@ -2160,7 +2161,7 @@ ACMD(produce) if ((flag = pc->additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND))) clif->additem(sd, 0, 0, flag); } else { - sprintf(atcmd_output, msg_fd(fd,169), item_id, item_data->name); // The item (%d: '%s') is not equipable. + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,169), item_id, item_data->name); // The item (%d: '%s') is not equipable. clif->message(fd, atcmd_output); return false; } @@ -2177,16 +2178,16 @@ ACMD(memo) memset(atcmd_output, '\0', sizeof(atcmd_output)); - if( !message || !*message || sscanf(message, "%d", &position) < 1 ) + if (!*message || sscanf(message, "%d", &position) < 1) { int i; clif->message(sd->fd, msg_fd(fd,868)); // "Your current memo positions are:" for( i = 0; i < MAX_MEMOPOINTS; i++ ) { if( sd->status.memo_point[i].map ) - sprintf(atcmd_output, "%d - %s (%d,%d)", i, mapindex_id2name(sd->status.memo_point[i].map), sd->status.memo_point[i].x, sd->status.memo_point[i].y); + safesnprintf(atcmd_output, sizeof(atcmd_output), "%d - %s (%d,%d)", i, mapindex_id2name(sd->status.memo_point[i].map), sd->status.memo_point[i].x, sd->status.memo_point[i].y); else - sprintf(atcmd_output, msg_fd(fd,171), i); // %d - void + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,171), i); // %d - void clif->message(sd->fd, atcmd_output); } return true; @@ -2194,7 +2195,7 @@ ACMD(memo) if( position < 0 || position >= MAX_MEMOPOINTS ) { - sprintf(atcmd_output, msg_fd(fd,1008), 0, MAX_MEMOPOINTS-1); // Please enter a valid position (usage: @memo ). + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1008), 0, MAX_MEMOPOINTS-1); // Please enter a valid position (usage: @memo ). clif->message(fd, atcmd_output); return false; } @@ -2212,7 +2213,7 @@ ACMD(gat) { memset(atcmd_output, '\0', sizeof(atcmd_output)); for (y = 2; y >= -2; y--) { - sprintf(atcmd_output, "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", + safesnprintf(atcmd_output, sizeof(atcmd_output), "%s (x= %d, y= %d) %02X %02X %02X %02X %02X", map->list[sd->bl.m].name, sd->bl.x - 2, sd->bl.y + y, map->getcell(sd->bl.m, sd->bl.x - 2, sd->bl.y + y, CELL_GETTYPE), map->getcell(sd->bl.m, sd->bl.x - 1, sd->bl.y + y, CELL_GETTYPE), @@ -2233,7 +2234,7 @@ ACMD(displaystatus) { int i, type, flag, tick, val1 = 0, val2 = 0, val3 = 0; - if (!message || !*message || (i = sscanf(message, "%d %d %d %d %d %d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) { + if (!*message || (i = sscanf(message, "%d %d %d %d %d %d", &type, &flag, &tick, &val1, &val2, &val3)) < 1) { clif->message(fd, msg_fd(fd,1009)); // Please enter a status type/flag (usage: @displaystatus { { {}}}). return false; } @@ -2256,7 +2257,7 @@ ACMD(statuspoint) int point; unsigned int new_status_point; - if (!message || !*message || (point = atoi(message)) == 0) { + if (!*message || (point = atoi(message)) == 0) { clif->message(fd, msg_fd(fd,1010)); // Please enter a number (usage: @stpoint ). return false; } @@ -2304,7 +2305,7 @@ ACMD(skillpoint) int point; unsigned int new_skill_point; - if (!message || !*message || (point = atoi(message)) == 0) { + if (!*message || (point = atoi(message)) == 0) { clif->message(fd, msg_fd(fd,1011)); // Please enter a number (usage: @skpoint ). return false; } @@ -2351,12 +2352,12 @@ ACMD(zeny) { int zeny=0, ret=-1; - if (!message || !*message || (zeny = atoi(message)) == 0) { + if (!*message || (zeny = atoi(message)) == 0) { clif->message(fd, msg_fd(fd,1012)); // Please enter an amount (usage: @zeny ). return false; } - if(zeny > 0){ + if(zeny > 0) { if((ret=pc->getzeny(sd,zeny,LOG_TYPE_COMMAND,NULL)) == 1) clif->message(fd, msg_fd(fd,149)); // Unable to increase the number/value. } @@ -2384,7 +2385,7 @@ ACMD(param) { memset(atcmd_output, '\0', sizeof(atcmd_output)); - if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) { + if (!*message || sscanf(message, "%d", &value) < 1 || value == 0) { clif->message(fd, msg_fd(fd,1013)); // Please enter a valid value (usage: @str/@agi/@vit/@int/@dex/@luk <+/-adjustment>). return false; } @@ -2448,7 +2449,7 @@ ACMD(stat_all) { stats[4] = &sd->status.dex; stats[5] = &sd->status.luk; - if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) { + if (!*message || sscanf(message, "%d", &value) < 1 || value == 0) { value = pc_maxparameter(sd); max = pc_maxparameter(sd); } else { @@ -2497,7 +2498,7 @@ ACMD(guildlevelup) { int16 added_level; struct guild *guild_info; - if (!message || !*message || sscanf(message, "%d", &level) < 1 || level == 0) { + if (!*message || sscanf(message, "%d", &level) < 1 || level == 0) { clif->message(fd, msg_fd(fd,1014)); // Please enter a valid level (usage: @guildlvup/@guildlvlup <# of levels>). return false; } @@ -2538,7 +2539,7 @@ ACMD(makeegg) struct item_data *item_data; int id, pet_id; - if (!message || !*message) { + if (!*message) { clif->message(fd, msg_fd(fd,1015)); // Please enter a monster/egg name/ID (usage: @makeegg ). return false; } @@ -2592,7 +2593,7 @@ ACMD(petfriendly) int friendly; struct pet_data *pd; - if (!message || !*message || (friendly = atoi(message)) < 0) { + if (!*message || (friendly = atoi(message)) < 0) { clif->message(fd, msg_fd(fd,1016)); // Please enter a valid value (usage: @petfriendly <0-1000>). return false; } @@ -2628,7 +2629,7 @@ ACMD(pethungry) int hungry; struct pet_data *pd; - if (!message || !*message || (hungry = atoi(message)) < 0) { + if (!*message || (hungry = atoi(message)) < 0) { clif->message(fd, msg_fd(fd,1017)); // Please enter a valid number (usage: @pethungry <0-100>). return false; } @@ -2684,7 +2685,7 @@ ACMD(petrename) ACMD(recall) { struct map_session_data *pl_sd = NULL; - if (!message || !*message) { + if (!*message) { clif->message(fd, msg_fd(fd,1018)); // Please enter a player name (usage: @recall ). return false; } @@ -2712,7 +2713,7 @@ ACMD(recall) { return false; } pc->setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN); - sprintf(atcmd_output, msg_fd(fd,46), pl_sd->status.name); // %s recalled! + safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,46), pl_sd->status.name); // %s recalled! clif->message(fd, atcmd_output); return true; @@ -2727,7 +2728,7 @@ ACMD(char_block) memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); - if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { + if (!*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) { clif->message(fd, msg_fd(fd,1021)); // Please enter a player name (usage: @block ). return false; } @@ -2763,7 +2764,7 @@ ACMD(char_ban) memset(atcmd_output, '\0', sizeof(atcmd_output)); memset(atcmd_player_name, '\0', sizeof(atcmd_player_name)); - if (!message || !*message || sscanf(message, "%255s %23[^\n]", atcmd_output, atcmd_player_name) < 2) { + if (!*message || sscanf(message, "%255s %23[^\n]", atcmd_output, atcmd_player_name) < 2) { clif->message(fd, msg_fd(fd,1022)); // Please enter ban time and a player name (usage: @ban