Commit 7bc551ba authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(assign_timeval): Added overflow checking.

parent d3b9f65d
/*
* $Id: conf-file.c,v 1.30 2003/07/16 07:33:01 ceder Exp $
* $Id: conf-file.c,v 1.31 2003/07/21 22:26:16 ceder Exp $
* Copyright (C) 1994-1995, 1998-1999, 2001-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -429,8 +429,10 @@ assign_timeval(const char *val,
{
char *tail = NULL;
double number;
double err;
const char *suffix;
const struct suffix_conversion *s;
struct timeval tv;
assert(par->default_suffix != NULL);
......@@ -454,12 +456,33 @@ assign_timeval(const char *val,
break;
if (s->suffix == NULL)
{
kom_log("Bad suffix for parameter %s\n", par->name);
return FAILURE;
}
number *= s->factor;
*(struct timeval*)par->value = timeval_ctor(
number, ((number - (int)number) * 1000000) + 0.5);
if (number < 0)
{
kom_log("Negative values not supported for parameter %s\n",
par->name);
return FAILURE;
}
tv = timeval_ctor(number, ((number - (int)number) * 1000000) + 0.5);
err = (tv.tv_sec + 1.0e-6 * tv.tv_usec) - number;
if (err < 0)
err = -err;
if ((err > 1.0e-6 && err < 1.0e-6 * number)
|| tv.tv_sec < 0
|| tv.tv_usec < 0
|| tv.tv_usec >= 1000000)
{
kom_log("Overflow for parameter %s (%s)\n", par->name, val);
return FAILURE;
}
*(struct timeval*)par->value = tv;
}
return OK;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment