The contents of /proc/uptime is typically something like "80164.57
640617.58", so the existing 512 byte buffer is more than large enoguh,
so reduce its effective size to 511 bytes and ensure we include a
NULL.
Otherwise Coverity points out that we pass a potentially unterminated
string to strtok. In practice this likely doesn't actually cause
issues (at least on Linux) because the
string should always contain a space so we will stop parsing.
CID: 105590
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
static void print_dom0_uptime(int short_mode, time_t now)
{
int fd;
+ ssize_t nr;
char buf[512];
uint32_t uptime = 0;
char *uptime_str = NULL;
if (fd == -1)
goto err;
- if (read(fd, buf, sizeof(buf)) == -1) {
+ nr = read(fd, buf, sizeof(buf) - 1);
+ if (nr == -1) {
close(fd);
goto err;
}
close(fd);
+ buf[nr] = '\0';
+
strtok(buf, " ");
uptime = strtoul(buf, NULL, 10);