Browse Source

fix safecopy: %s too long 8 error on RPC with coins len(name) > 7

Added symbol_len in iguana_coinchoose. Here was a sizeof(symbol)
in safecopy call args, but sizeof(char *) always = 8 on 64-bit systems,
as a result if symbol have more than 7 letters, like "VRSCTEST"
safecopy returns an error.
blackjok3r
DeckerSU 6 years ago
parent
commit
a282cf9684
  1. 15
      iguana/iguana_rpc.c

15
iguana/iguana_rpc.c

@ -687,7 +687,7 @@ char *iguana_bitcoinrpc(struct supernet_info *myinfo,uint16_t port,struct iguana
} }
return(clonestr("{\"error\":\"invalid coin address\"}")); return(clonestr("{\"error\":\"invalid coin address\"}"));
} }
struct iguana_info *iguana_coinchoose(struct supernet_info *myinfo,char *symbol,cJSON *json,uint16_t port) struct iguana_info *iguana_coinchoose(struct supernet_info *myinfo,char *symbol, long symbol_len, cJSON *json,uint16_t port)
{ {
int32_t i,c; struct iguana_info *tmp,*coin = 0; int32_t i,c; struct iguana_info *tmp,*coin = 0;
if ( port == myinfo->rpcport ) if ( port == myinfo->rpcport )
@ -703,9 +703,10 @@ struct iguana_info *iguana_coinchoose(struct supernet_info *myinfo,char *symbol,
} }
else else
{ {
safecopy(symbol,jstr(json,"coin"),sizeof(symbol)); safecopy(symbol, jstr(json, "coin"), symbol_len); // here was sizeof(symbol), but sizeof of pointer (char *) always = 8
for (i=0; symbol[i]!=0; i++) for (i = 0; symbol[i] != 0; i++)
symbol[i] = toupper((int32_t)symbol[i]); symbol[i] = toupper((int32_t)symbol[i]);
} }
} }
else else
@ -726,14 +727,14 @@ struct iguana_info *iguana_coinchoose(struct supernet_info *myinfo,char *symbol,
char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port) char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port)
{ {
cJSON *params[16],*array; struct iguana_info *coin = 0; char symbol[16],*userpass; uint32_t immed; int32_t i,n; char *retstr = 0; cJSON *params[16],*array; struct iguana_info *coin = 0; char symbol[64],*userpass; uint32_t immed; int32_t i,n; char *retstr = 0;
symbol[0] = 0; symbol[0] = 0;
memset(params,0,sizeof(params)); memset(params,0,sizeof(params));
//printf("bitcoinRPC.(%s)\n",jprint(json,0)); //printf("bitcoinRPC.(%s)\n",jprint(json,0));
if ( json != 0 ) if ( json != 0 )
{ {
userpass = jstr(json,"userpass"); userpass = jstr(json,"userpass");
coin = iguana_coinchoose(myinfo,symbol,json,port); coin = iguana_coinchoose(myinfo,symbol, sizeof(symbol), json,port);
if ( myinfo->rpcsymbol[0] == 0 ) if ( myinfo->rpcsymbol[0] == 0 )
strcpy(myinfo->rpcsymbol,symbol); strcpy(myinfo->rpcsymbol,symbol);
if ( coin != 0 ) if ( coin != 0 )
@ -1089,7 +1090,7 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
if ( userpass != 0 && jstr(argjson,"userpass") == 0 ) if ( userpass != 0 && jstr(argjson,"userpass") == 0 )
jaddstr(argjson,"userpass",userpass); jaddstr(argjson,"userpass",userpass);
//printf("after urlconv.(%s) argjson.(%s)\n",jprint(json,0),jprint(argjson,0)); //printf("after urlconv.(%s) argjson.(%s)\n",jprint(json,0),jprint(argjson,0));
coin = iguana_coinchoose(myinfo,symbol,argjson,port); coin = iguana_coinchoose(myinfo,symbol, sizeof(symbol), argjson,port);
if ( (retstr= SuperNET_JSON(myinfo,coin,argjson,remoteaddr,port)) != 0 ) if ( (retstr= SuperNET_JSON(myinfo,coin,argjson,remoteaddr,port)) != 0 )
{ {
if ( (retitem= cJSON_Parse(retstr)) != 0 ) if ( (retitem= cJSON_Parse(retstr)) != 0 )
@ -1111,7 +1112,7 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
arg = jitem(arg,0); arg = jitem(arg,0);
} else arg = argjson; } else arg = argjson;
//printf("ARGJSON.(%s)\n",jprint(arg,0)); //printf("ARGJSON.(%s)\n",jprint(arg,0));
coin = iguana_coinchoose(myinfo,symbol,arg,port); coin = iguana_coinchoose(myinfo,symbol, sizeof(symbol), arg,port);
if ( userpass != 0 && jstr(arg,"userpass") == 0 ) if ( userpass != 0 && jstr(arg,"userpass") == 0 )
jaddstr(arg,"userpass",userpass); jaddstr(arg,"userpass",userpass);
retstr = SuperNET_JSON(myinfo,coin,arg,remoteaddr,port); retstr = SuperNET_JSON(myinfo,coin,arg,remoteaddr,port);

Loading…
Cancel
Save