diff options
author | shennetsind <ind@henn.et> | 2013-01-31 16:11:07 -0200 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-01-31 16:11:07 -0200 |
commit | 638e2b5c985c13a8138d1cb166d5fdb8148b690c (patch) | |
tree | 61b8cc443ac8171cd203a89744c31d5d51664b2a | |
parent | fc2e159d8c3d45ddeae4ce1dcc84312303442745 (diff) | |
download | hercules-638e2b5c985c13a8138d1cb166d5fdb8148b690c.tar.gz hercules-638e2b5c985c13a8138d1cb166d5fdb8148b690c.tar.bz2 hercules-638e2b5c985c13a8138d1cb166d5fdb8148b690c.tar.xz hercules-638e2b5c985c13a8138d1cb166d5fdb8148b690c.zip |
Fixed Bug #3080
Replaced strncpy with safestrncpy where I found would be beneficial.
http://hercules.ws/board/tracker/issue-3080-safestrncpy-instead-of-strncpy-where-applicable/
Also modifying headers accordingly.
Signed-off-by: shennetsind <ind@henn.et>
-rw-r--r-- | src/char/int_guild.c | 7 | ||||
-rw-r--r-- | src/char/int_pet.c | 7 | ||||
-rw-r--r-- | src/common/mapindex.c | 9 | ||||
-rw-r--r-- | src/login/login.c | 7 | ||||
-rw-r--r-- | src/map/chrif.c | 7 | ||||
-rw-r--r-- | src/map/clif.c | 2 | ||||
-rw-r--r-- | src/map/elemental.c | 10 | ||||
-rw-r--r-- | src/map/homunculus.c | 11 | ||||
-rw-r--r-- | src/map/map.c | 9 | ||||
-rw-r--r-- | src/map/mercenary.c | 9 | ||||
-rw-r--r-- | src/map/mob.c | 7 | ||||
-rw-r--r-- | src/map/npc.c | 9 |
12 files changed, 53 insertions, 41 deletions
diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 7090af5ee..9cb17dca8 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/mmo.h" @@ -1815,7 +1816,7 @@ int mapif_parse_GuildMasterChange(int fd, int guild_id, const char* name, int le g->member[0].position = 0; //Position 0: guild Master. g->member[0].modified = GS_MEMBER_MODIFIED; - strncpy(g->master, name, len); + safestrncpy(g->master, name, len); if (len < NAME_LENGTH) g->master[len] = '\0'; diff --git a/src/char/int_pet.c b/src/char/int_pet.c index 114398290..d9b0cf5ef 100644 --- a/src/char/int_pet.c +++ b/src/char/int_pet.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/mmo.h" #include "../common/malloc.h" @@ -184,7 +185,7 @@ int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short short pet_equip, short intimate, short hungry, char rename_flag, char incuvate, char *pet_name) { memset(pet_pt, 0, sizeof(struct s_pet)); - strncpy(pet_pt->name, pet_name, NAME_LENGTH); + safestrncpy(pet_pt->name, pet_name, NAME_LENGTH); if(incuvate == 1) pet_pt->account_id = pet_pt->char_id = 0; else { diff --git a/src/common/mapindex.c b/src/common/mapindex.c index d46047833..cea945ac0 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/mmo.h" #include "../common/showmsg.h" @@ -37,7 +38,7 @@ const char* mapindex_getmapname(const char* string, char* output) len -= 4; // strip .gat extension len = min(len, MAP_NAME_LENGTH-1); - strncpy(dest, string, len+1); + safestrncpy(dest, string, len+1); memset(&dest[len], '\0', MAP_NAME_LENGTH-len); return dest; @@ -61,7 +62,7 @@ const char* mapindex_getmapname_ext(const char* string, char* output) ShowWarning("(mapindex_normalize_name) Map name '%*s' is too long!\n", 2*MAP_NAME_LENGTH, buf); len--; } - strncpy(dest, buf, len+1); + safestrncpy(dest, buf, len+1); if (len < 4 || stricmp(&dest[len-4], ".gat") != 0) { strcpy(&dest[len], ".gat"); diff --git a/src/login/login.c b/src/login/login.c index e079dbaf2..625e0f5c6 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/core.h" #include "../common/db.h" @@ -1596,7 +1597,7 @@ int login_config_read(const char* cfgName) continue; if(!strcmpi(w1,"timestamp_format")) - strncpy(timestamp_format, w2, 20); + safestrncpy(timestamp_format, w2, 20); else if(!strcmpi(w1,"stdout_with_ansisequence")) stdout_with_ansisequence = config_switch(w2); else if(!strcmpi(w1,"console_silent")) { diff --git a/src/map/chrif.c b/src/map/chrif.c index e109f7095..3ad164b89 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/malloc.h" @@ -246,7 +247,7 @@ int chrif_setip(const char* ip) { return 0; } - strncpy(char_ip_str, ip, sizeof(char_ip_str)); + safestrncpy(char_ip_str, ip, sizeof(char_ip_str)); ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(char_ip, ip_str)); diff --git a/src/map/clif.c b/src/map/clif.c index 3f4ea8bc2..0e555252b 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -203,7 +203,7 @@ int clif_setip(const char* ip) return 0; } - strncpy(map_ip_str, ip, sizeof(map_ip_str)); + safestrncpy(map_ip_str, ip, sizeof(map_ip_str)); ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str)); return 1; } diff --git a/src/map/elemental.c b/src/map/elemental.c index 90b90c1e3..f6c9eff84 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/malloc.h" @@ -10,6 +11,7 @@ #include "../common/showmsg.h" #include "../common/utils.h" #include "../common/random.h" +#include "../common/strlib.h" #include "log.h" #include "clif.h" @@ -795,8 +797,8 @@ int read_elementaldb(void) { db = &elemental_db[j]; db->class_ = atoi(str[0]); - strncpy(db->sprite, str[1], NAME_LENGTH); - strncpy(db->name, str[2], NAME_LENGTH); + safestrncpy(db->sprite, str[1], NAME_LENGTH); + safestrncpy(db->name, str[2], NAME_LENGTH); db->lv = atoi(str[3]); status = &db->status; diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 081287d8a..c94a95775 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/malloc.h" @@ -709,7 +710,7 @@ int merc_hom_change_name_ack(struct map_session_data *sd, char* name, int flag) clif_displaymessage(sd->fd, msg_txt(280)); // You cannot use this name return 0; } - strncpy(hd->homunculus.name,name,NAME_LENGTH); + safestrncpy(hd->homunculus.name,name,NAME_LENGTH); clif_charnameack (0,&hd->bl); hd->homunculus.rename_flag = 1; clif_hominfo(sd,hd,0); @@ -887,7 +888,7 @@ int merc_create_homunculus_request(struct map_session_data *sd, int class_) memset(&homun, 0, sizeof(struct s_homunculus)); //Initial data - strncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1); + safestrncpy(homun.name, homunculus_db[i].name, NAME_LENGTH-1); homun.class_ = class_; homun.level = 1; homun.hunger = 32; //32% @@ -1050,7 +1051,7 @@ static bool read_homunculusdb_sub(char* str[], int columns, int current) } db->evo_class = classid; //Name, Food, Hungry Delay, Base Size, Evo Size, Race, Element, ASPD - strncpy(db->name,str[2],NAME_LENGTH-1); + safestrncpy(db->name,str[2],NAME_LENGTH-1); db->foodID = atoi(str[3]); db->hungryDelay = atoi(str[4]); db->base_size = atoi(str[5]); diff --git a/src/map/map.c b/src/map/map.c index a8521de7d..d2cc9c4a9 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/core.h" @@ -3216,7 +3217,7 @@ int map_config_read(char *cfgName) *ptr = '\0'; if(strcmpi(w1,"timestamp_format")==0) - strncpy(timestamp_format, w2, 20); + safestrncpy(timestamp_format, w2, 20); else if(strcmpi(w1,"stdout_with_ansisequence")==0) stdout_with_ansisequence = config_switch(w2); else if(strcmpi(w1,"console_silent")==0) { @@ -3267,7 +3268,7 @@ int map_config_read(char *cfgName) else if (strcmpi(w1, "charhelp_txt") == 0) strcpy(charhelp_txt, w2); else if(strcmpi(w1,"db_path") == 0) - strncpy(db_path,w2,255); + safestrncpy(db_path,w2,255); else if (strcmpi(w1, "console") == 0) { console = config_switch(w2); if (console) diff --git a/src/map/mercenary.c b/src/map/mercenary.c index 973dac33e..c3fb8e3e2 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/malloc.h" @@ -404,8 +405,8 @@ static bool read_mercenarydb_sub(char* str[], int columns, int current) db = &mercenary_db[current]; db->class_ = atoi(str[0]); - strncpy(db->sprite, str[1], NAME_LENGTH); - strncpy(db->name, str[2], NAME_LENGTH); + safestrncpy(db->sprite, str[1], NAME_LENGTH); + safestrncpy(db->name, str[2], NAME_LENGTH); db->lv = atoi(str[3]); status = &db->status; diff --git a/src/map/mob.c b/src/map/mob.c index ac3c1dfe3..6550d9b0e 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/timer.h" @@ -4120,7 +4121,7 @@ static bool mob_parse_row_chatdb(char** str, const char* source, int line, int* } msg[len] = 0; // strip previously found EOL - strncpy(ms->msg, str[2], CHAT_SIZE_MAX); + safestrncpy(ms->msg, str[2], CHAT_SIZE_MAX); return true; } diff --git a/src/map/npc.c b/src/map/npc.c index 5d8a0274e..8de53a64e 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1,5 +1,6 @@ -// Copyright (c) Athena Dev Teams - Licensed under GNU GPL -// For more information, see LICENCE in the main folder +// Copyright (c) Hercules dev team, licensed under GNU GPL. +// See the LICENSE file +// Portions Copyright (c) Athena dev team #include "../common/cbasetypes.h" #include "../common/timer.h" @@ -1915,7 +1916,7 @@ void npc_addsrcfile(const char* name) file = (struct npc_src_list*)aMalloc(sizeof(struct npc_src_list) + strlen(name)); file->next = NULL; - strncpy(file->name, name, strlen(name) + 1); + safestrncpy(file->name, name, strlen(name) + 1); if( file_prev == NULL ) npc_src_files = file; else @@ -3606,7 +3607,7 @@ void npc_read_event_script(void) DBData *data; char name[64]="::"; - strncpy(name+2,config[i].event_name,62); + safestrncpy(name+2,config[i].event_name,62); script_event[i].event_count = 0; iter = db_iterator(ev_db); |