aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-07-04 10:41:38 +0800
committerDaniel Veillard <veillard@redhat.com>2011-07-04 10:41:38 +0800
commit5dc404b71d15d214926eb259a3700a8206dd2838 (patch)
tree245cbddb4bd373a680a74efb4ee67cee39647d91
parentvmware: avoid null deref on failed lookup (diff)
downloadlibvirt-5dc404b71d15d214926eb259a3700a8206dd2838.tar.gz
libvirt-5dc404b71d15d214926eb259a3700a8206dd2838.tar.bz2
libvirt-5dc404b71d15d214926eb259a3700a8206dd2838.zip
storage: avoid crash on parse error
Coverity detected that we could crash on bogus input. Meanwhile, strtok_r is rather heavy compared to strchr. * src/storage/storage_backend_iscsi.c (virStorageBackendIQNFound): Check for parse failure, and use lighter-weight functions.
-rw-r--r--src/storage/storage_backend_iscsi.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 15b5862e6..72887e3c7 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -183,8 +183,7 @@ virStorageBackendIQNFound(const char *initiatoriqn,
int ret = IQN_MISSING, fd = -1;
char ebuf[64];
FILE *fp = NULL;
- char *line = NULL, *newline = NULL, *iqn = NULL, *token = NULL,
- *saveptr = NULL;
+ char *line = NULL, *newline = NULL, *iqn = NULL, *token = NULL;
virCommandPtr cmd = virCommandNewArgList(ISCSIADM,
"--mode", "iface", NULL);
@@ -232,8 +231,15 @@ virStorageBackendIQNFound(const char *initiatoriqn,
iqn++;
if (STREQ(iqn, initiatoriqn)) {
- token = strtok_r(line, " ", &saveptr);
- *ifacename = strdup(token);
+ token = strchr(line, ' ');
+ if (!token) {
+ ret = IQN_ERROR;
+ virStorageReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Missing space when parsing output "
+ "of '%s'"), ISCSIADM);
+ goto out;
+ }
+ *ifacename = strndup(line, token - line);
if (*ifacename == NULL) {
ret = IQN_ERROR;
virReportOOMError();