1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
Description: Catch overflow errors when converting strings to numbers
Passing e.g. `-u 99999999999` would not change the variable at all, yet
not be reported as an error.
Forwarded: yes
Author: Peter Pentchev <roam@ringlet.net>
Last-Update: 2024-12-12
--- a/unixserver.c
+++ b/unixserver.c
@@ -1,3 +1,4 @@
+#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -102,8 +103,9 @@
{
char* ptr;
if (!str) return 0;
+ errno = 0;
*out = strtoul(str, &ptr, base);
- return (*ptr == 0);
+ return (*ptr == 0) && (errno == 0);
}
static void use_uid(const char* str)
|