1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-06 13:06:33 +00:00

Tightened syntax checks to discover bad numerical arguments

This commit is contained in:
Gerhard Rieger 2022-08-12 13:19:03 +02:00
parent 88cdeed092
commit 893d031cc2
10 changed files with 233 additions and 56 deletions

View file

@ -824,3 +824,45 @@ int xiosetenvushort(const char *varname, unsigned short value, int overwrite) {
return xiosetenv(varname, envbuff, overwrite, NULL);
# undef XIO_SHORTLEN
}
unsigned long int Strtoul(const char *nptr, char **endptr, int base, const char *txt) {
unsigned long res;
res = strtoul(nptr, endptr, base);
if (nptr == *endptr) {
Error1("parseopts(): missing numerical value of option \"%s\"", txt);
}
if (**endptr != '\0') {
Error1("parseopts(): trailing garbage in numerical arg of option \"%s\"", txt);
}
return res;
}
#if HAVE_STRTOLL
long long int Strtoll(const char *nptr, char **endptr, int base, const char *txt) {
long long int res;
res = strtoul(nptr, endptr, base);
if (nptr == *endptr) {
Error1("parseopts(): missing numerical value of option \"%s\"", txt);
}
if (**endptr != '\0') {
Error1("parseopts(): trailing garbage in numerical arg of option \"%s\"", txt);
}
return res;
}
#endif /* HAVE_STRTOLL */
double Strtod(const char *nptr, char **endptr, const char *txt) {
double res;
res = strtod(nptr, endptr);
if (nptr == *endptr) {
Error1("parseopts(): missing numerical value of option \"%s\"", txt);
}
if (**endptr != '\0') {
Error1("parseopts(): trailing garbage in numerical arg of option \"%s\"", txt);
}
return res;
}