/*
* sa_conv.c: Convert an old format sa file to the up-to-date format.
- * (C) 1999-2018 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1999-2021 by Sebastien GODARD (sysstat <at> orange.fr)
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify it *
#endif
extern int endian_mismatch;
+extern unsigned int user_hz;
extern unsigned int act_types_nr[];
extern unsigned int rec_types_nr[];
extern unsigned int hdr_types_nr[];
file_hdr->sa_day = f_hdr_2171->sa_day;
file_hdr->sa_month = f_hdr_2171->sa_month;
file_hdr->sa_sizeof_long = f_hdr_2171->sa_sizeof_long;
- strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, UTSNAME_LEN);
- file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, UTSNAME_LEN);
- file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, UTSNAME_LEN);
- file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, UTSNAME_LEN);
- file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
+ strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, sizeof(file_hdr->sa_sysname));
+ file_hdr->sa_sysname[sizeof(file_hdr->sa_sysname) - 1] = '\0';
+ strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, sizeof(file_hdr->sa_nodename));
+ file_hdr->sa_nodename[sizeof(file_hdr->sa_nodename) - 1] = '\0';
+ strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, sizeof(file_hdr->sa_release));
+ file_hdr->sa_release[sizeof(file_hdr->sa_release) - 1] = '\0';
+ strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, sizeof(file_hdr->sa_machine));
+ file_hdr->sa_machine[sizeof(file_hdr->sa_machine) - 1] = '\0';
}
else if (previous_format == FORMAT_MAGIC_2173) {
}
file_hdr->act_size = FILE_ACTIVITY_SIZE;
file_hdr->rec_size = RECORD_HEADER_SIZE;
+
+ /*
+ * Note: @extra_next and @sa_tzname[] members are set to zero
+ * because file_hdr has been memset'd to zero.
+ */
}
/*
a_cpu = TRUE;
}
- /* Size of an activity cannot be zero */
- if (!ofal->size)
+ /* Sanity checks */
+ if (!ofal->size || (ofal->size > MAX_ITEM_STRUCT_SIZE))
goto invalid_header;
/* Size of activity in file is larger than up-to-date activity size */
sndc->tx_compressed = moveto_long_long(&sndp->tx_compressed, endian_mismatch, arch_64);
sndc->multicast = moveto_long_long(&sndp->multicast, endian_mismatch, arch_64);
sndc->speed = 0; /* New field */
- strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
- sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+ sndc->interface[sizeof(sndc->interface) - 1] = '\0';
sndc->duplex = '\0'; /* New field */
}
}
sndc->tx_compressed = sndp->tx_compressed;
sndc->multicast = sndp->multicast;
sndc->speed = 0; /* New field */
- strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
- sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+ sndc->interface[sizeof(sndc->interface) - 1] = '\0';
sndc->duplex = '\0'; /* New field */
}
}
sndc->tx_compressed = sndp->tx_compressed;
sndc->multicast = sndp->multicast;
sndc->speed = sndp->speed;
- strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
- sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+ sndc->interface[sizeof(sndc->interface) - 1] = '\0';
sndc->duplex = sndp->duplex;
}
}
snedc->tx_fifo_errors = moveto_long_long(&snedp->tx_fifo_errors, endian_mismatch, arch_64);
snedc->rx_frame_errors = moveto_long_long(&snedp->rx_frame_errors, endian_mismatch, arch_64);
snedc->tx_carrier_errors = moveto_long_long(&snedp->tx_carrier_errors, endian_mismatch, arch_64);
- strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
- snedc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
+ snedc->interface[sizeof(snedc->interface) - 1] = '\0';
}
}
else {
snedc->tx_fifo_errors = snedp->tx_fifo_errors;
snedc->rx_frame_errors = snedp->rx_frame_errors;
snedc->tx_carrier_errors = snedp->tx_carrier_errors;
- strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
- snedc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
+ snedc->interface[sizeof(snedc->interface) - 1] = '\0';
}
}
}
sfc->f_bavail = sfp->f_bavail;
sfc->f_files = sfp->f_files;
sfc->f_ffree = sfp->f_ffree;
- strncpy(sfc->fs_name, sfp->fs_name, MAX_FS_LEN);
- sfc->fs_name[MAX_FS_LEN - 1] = '\0';
+ strncpy(sfc->fs_name, sfp->fs_name, sizeof(sfc->fs_name));
+ sfc->fs_name[sizeof(sfc->fs_name) - 1] = '\0';
if (st_size <= STATS_FILESYSTEM_8A_1_SIZE) {
/* mountp didn't exist with older versions */
sfc->mountp[0] = '\0';
}
else {
- strncpy(sfc->mountp, sfp->mountp, MAX_FS_LEN);
- sfc->mountp[MAX_FS_LEN - 1] = '\0';
+ strncpy(sfc->mountp, sfp->mountp, sizeof(sfc->mountp));
+ sfc->mountp[sizeof(sfc->mountp) - 1] = '\0';
}
}
}
{
struct record_header rec_hdr;
+ memset(&rec_hdr, 0, sizeof(struct record_header));
+
/* Convert current record header */
rec_hdr.uptime_cs = orec_hdr->uptime0 * 100 / HZ; /* Uptime in cs, not jiffies */
rec_hdr.ust_time = (unsigned long long) orec_hdr->ust_time;
char file_comment[MAX_COMMENT_LEN];
/* Read the COMMENT record */
- sa_fread(fd, file_comment, MAX_COMMENT_LEN, HARD_SIZE, UEOF_STOP);
- file_comment[MAX_COMMENT_LEN - 1] = '\0';
+ sa_fread(fd, file_comment, sizeof(file_comment), HARD_SIZE, UEOF_STOP);
+ file_comment[sizeof(file_comment) - 1] = '\0';
/* Then write it. No changes at this time */
- if (write_all(stdfd, file_comment, MAX_COMMENT_LEN) != MAX_COMMENT_LEN) {
+ if (write_all(stdfd, file_comment, sizeof(file_comment)) != sizeof(file_comment)) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
goto success;
}
- /* Get HZ */
- get_HZ();
+ if (!user_hz) {
+ /* Get HZ */
+ get_HZ();
+ }
+ else {
+ /* HZ set on the command line with option -O */
+ hz = user_hz;
+ }
fprintf(stderr, _("HZ: Using current value: %lu\n"), HZ);
/* Upgrade file's header section */