Removed. Cleaned. Replaced unsafe strcpy by g_strlcpy.

* glibtop_machine.h (skip_token): Removed.
	* glibtop_server.h (skip_multiple_token): Cleaned.
	* netload.c: (glibtop_get_netload_s): Replaced unsafe strcpy by g_strlcpy.
	* procmap.c: (glibtop_get_proc_map_s): s/strncpy/g_strlcpy/.
	* procstate.c: (glibtop_get_proc_state_s): Likewise.
	* sysinfo.c: (init_sysinfo): Cleaned.
This commit is contained in:
Benoît Dejean
2004-06-06 22:07:44 +00:00
parent 2f87aa4479
commit 54fb1482ba
7 changed files with 23 additions and 27 deletions

View File

@@ -1,3 +1,12 @@
2004-06-07 Benoît Dejean <tazforever@dlfp.org>
* glibtop_machine.h (skip_token): Removed.
* glibtop_server.h (skip_multiple_token): Cleaned.
* netload.c: (glibtop_get_netload_s): Replaced unsafe strcpy by g_strlcpy.
* procmap.c: (glibtop_get_proc_map_s): s/strncpy/g_strlcpy/.
* procstate.c: (glibtop_get_proc_state_s): Likewise.
* sysinfo.c: (init_sysinfo): Cleaned.
2004-05-26 Benoît Dejean <tazforever@dlfp.org> 2004-05-26 Benoît Dejean <tazforever@dlfp.org>
* cpu.c: (glibtop_get_cpu_s): Cleaned whitespaces. * cpu.c: (glibtop_get_cpu_s): Cleaned whitespaces.

View File

@@ -30,18 +30,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#if _IN_LIBGTOP
static inline char *
skip_token(const char *p)
{
while (isspace(*p)) p++;
while (*p && !isspace(*p)) p++;
return (char *)p;
}
#endif
typedef struct _glibtop_machine glibtop_machine; typedef struct _glibtop_machine glibtop_machine;
struct _glibtop_machine struct _glibtop_machine

View File

@@ -42,9 +42,9 @@ skip_token (const char *p)
} }
static inline char * static inline char *
skip_multiple_token (const char *p, int count) skip_multiple_token (const char *p, size_t count)
{ {
int i; size_t i;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
p = skip_token (p); p = skip_token (p);

View File

@@ -114,7 +114,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
struct ifreq ifr; struct ifreq ifr;
unsigned long long flags; unsigned long long flags;
strcpy (ifr.ifr_name, interface); g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) { if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS); buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS);
flags = ifr.ifr_flags; flags = ifr.ifr_flags;
@@ -151,7 +151,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
if (flags & IFF_MULTICAST) if (flags & IFF_MULTICAST)
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST); buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
strcpy (ifr.ifr_name, interface); g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
if (!ioctl (skfd, SIOCGIFADDR, &ifr)) { if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
struct sockaddr_in addr = struct sockaddr_in addr =
*(struct sockaddr_in *) &ifr.ifr_addr; *(struct sockaddr_in *) &ifr.ifr_addr;
@@ -159,7 +159,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS); buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS);
} }
strcpy (ifr.ifr_name, interface); g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) { if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
struct sockaddr_in addr = struct sockaddr_in addr =
*(struct sockaddr_in *) &ifr.ifr_addr; *(struct sockaddr_in *) &ifr.ifr_addr;
@@ -167,7 +167,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET); buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET);
} }
strcpy (ifr.ifr_name, interface); g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
if (!ioctl (skfd, SIOCGIFMTU, &ifr)) { if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
buf->mtu = ifr.ifr_mtu; buf->mtu = ifr.ifr_mtu;
buf->flags |= (1L << GLIBTOP_NETLOAD_MTU); buf->flags |= (1L << GLIBTOP_NETLOAD_MTU);

View File

@@ -120,9 +120,8 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
(guint64) dev_minor; (guint64) dev_minor;
entry_list [n].inode = (guint64) inode; entry_list [n].inode = (guint64) inode;
strncpy (entry_list [n].filename, fn, GLIBTOP_MAP_FILENAME_LEN); g_strlcpy (entry_list [n].filename, fn, sizeof entry_list [n].filename);
entry_list [n].filename [GLIBTOP_MAP_FILENAME_LEN] = 0;
n++; n++;
} while (rv != EOF && rv && fn [0] != EOF); } while (rv != EOF && rv && fn [0] != EOF);

View File

@@ -86,8 +86,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
if (*p++ != '(') if (*p++ != '(')
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid); glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
strncpy (buf->cmd, p, sizeof (buf->cmd)-1); g_strlcpy (buf->cmd, p, sizeof buf->cmd);
buf->cmd [sizeof (buf->cmd)-1] = 0;
buf->flags |= _glibtop_sysdeps_proc_state; buf->flags |= _glibtop_sysdeps_proc_state;
} }

View File

@@ -33,14 +33,15 @@ static glibtop_sysinfo sysinfo;
static void static void
init_sysinfo (glibtop *server) init_sysinfo (glibtop *server)
{ {
char buffer [BUFSIZ]; static gboolean is_init = FALSE;
static int init = 0;
char buffer [BUFSIZ];
glibtop_entry *cpuinfo = NULL; glibtop_entry *cpuinfo = NULL;
FILE *f; FILE *f;
if (init) return; if (is_init) return;
init = TRUE; is_init = TRUE;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);