Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/tpi buffer overflow #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/tpi/tpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ bool power(int arg)
{
char cmd[128] = {0};
if(arg==1)
sprintf(cmd,"curl 'http://%s/api/bmc?opt=set&type=power&node1=1&node2=1&node3=1&node4=1'",host);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=set&type=power&node1=1&node2=1&node3=1&node4=1'",host);
else if(0==arg)
sprintf(cmd,"curl 'http://%s/api/bmc?opt=set&type=power&node1=0&node2=0&node3=0&node4=0'",host);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=set&type=power&node1=0&node2=0&node3=0&node4=0'",host);
else if(2 == arg)
{
sprintf(cmd,"curl 'http://%s/api/bmc?opt=get&type=power'",host);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=get&type=power'",host);
}
system(cmd);
}
Expand All @@ -58,29 +58,29 @@ bool usb_ctrl(int mode,int node)
{
char cmd[128] = {0};
if(mode==2)
sprintf(cmd,"curl 'http://%s/api/bmc?opt=get&type=usb'",host);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=get&type=usb'",host);
else
sprintf(cmd,"curl 'http://%s/api/bmc?opt=set&type=usb&mode=%d&node=%d'",host,mode,node-1);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=set&type=usb&mode=%d&node=%d'",host,mode,node-1);
system(cmd);
}

bool resetSW(void)
{
char cmd[128] = {0};
sprintf(cmd,"curl 'http://%s/api/bmc?opt=set&type=network&cmd=reset'",host);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=set&type=network&cmd=reset'",host);
system(cmd);
}

bool uart_ctrl(int mode,int node,char* data)
{
char cmd[128] = {0};
if(mode==0)
sprintf(cmd,"curl 'http://%s/api/bmc?opt=get&type=uart&node=%d'",host,node);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=get&type=uart&node=%d'",host,node);
else
{
if(NULL==data)
return false;
sprintf(cmd,"curl 'http://%s/api/bmc?opt=set&type=uart&node=%d&cmd=%s'",host,node,data);
snprintf(cmd,sizeof(cmd),"curl 'http://%s/api/bmc?opt=set&type=uart&node=%d&cmd=%s'",host,node,data);
}

system(cmd);
Expand All @@ -92,7 +92,7 @@ bool update_fw(char* file)
bool ret = false;
char cmd[128] = {0};
char line[1024] = {0};
sprintf(cmd,"curl -F 'file=@%s' 'http://%s/api/bmc?opt=set&type=firmware'",file,host);
snprintf(cmd,sizeof(cmd),"curl -F 'file=@%s' 'http://%s/api/bmc?opt=set&type=firmware'",file,host);

FILE* pp = popen(cmd,"r");
if(pp)
Expand Down Expand Up @@ -406,11 +406,11 @@ int main(int argc, char *argv[])
case 'F':
{
mode = 4;
strcpy(up_file,optarg);
strncpy(up_file,optarg,sizeof(up_file));
}
case 'C':
{
strcpy(uart_cmd,optarg);
strncpy(uart_cmd,optarg,sizeof(uart_cmd));
break;
}
default:
Expand Down