[systemd-devel] [PATCH v3] add parameters checking for 'udevadm settle"
Yang Zhiyong
yangzy.fnst at cn.fujitsu.com
Sun Nov 3 19:26:07 PST 2013
This patch adds parameters checking for 'udevadm settle':
- Add extraneous argument checking.
If exist extraneous argument,the program will print stderr and exit.
- Change "seconds"'s type from "int" to "unsigned int".
And use safe_atou() for catching invalid timeout value.
---
src/udev/udevadm-settle.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c
index c4fc4ee..b991da2 100644
--- a/src/udev/udevadm-settle.c
+++ b/src/udev/udevadm-settle.c
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include "udev.h"
+#include "util.h"
static int adm_settle(struct udev *udev, int argc, char *argv[])
{
@@ -56,14 +57,19 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
struct pollfd pfd[1] = { {.fd = -1}, };
struct udev_queue *udev_queue = NULL;
int rc = EXIT_FAILURE;
-
+ int r = -1;
for (;;) {
int option;
- int seconds;
+ unsigned int seconds;
option = getopt_long(argc, argv, "s:e:t:E:qh", options, NULL);
- if (option == -1)
+ if (option == -1) {
+ if (optind < argc) {
+ fprintf(stderr, "Extraneous argument: '%s'\n",argv[optind]);
+ exit(EXIT_FAILURE);
+ }
break;
+ }
switch (option) {
case 's':
@@ -73,11 +79,13 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
end = strtoull(optarg, NULL, 0);
break;
case 't':
- seconds = atoi(optarg);
- if (seconds >= 0)
+ r = safe_atou(optarg,&seconds);
+ if (r < 0) {
+ fprintf(stderr, "Invalid timeout value '%s': %s\n", optarg, strerror(-r));
+ exit(EXIT_FAILURE);
+ } else {
timeout = seconds;
- else
- fprintf(stderr, "invalid timeout value\n");
+ }
break;
case 'q':
quiet = 1;
--
1.8.1
More information about the systemd-devel
mailing list