Adjust 'after' so that it tries more rigorously to parse the input
[sgt/utils] / after / after.c
index 5c8cbe4..eb74813 100644 (file)
@@ -219,7 +219,7 @@ void licence(void) {
 }
 
 void version(void) {
-#define SVN_REV "$Revision: 6566 $"
+#define SVN_REV "$Revision$"
     char rev[sizeof(SVN_REV)];
     char *p, *q;
 
@@ -274,7 +274,14 @@ int main(int argc, char **argv)
                fprintf(stderr, "%s: parameter `%s' unexpected\n", pname, p);
                return 1;
            } else {
-               pid = atoi(p);
+                char *end;
+                errno = 0;
+               pid = strtol(p, &end, 0);
+                if (errno == ERANGE || *end || pid < 0) {
+                    fprintf(stderr, "%s: unable to parse `%s' as a pid\n",
+                            pname, p);
+                    return 1;
+                }
            }
        }
     }