From: Sebastien Godard Date: Sun, 6 Feb 2011 07:27:12 +0000 (+0100) Subject: Check calloc() return value in nfsiostat and cifsiostat. X-Git-Tag: v10.0.0~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01b3d993fd51080ef24bf848a7e13e67a9568f9b;p=sysstat Check calloc() return value in nfsiostat and cifsiostat. A call to calloc() function to allocate structures in nfsiostat and cifsiostat wasn't checked for its return code. This call could possibly fail without ever being noticed. Mail from Ivana Varekova (varekova@redhat.com) 02/02/2011 Hello, I'm sending 6 patches - 3 for nfsiostat and 3 for cifsiostat nfsiostat: nfsiostat2.patch - adds the forgotten test to malloc (...) cifsiostat: cifsiostat2.patch - adds the forgotten test to malloc (...) --- diff --git a/CHANGES b/CHANGES index 4045799..e5525c3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,8 +1,10 @@ Changes: xxxx/xx/xx: Version 10.0.0 - Sebastien Godard (sysstat orange.fr) - * [Jan Kaluza]: Added --debuginfo option to cifsiostat. - * [Jan Kaluza]: Added --debuginfo option to nfsiostat. + * [Ivana Varekova]: Check calloc() return value in cifsiostat + and nfsiostat. + * [Jan Kaluza]: Added --debuginfo option to cifsiostat and + nfsiostat. * cifsiostat and nfsiostat manual pages updated. * sysstat_panic function is now defined only in DEBUG mode. * NLS updated. Ukrainian translation added. diff --git a/cifsiostat.c b/cifsiostat.c index 8aeddae..5d9f127 100644 --- a/cifsiostat.c +++ b/cifsiostat.c @@ -174,7 +174,10 @@ void io_sys_init(void) if ((cifs_nr = get_cifs_nr()) > 0) { cifs_nr += NR_CIFS_PREALLOC; } - st_hdr_cifs = (struct io_hdr_stats *) calloc(cifs_nr, IO_HDR_STATS_SIZE); + if ((st_hdr_cifs = (struct io_hdr_stats *) calloc(cifs_nr, IO_HDR_STATS_SIZE)) == NULL) { + perror("malloc"); + exit(4); + } /* Allocate structures for number of CIFS directories found */ for (i = 0; i < 2; i++) { diff --git a/nfsiostat.c b/nfsiostat.c index 70cd931..4222bd3 100644 --- a/nfsiostat.c +++ b/nfsiostat.c @@ -198,7 +198,10 @@ void io_sys_init(void) if ((ionfs_nr = get_nfs_mount_nr()) > 0) { ionfs_nr += NR_NFS_PREALLOC; } - st_hdr_ionfs = (struct io_hdr_stats *) calloc(ionfs_nr, IO_HDR_STATS_SIZE); + if ((st_hdr_ionfs = (struct io_hdr_stats *) calloc(ionfs_nr, IO_HDR_STATS_SIZE)) == NULL) { + perror("malloc"); + exit(4); + } /* Allocate structures for number of NFS directories found */ for (i = 0; i < 2; i++) {