[U-Boot] [PATCH v2 1/3] net: Correct size of NFS buffers

Reported-by: Coverity (CID: 152888) Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: - Take into account the attributes that could be there - Tested with v2 and v3
net/nfs.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/nfs.h b/net/nfs.h index 6359cd2848..a377c90088 100644 --- a/net/nfs.h +++ b/net/nfs.h @@ -42,6 +42,7 @@ * case, most NFS servers are optimized for a power of 2. */ #define NFS_READ_SIZE 1024 /* biggest power of two that fits Ether frame */ +#define NFS_MAX_ATTRS 26
/* Values for Accept State flag on RPC answers (See: rfc1831) */ enum rpc_accept_stat { @@ -55,7 +56,8 @@ enum rpc_accept_stat {
struct rpc_t { union { - uint8_t data[2048]; + uint8_t data[NFS_READ_SIZE + (6 + NFS_MAX_ATTRS) * + sizeof(uint32_t)]; struct { uint32_t id; uint32_t type; @@ -72,7 +74,8 @@ struct rpc_t { uint32_t verifier; uint32_t v2; uint32_t astatus; - uint32_t data[NFS_READ_SIZE]; + uint32_t data[NFS_READ_SIZE / sizeof(uint32_t) + + NFS_MAX_ATTRS]; } reply; } u; } __attribute__((packed));

The check for sending to the gateway was not using the correct variable for comparison, so it was reporting that packets are sent to the gateway when they were not.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: None
net/nfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/nfs.c b/net/nfs.c index 9a16765ba1..7e8af28e9f 100644 --- a/net/nfs.c +++ b/net/nfs.c @@ -896,7 +896,7 @@ void nfs_start(void) struct in_addr server_net;
our_net.s_addr = net_ip.s_addr & net_netmask.s_addr; - server_net.s_addr = net_server_ip.s_addr & net_netmask.s_addr; + server_net.s_addr = nfs_server_ip.s_addr & net_netmask.s_addr; if (our_net.s_addr != server_net.s_addr) debug("; sending through gateway %pI4", &net_gateway);

Hi Joe,
https://patchwork.ozlabs.org/patch/939038/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git
Thanks! -Joe

nfs was only printing basic info about the transfer in the case of a DEBUG build. Print the same level of detail as tftp always.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: None
net/nfs.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/net/nfs.c b/net/nfs.c index 7e8af28e9f..86dfe9a494 100644 --- a/net/nfs.c +++ b/net/nfs.c @@ -533,7 +533,7 @@ static int nfs_lookup_reply(uchar *pkt, unsigned len) switch (ntohl(rpc_pkt.u.reply.data[0])) { /* Minimal supported NFS version */ case 3: - debug("*** Waring: NFS version not supported: Requested: V%d, accepted: min V%d - max V%d\n", + debug("*** Warning: NFS version not supported: Requested: V%d, accepted: min V%d - max V%d\n", (supported_nfs_versions & NFSV2_FLAG) ? 2 : 3, ntohl(rpc_pkt.u.reply.data[0]), @@ -855,7 +855,7 @@ void nfs_start(void)
if (nfs_path == NULL) { net_set_state(NETLOOP_FAIL); - debug("*** ERROR: Fail allocate memory\n"); + printf("*** ERROR: Fail allocate memory\n"); return; }
@@ -866,8 +866,8 @@ void nfs_start(void) (net_ip.s_addr >> 16) & 0xFF, (net_ip.s_addr >> 24) & 0xFF);
- debug("*** Warning: no boot file name; using '%s'\n", - nfs_path); + printf("*** Warning: no boot file name; using '%s'\n", + nfs_path); } else { char *p = net_boot_file_name;
@@ -885,10 +885,10 @@ void nfs_start(void) nfs_filename = basename(nfs_path); nfs_path = dirname(nfs_path);
- debug("Using %s device\n", eth_get_name()); + printf("Using %s device\n", eth_get_name());
- debug("File transfer via NFS from server %pI4; our IP address is %pI4", - &nfs_server_ip, &net_ip); + printf("File transfer via NFS from server %pI4; our IP address is %pI4", + &nfs_server_ip, &net_ip);
/* Check if we need to send across this subnet */ if (net_gateway.s_addr && net_netmask.s_addr) { @@ -898,17 +898,17 @@ void nfs_start(void) our_net.s_addr = net_ip.s_addr & net_netmask.s_addr; server_net.s_addr = nfs_server_ip.s_addr & net_netmask.s_addr; if (our_net.s_addr != server_net.s_addr) - debug("; sending through gateway %pI4", - &net_gateway); + printf("; sending through gateway %pI4", + &net_gateway); } - debug("\nFilename '%s/%s'.", nfs_path, nfs_filename); + printf("\nFilename '%s/%s'.", nfs_path, nfs_filename);
if (net_boot_file_expected_size_in_blocks) { - debug(" Size is 0x%x Bytes = ", - net_boot_file_expected_size_in_blocks << 9); + printf(" Size is 0x%x Bytes = ", + net_boot_file_expected_size_in_blocks << 9); print_size(net_boot_file_expected_size_in_blocks << 9, ""); } - debug("\nLoad address: 0x%lx\nLoading: *\b", load_addr); + printf("\nLoad address: 0x%lx\nLoading: *\b", load_addr);
net_set_timeout_handler(nfs_timeout, nfs_timeout_handler); net_set_udp_handler(nfs_handler);

Hi Joe,
https://patchwork.ozlabs.org/patch/939039/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git
Thanks! -Joe

Hi Joe,
https://patchwork.ozlabs.org/patch/939037/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git
Thanks! -Joe
participants (1)
-
Joe Hershberger