File: strtoul-errno.patch

package info (click to toggle)
ucspi-unix 1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 452 kB
  • sloc: ansic: 2,606; python: 535; makefile: 14; sh: 1
file content (25 lines) | stat: -rw-r--r-- 606 bytes parent folder | download | duplicates (2)
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)