[sheepdog] [PATCH] dog:fix dog command misinterpretation when characters are mixed in a -p option

Yuichi Bando bando.yuichi at lab.ntt.co.jp
Mon Apr 21 03:57:22 CEST 2014


This bug is reported in https://bugs.launchpad.net/sheepdog-project/+bug/1309301
I added a check code if the port number (specified in -p option) is numeric or not.

=== Bug Description ===
I found that dog command misinterprets when characters are mixed in a numeric option.

Here's the example.

$dog vdi list -p 7X000
  Name Id Size Used Shared Creation time VDI id Copies Tag
failed to connect to 127.0.0.1:7: Connection refused
failed to connect to 127.0.0.1:7: Connection refused

dog interpreted "7X000" as "7".
I think that dog should output error message " Invalid port number '7X000' ".

=== After modified ===
$dog vdi list -p 7X000
Invalid port number '7X000'

Thanks
Yuichi Bando

Signed-off-by: Yuichi Bando <bando.yuichi at lab.ntt.co.jp>
---
 dog/dog.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/dog/dog.c b/dog/dog.c
index fbedd6d..e12f73d 100644
--- a/dog/dog.c
+++ b/dog/dog.c
@@ -467,8 +467,7 @@ int main(int argc, char **argv)
 			break;
 		case 'p':
 			sdport = strtol(optarg, &p, 10);
-			if (optarg == p || sdport < 1 || sdport > UINT16_MAX) {
+			if (optarg == p || sdport < 1 || sdport > UINT16_MAX || !is_numeric(optarg)) {
 				sd_err("Invalid port number '%s'", optarg);
 				exit(EXIT_USAGE);
 			}
-- 
1.7.1





More information about the sheepdog mailing list