Fixes for problems found by Coverity in the apps/ repository:
nshlib/nsh_parse.c: Avoid truncating the strcmp result into a unsigned char variable. nshlib/nsh_netcmds.c: Check for valid hostip before using it. nshlib/nsh_ddcmd.c: Fix resouce leak when 'if=' or 'of=' params are repeated in the command line. For example: dd if=/dev/null if=/dev/zero of=/dev/null or dd if=/dev/zero of=/dev/zero of=/dev/null
This commit is contained in:
parent
873e4ee83e
commit
3fe720d1e2
@ -246,10 +246,20 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
{
|
{
|
||||||
if (strncmp(argv[i], "if=", 3) == 0)
|
if (strncmp(argv[i], "if=", 3) == 0)
|
||||||
{
|
{
|
||||||
|
if (infile != NULL)
|
||||||
|
{
|
||||||
|
free(infile);
|
||||||
|
}
|
||||||
|
|
||||||
infile = nsh_getfullpath(vtbl, &argv[i][3]);
|
infile = nsh_getfullpath(vtbl, &argv[i][3]);
|
||||||
}
|
}
|
||||||
else if (strncmp(argv[i], "of=", 3) == 0)
|
else if (strncmp(argv[i], "of=", 3) == 0)
|
||||||
{
|
{
|
||||||
|
if (outfile != NULL)
|
||||||
|
{
|
||||||
|
free(outfile);
|
||||||
|
}
|
||||||
|
|
||||||
outfile = nsh_getfullpath(vtbl, &argv[i][3]);
|
outfile = nsh_getfullpath(vtbl, &argv[i][3]);
|
||||||
}
|
}
|
||||||
else if (strncmp(argv[i], "bs=", 3) == 0)
|
else if (strncmp(argv[i], "bs=", 3) == 0)
|
||||||
@ -267,7 +277,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CAN_PIPE_FROM_STD
|
#ifndef CAN_PIPE_FROM_STD
|
||||||
if (!infile || !outfile)
|
if (infile == NULL || outfile == NULL)
|
||||||
{
|
{
|
||||||
nsh_output(vtbl, g_fmtargrequired, g_dd);
|
nsh_output(vtbl, g_fmtargrequired, g_dd);
|
||||||
goto errout_with_paths;
|
goto errout_with_paths;
|
||||||
|
@ -997,21 +997,24 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
if (hostip != NULL)
|
||||||
|
{
|
||||||
#if defined(CONFIG_NSH_DHCPC)
|
#if defined(CONFIG_NSH_DHCPC)
|
||||||
if (!strcmp(hostip, "dhcp"))
|
if (!strcmp(hostip, "dhcp"))
|
||||||
{
|
{
|
||||||
/* Set DHCP addr */
|
/* Set DHCP addr */
|
||||||
|
|
||||||
ninfo("DHCPC Mode\n");
|
ninfo("DHCPC Mode\n");
|
||||||
gip = addr.s_addr = 0;
|
gip = addr.s_addr = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* Set host IP address */
|
/* Set host IP address */
|
||||||
|
|
||||||
ninfo("Host IP: %s\n", hostip);
|
ninfo("Host IP: %s\n", hostip);
|
||||||
gip = addr.s_addr = inet_addr(hostip);
|
gip = addr.s_addr = inet_addr(hostip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
netlib_set_ipv4addr(ifname, &addr);
|
netlib_set_ipv4addr(ifname, &addr);
|
||||||
@ -1020,7 +1023,7 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
if (inet6)
|
if (inet6i != NULL)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#warning Missing Logic
|
#warning Missing Logic
|
||||||
|
@ -1497,10 +1497,10 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
|
|||||||
{
|
{
|
||||||
/* Check if the command is preceded by "while" or "until" */
|
/* Check if the command is preceded by "while" or "until" */
|
||||||
|
|
||||||
whilematch = strcmp(cmd, "while");
|
whilematch = strcmp(cmd, "while") == 0;
|
||||||
untilmatch = strcmp(cmd, "until");
|
untilmatch = strcmp(cmd, "until") == 0;
|
||||||
|
|
||||||
if (whilematch == 0 || untilmatch == 0)
|
if (whilematch || untilmatch)
|
||||||
{
|
{
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user