summaryrefslogtreecommitdiff
path: root/src/map/pc.c
diff options
context:
space:
mode:
authorglighta <glighta@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-11-14 02:26:00 +0000
committerglighta <glighta@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-11-14 02:26:00 +0000
commit4e406f3ed6e6f8b2b8434a366a5e54c8f7186f45 (patch)
treeae5f4769d161f5693f94e95b1623909a3d75eaf9 /src/map/pc.c
parentdc88ae10c96b5d5d9d40fccbb102f1ec80058063 (diff)
downloadhercules-4e406f3ed6e6f8b2b8434a366a5e54c8f7186f45.tar.gz
hercules-4e406f3ed6e6f8b2b8434a366a5e54c8f7186f45.tar.bz2
hercules-4e406f3ed6e6f8b2b8434a366a5e54c8f7186f45.tar.xz
hercules-4e406f3ed6e6f8b2b8434a366a5e54c8f7186f45.zip
Following r16914
-fix @zeny for negative amout bugreport:6886, bugreport:6895 bugreport:6888 -fix @cash,@points command display result -enforce bound chk for both git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16924 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/pc.c')
-rw-r--r--src/map/pc.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 986087484..b54b88ae2 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -3590,6 +3590,7 @@ int pc_payzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type,
{
nullpo_ret(sd);
+ zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
if( zeny < 0 )
{
ShowError("pc_payzeny: Paying negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
@@ -3616,16 +3617,17 @@ int pc_payzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type,
* Cash Shop
*------------------------------------------*/
-void pc_paycash(struct map_session_data *sd, int price, int points)
+int pc_paycash(struct map_session_data *sd, int price, int points)
{
char output[128];
int cash;
nullpo_retv(sd);
+ points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
if( price < 0 || points < 0 )
{
ShowError("pc_paycash: Paying negative points (price=%d, points=%d, account_id=%d, char_id=%d).\n", price, points, sd->status.account_id, sd->status.char_id);
- return;
+ return -2;
}
if( points > price )
@@ -3639,7 +3641,7 @@ void pc_paycash(struct map_session_data *sd, int price, int points)
if( sd->cashPoints < cash || sd->kafraPoints < points )
{
ShowError("pc_paycash: Not enough points (cash=%d, kafra=%d) to cover the price (cash=%d, kafra=%d) (account_id=%d, char_id=%d).\n", sd->cashPoints, sd->kafraPoints, cash, points, sd->status.account_id, sd->status.char_id);
- return;
+ return -1;
}
pc_setaccountreg(sd, "#CASHPOINTS", sd->cashPoints-cash);
@@ -3650,13 +3652,16 @@ void pc_paycash(struct map_session_data *sd, int price, int points)
sprintf(output, msg_txt(504), points, cash, sd->kafraPoints, sd->cashPoints);
clif_disp_onlyself(sd, output, strlen(output));
}
+ return cash+points;
}
-void pc_getcash(struct map_session_data *sd, int cash, int points)
+int pc_getcash(struct map_session_data *sd, int cash, int points)
{
char output[128];
nullpo_retv(sd);
+ cash = cap_value(cash,-MAX_ZENY,MAX_ZENY); //prevent command UB
+ points = cap_value(points,-MAX_ZENY,MAX_ZENY); //prevent command UB
if( cash > 0 )
{
if( cash > MAX_ZENY-sd->cashPoints )
@@ -3672,10 +3677,12 @@ void pc_getcash(struct map_session_data *sd, int cash, int points)
sprintf(output, msg_txt(505), cash, sd->cashPoints);
clif_disp_onlyself(sd, output, strlen(output));
}
+ return cash;
}
else if( cash < 0 )
{
ShowError("pc_getcash: Obtaining negative cash points (cash=%d, account_id=%d, char_id=%d).\n", cash, sd->status.account_id, sd->status.char_id);
+ return -1;
}
if( points > 0 )
@@ -3693,11 +3700,14 @@ void pc_getcash(struct map_session_data *sd, int cash, int points)
sprintf(output, msg_txt(506), points, sd->kafraPoints);
clif_disp_onlyself(sd, output, strlen(output));
}
+ return points;
}
else if( points < 0 )
{
ShowError("pc_getcash: Obtaining negative kafra points (points=%d, account_id=%d, char_id=%d).\n", points, sd->status.account_id, sd->status.char_id);
+ return -1;
}
+ return -2; //shouldn't happen but jsut in case
}
/*==========================================
@@ -3708,6 +3718,7 @@ int pc_getzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type,
{
nullpo_ret(sd);
+ zeny = cap_value(zeny,-MAX_ZENY,MAX_ZENY); //prevent command UB
if( zeny < 0 )
{
ShowError("pc_getzeny: Obtaining negative Zeny (zeny=%d, account_id=%d, char_id=%d).\n", zeny, sd->status.account_id, sd->status.char_id);
@@ -3720,7 +3731,7 @@ int pc_getzeny(struct map_session_data *sd,int zeny, enum e_log_pick_type type,
sd->status.zeny += zeny;
clif_updatestatus(sd,SP_ZENY);
- if(!sd) tsd = sd;
+ if(!tsd) tsd = sd;
log_zeny(sd, type, tsd, zeny);
if( zeny > 0 && sd->state.showzeny ) {
char output[255];