diff options
author | Chris Leech <cleech@redhat.com> | 2019-10-31 12:45:28 -0700 |
---|---|---|
committer | Chris Leech <cleech@redhat.com> | 2019-10-31 15:48:08 -0700 |
commit | 2fc3810607464a111f32f47e5cec06c7daf82f56 (patch) | |
tree | 59ba96383fdafc58e0c8b1be9a564842555854c1 /utils | |
parent | 38680ad69db52cde97536c8413f2ce18a45cc7cd (diff) | |
download | open-iscsi-2fc3810607464a111f32f47e5cec06c7daf82f56.tar.gz |
iscsi-iname: verify prefix length is at most 210 characters
Don't know who might be trying to make really long IQNs ¯\_(ツ)_/¯
Diffstat (limited to 'utils')
-rw-r--r-- | utils/iscsi-iname.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c index 9264a1d..f840f3e 100644 --- a/utils/iscsi-iname.c +++ b/utils/iscsi-iname.c @@ -36,6 +36,10 @@ #define RANDOM_NUM_GENERATOR "/dev/urandom" +/* iSCSI names have a maximum length of 223 characters, we reserve 13 to append + * a seperator and 12 characters (6 random bytes in hex representation) */ +#define PREFIX_MAX_LEN 210 + int main(int argc, char *argv[]) { @@ -67,6 +71,11 @@ main(int argc, char *argv[]) exit(0); } else if ( strcmp(prefix, "-p") == 0 ) { prefix = argv[2]; + if (strnlen(prefix, PREFIX_MAX_LEN + 1) > PREFIX_MAX_LEN) { + printf("Error: Prefix cannot exceed %d " + "characters.\n", PREFIX_MAX_LEN); + exit(1); + } } else { printf("\nUsage: iscsi-iname [-h | --help | " "-p <prefix>]\n"); |