From 68f841fcda29ee0af177b0299b52842afcf1bae2 Mon Sep 17 00:00:00 2001 From: Alasdair G Kergon Date: Wed, 18 Sep 2013 01:24:19 +0100 Subject: [PATCH] dmsetup: Detect invalid sector supplied to message. atoll doesn't check for errors, so invalid sector numbers were silently accepted in the "dmsetup message" command. (Mikulas) --- WHATS_NEW_DM | 1 + tools/dmsetup.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 252f105cf..51c771ce5 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.80 - ================================== + Detect invalid sector supplied to 'dmsetup message'. Free any previously-set string if a dm_task_set_* function is called again. Do not allow passing empty new name for dmsetup rename. Display any output returned by 'dmsetup message'. diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 01f49c314..517e8aa64 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -771,6 +771,8 @@ static int _message(CMD_ARGS) struct dm_task *dmt; char *str; const char *response; + uint64_t sector; + char *endptr; if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG))) return 0; @@ -785,7 +787,12 @@ static int _message(CMD_ARGS) argv++; } - if (!dm_task_set_sector(dmt, (uint64_t) atoll(argv[1]))) + sector = strtoull(argv[1], &endptr, 10); + if (*endptr || endptr == argv[1]) { + err("invalid sector"); + goto out; + } + if (!dm_task_set_sector(dmt, sector)) goto out; argc -= 2;