Skip to content

Commit

Permalink
tools/nut-scanner/nut-scanner.c: -t timeout: fix to use strtol() no…
Browse files Browse the repository at this point in the history
…t atol() [#2244]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 8, 2024
1 parent c1d631a commit d58ba21
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions tools/nut-scanner/nut-scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,12 +957,28 @@ int main(int argc, char *argv[])

switch(opt_ret) {
case 't':
timeout = (useconds_t)atol(optarg) * 1000 * 1000; /*in usec*/
if (timeout <= 0) {
fprintf(stderr,
"Illegal timeout value, using default %ds\n",
DEFAULT_NETWORK_TIMEOUT);
timeout = DEFAULT_NETWORK_TIMEOUT * 1000 * 1000;
{ // scoping
long l;
char *s = NULL;
int errno_saved;

errno = 0;
l = strtol(optarg, &s, 10);
errno_saved = errno;
upsdebugx(6, "errno=%d s='%s'(%p) input='%s'(%p) output=%ld",
errno_saved, NUT_STRARG(s), (void *)s,
optarg, (void *)(optarg), l);

if (errno_saved || (s && *s != '\0') || l <= 0) {
/* TODO: Any max limit? At least,
* max(useconds_t)/1000000 ? */
fprintf(stderr,
"Illegal timeout value, using default %ds\n",
DEFAULT_NETWORK_TIMEOUT);
timeout = DEFAULT_NETWORK_TIMEOUT * 1000 * 1000;
} else {
timeout = (useconds_t)l * 1000 * 1000; /*in usec*/
}
}
break;
case 's':
Expand Down

0 comments on commit d58ba21

Please sign in to comment.