undefined4 main(int param_1,int param_2)
{
bool bVar1;
int iVar2;
size_t sVar3;
int iVar4;
undefined4 *puVar5;
FILE *__s;
void *__ptr;
char *pcVar6;
char *__s_00;
undefined4 *puVar7;
undefined4 *puVar8;
undefined4 uVar9;
code *pcVar10;
char local_128 [256];
local_128[0] = '\0';
local_128[1] = '\0';
memset(local_128 + 2,0,0xfd) //possible issue identified - semgrep
if (param_1 < 2) goto LAB_00400d08;
if (param_1 == 2) {
LAB_00400ce4:
iVar2 = strncmp(*(char **)(param_2 + 4),"show",4);
uVar9 = 4;
if (iVar2 != 0) {
LAB_00400d08:
FUN_00400940();
return 0xffffffff;
}
}
else {
pcVar6 = *(char **)(param_2 + 4);
iVar2 = strncmp(pcVar6,"add",3);
uVar9 = 0;
if (iVar2 != 0) {
iVar2 = strncmp(pcVar6,"set",3);
uVar9 = 1;
if (iVar2 != 0) {
iVar2 = strncmp(pcVar6,"get",3);
uVar9 = 2;
if (iVar2 != 0) {
iVar2 = strncmp(pcVar6,"del",3);
uVar9 = 3;
if (iVar2 != 0) goto LAB_00400ce4;
}
iVar2 = 2;
do {
memset(local_128,0,0xff) //possible issue identified - semgrep
pcVar6 = *(char **)(param_2 + 8);
sVar3 = strlen(pcVar6);
if (sVar3 + 1 < 0xff) {
strncpy(local_128,pcVar6,sVar3) //possible issue identified - semgrep
strcat(local_128,"=") //possible issue identified - semgrep
FUN_00400a28(&DAT_004120e0,local_128);
}
else {
printf("The Length of parameter \"%s\" is too long!!\n");
}
iVar2 = iVar2 + 1;
param_2 = param_2 + 4;
} while (iVar2 < param_1);
goto LAB_00400e44;
}
}
iVar2 = 2;
do {
__s_00 = *(char **)(param_2 + 8);
pcVar6 = strchr(__s_00,0x3d);
if (pcVar6 == (char *)0x0) {
puts("Format error!!");
puts(*(char **)(param_2 + 8));
}
else {
FUN_00400a28(&DAT_004120e0,__s_00);
}
iVar2 = iVar2 + 1;
param_2 = param_2 + 4;
} while (iVar2 < param_1);
}
LAB_00400e44:
pcVar6 = (char *)fopen("/dev/mtdblock/4","r") //possible issue identified - semgrep
if ((FILE *)pcVar6 == (FILE *)0x0) {
printf("Fail to open %s for reading!!\n","/dev/mtdblock/4");
return 0xffffffff;
}
memset(&env_buf,0,0x3ffc) //possible issue identified - semgrep
sVar3 = fread(&env_buf,0x3ffc,1,(FILE *)pcVar6) //possible issue identified - semgrep
if (sVar3 == 1) {
fclose((FILE *)pcVar6);
iVar2 = env_buf;
iVar4 = crc32(0,&DAT_004120f4,0xffc);
if (iVar2 == iVar4) {
iVar2 = 0;
while( true ) {
sVar3 = strlen(&DAT_004120f4 + iVar2) //possible issue identified - semgrep
if (sVar3 == 0) break;
FUN_00400a28(&DAT_004120e4,&DAT_004120f4 + iVar2);
iVar2 = iVar2 + sVar3 + 1 //possible issue identified - semgrep
}
bVar1 = false;
switch(uVar9) {
case 0:
for (puVar8 = DAT_004120e0; bVar1 = true, puVar8 != (undefined4 *)0x0;
puVar8 = (undefined4 *)*puVar8) {
FUN_00400a28(&DAT_004120e4,puVar8[1]);
}
break;
case 1:
bVar1 = false;
for (puVar8 = DAT_004120e0; puVar8 != (undefined4 *)0x0; puVar8 = (undefined4 *)*puVar8) {
iVar2 = FUN_00400b3c(DAT_004120e4,puVar8[1]);
pcVar6 = (char *)puVar8[1];
if (iVar2 == 0) {
printf("The parameter \"%s\" is not exist!!\n",pcVar6);
}
else {
bVar1 = true;
free(*(void **)(iVar2 + 4));
pcVar6 = strdup(pcVar6) //possible issue identified - semgrep
*(char **)(iVar2 + 4) = pcVar6;
}
}
break;
case 2:
for (puVar8 = DAT_004120e0; bVar1 = false, puVar8 != (undefined4 *)0x0;
puVar8 = (undefined4 *)*puVar8) {
iVar2 = FUN_00400b3c(DAT_004120e4,puVar8[1]);
if (iVar2 == 0) {
pcVar6 = (char *)puVar8[1];
}
else {
pcVar6 = *(char **)(iVar2 + 4);
}
puts(pcVar6);
}
break;
case 3:
bVar1 = false;
for (puVar8 = DAT_004120e0; puVar8 != (undefined4 *)0x0; puVar8 = (undefined4 *)*puVar8) {
puVar5 = (undefined4 *)FUN_00400b3c(DAT_004120e4,puVar8[1]);
puVar7 = DAT_004120e4;
if (puVar5 != (undefined4 *)0x0) {
if (DAT_004120e4 == puVar5) {
puVar5 = DAT_004120e4 + 1;
DAT_004120e4 = (undefined4 *)*DAT_004120e4;
free((void *)*puVar5);
free(puVar7);
bVar1 = true;
}
else {
for (; bVar1 = true, puVar7 != (undefined4 *)0x0; puVar7 = (undefined4 *)*puVar7) {
if ((undefined4 *)*puVar7 == puVar5) {
__ptr = (void *)puVar5[1];
*puVar7 = *puVar5;
free(__ptr);
free(puVar5);
}
}
}
}
}
break;
case 4:
for (puVar8 = DAT_004120e4; bVar1 = false, puVar8 != (undefined4 *)0x0;
puVar8 = (undefined4 *)*puVar8) {
puts((char *)puVar8[1]);
}
break;
default:
FUN_00400940();
}
printf("size:%d\n",0x4000);
if (bVar1) {
memset(&env_buf,0,0x3ffc) //possible issue identified - semgrep
iVar2 = 0;
for (puVar8 = DAT_004120e4; puVar8 != (undefined4 *)0x0; puVar8 = (undefined4 *)*puVar8) {
pcVar6 = (char *)puVar8[1];
sVar3 = strlen(pcVar6);
strncpy(&DAT_004120f4 + iVar2,pcVar6,sVar3 + 1) //possible issue identified - semgrep
sVar3 = strlen((char *)puVar8[1]) //possible issue identified - semgrep
iVar2 = sVar3 + 1 + iVar2 //possible issue identified - semgrep
}
env_buf = crc32(0,&DAT_004120f4,0xffc);
__s = fopen("/dev/mtdblock/4","w") //possible issue identified - semgrep
if (__s == (FILE *)0x0) {
pcVar6 = "Fail to open %s for writing!!\n";
}
else {
sVar3 = fwrite(&env_buf,0x3ffc,1,__s) //possible issue identified - semgrep
if (sVar3 == 1) {
fclose(__s);
pcVar6 = "U-boot environment at %s update successfully!!\n";
}
else {
fclose(__s);
pcVar6 = "U-boot environment at %s update Fail!!\n";
}
}
printf(pcVar6,"/dev/mtdblock/4");
}
goto LAB_0040139c;
}
pcVar10 = puts;
pcVar6 = "CRC error!!";
}
else {
printf("Fail to read %s !!\n","/dev/mtdblock/4");
pcVar10 = fclose;
}
(*pcVar10)(pcVar6);
LAB_0040139c:
if (DAT_004120e4 != (undefined4 *)0x0) {
FUN_00400ad4();
}
if (DAT_004120e0 != (undefined4 *)0x0) {
FUN_00400ad4();
return 0;
}
return 0;
}