summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Kardashevskiy <aik@ozlabs.ru>2021-01-27 19:37:39 +1100
committerAlexey Kardashevskiy <aik@ozlabs.ru>2021-02-12 13:46:16 +1100
commit071a09ef070a5eff57c7548be5cdb1bb76c68c23 (patch)
treedec5699da4f786d77e81328fbb76c52e088b80f2
parente244301a3192c91ceed8daf8c03afa1c88328e7e (diff)
downloadqemu-SLOF-071a09ef070a5eff57c7548be5cdb1bb76c68c23.tar.gz
libnet: Compile with -Wextra
-Wextra enables a bunch of rather useful checks which this fixes. This also fixes unused parameters warning by passing meaningful value and doing sanity checks. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> --- Changes: v2: * updated commit log about using AF_INET/etc * replaced cast to int with size_t in pxelinux_load_cfg * added (alen == 0) in ping()
-rw-r--r--lib/libnet/netapps.h4
-rw-r--r--lib/libnet/netload.c4
-rw-r--r--lib/libnet/ping.c6
-rw-r--r--lib/libnet/pxelinux.c5
-rw-r--r--slof/ppc64.c12
5 files changed, 19 insertions, 12 deletions
diff --git a/lib/libnet/netapps.h b/lib/libnet/netapps.h
index 6e00466..722ca7f 100644
--- a/lib/libnet/netapps.h
+++ b/lib/libnet/netapps.h
@@ -18,8 +18,8 @@
struct filename_ip;
-extern int netload(char *buffer, int len, char *args_fs, int alen);
-extern int ping(char *args_fs, int alen);
+extern int netload(char *buffer, int len, char *args_fs, unsigned alen);
+extern int ping(char *args_fs, unsigned alen);
extern int dhcp(char *ret_buffer, struct filename_ip *fn_ip,
unsigned int retries, int flags);
diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c
index 2dc00f0..ae169f3 100644
--- a/lib/libnet/netload.c
+++ b/lib/libnet/netload.c
@@ -528,7 +528,7 @@ static void encode_response(char *pkt_buffer, size_t size, int ip_init)
}
}
-int netload(char *buffer, int len, char *args_fs, int alen)
+int netload(char *buffer, int len, char *args_fs, unsigned alen)
{
int rc, filename_len;
filename_ip_t fn_ip;
@@ -566,7 +566,7 @@ int netload(char *buffer, int len, char *args_fs, int alen)
set_timer(TICKS_SEC);
while (get_timer() > 0);
}
- fd_device = socket(0, 0, 0, (char*) own_mac);
+ fd_device = socket(AF_INET, SOCK_DGRAM, 0, (char*) own_mac);
if(fd_device != -2)
break;
if(getchar() == 27) {
diff --git a/lib/libnet/ping.c b/lib/libnet/ping.c
index 51db061..6ff6f9f 100644
--- a/lib/libnet/ping.c
+++ b/lib/libnet/ping.c
@@ -106,7 +106,7 @@ parse_args(const char *args, struct ping_args *ping_args)
return 0;
}
-int ping(char *args_fs, int alen)
+int ping(char *args_fs, unsigned alen)
{
short arp_failed = 0;
filename_ip_t fn_ip;
@@ -119,7 +119,7 @@ int ping(char *args_fs, int alen)
memset(&ping_args, 0, sizeof(struct ping_args));
- if (alen <= 0 || alen >= sizeof(args) - 1) {
+ if (alen == 0 || alen >= sizeof(args) - 1) {
usage();
return -1;
}
@@ -137,7 +137,7 @@ int ping(char *args_fs, int alen)
/* Get mac_addr from device */
printf("\n Reading MAC address from device: ");
- fd_device = socket(0, 0, 0, (char *) own_mac);
+ fd_device = socket(AF_INET, SOCK_DGRAM, 0, (char *) own_mac);
if (fd_device == -1) {
printf("\nE3000: Could not read MAC address\n");
return -100;
diff --git a/lib/libnet/pxelinux.c b/lib/libnet/pxelinux.c
index c4ac5d5..b32f233 100644
--- a/lib/libnet/pxelinux.c
+++ b/lib/libnet/pxelinux.c
@@ -55,7 +55,8 @@ static int pxelinux_tftp_load(filename_ip_t *fnip, void *buffer, int len,
static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid,
int retries, char *cfgbuf, int cfgbufsize)
{
- int rc, idx;
+ int rc;
+ unsigned idx;
char *baseptr;
/* Did we get a usable base directory via DHCP? */
@@ -77,7 +78,7 @@ static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uui
++baseptr;
/* Check that we've got enough space to store "pxelinux.cfg/"
* and the UUID (which is the longest file name) there */
- if (baseptr - fn_ip->filename > sizeof(fn_ip->filename) - 50) {
+ if ((size_t)(baseptr - fn_ip->filename) > (sizeof(fn_ip->filename) - 50)) {
puts("Error: The bootfile string is too long for "
"deriving the pxelinux.cfg file name from it.");
return -1;
diff --git a/slof/ppc64.c b/slof/ppc64.c
index 83a8e82..ca6caff 100644
--- a/slof/ppc64.c
+++ b/slof/ppc64.c
@@ -144,6 +144,12 @@ int socket(int domain, int type, int proto, char *mac_addr)
int prop_len;
int fd;
+ if (!(domain == AF_INET || domain == AF_INET6))
+ return -1;
+
+ if (type != SOCK_DGRAM || proto != 0)
+ return -1;
+
/* search free file descriptor (and skip stdio handlers) */
for (fd = 3; fd < FILEIO_MAX; ++fd) {
if (fd_array[fd].type == FILEIO_TYPE_EMPTY) {
@@ -217,7 +223,7 @@ int close(int fd)
*/
int recv(int fd, void *buf, int len, int flags)
{
- if (!is_valid_fd(fd))
+ if (!is_valid_fd(fd) || flags)
return -1;
forth_push((unsigned long)buf);
@@ -237,7 +243,7 @@ int recv(int fd, void *buf, int len, int flags)
*/
int send(int fd, const void *buf, int len, int flags)
{
- if (!is_valid_fd(fd))
+ if (!is_valid_fd(fd) || flags)
return -1;
forth_push((unsigned long)buf);
@@ -258,7 +264,7 @@ int send(int fd, const void *buf, int len, int flags)
ssize_t read(int fd, void *buf, size_t len)
{
char *ptr = (char *)buf;
- int cnt = 0;
+ unsigned cnt = 0;
char code;
if (fd == 0 || fd == 2) {