From: claudio Date: Sun, 20 Apr 2014 16:49:56 +0000 (+0000) Subject: Fix conn_gen_kvp and its caller to fill the kvp array properly (including X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=889e0b3b7ab0574105a0c39b25a2f33821963efb;p=openbsd Fix conn_gen_kvp and its caller to fill the kvp array properly (including the NULL terminator at the end). Now iscsid does proper LoginOperational negotiation (which will bump the MaxRecvDataSegmentLength to 64k) --- diff --git a/usr.sbin/iscsid/connection.c b/usr.sbin/iscsid/connection.c index dc63a3ee187..d9c0ad6ae1d 100644 --- a/usr.sbin/iscsid/connection.c +++ b/usr.sbin/iscsid/connection.c @@ -1,4 +1,4 @@ -/* $OpenBSD: connection.c,v 1.13 2011/05/04 21:00:04 claudio Exp $ */ +/* $OpenBSD: connection.c,v 1.14 2014/04/20 16:49:56 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker @@ -313,31 +313,31 @@ conn_gen_kvp(struct connection *c, struct kvp *kvp, size_t *nkvp) size_t i = 0; if (s->mine.MaxConnections != iscsi_sess_defaults.MaxConnections) { - i++; if (kvp && i < *nkvp) { kvp[i].key = strdup("MaxConnections"); if (kvp[i].key == NULL) return (-1); - if (asprintf(&kvp[i].value, "%u", - (unsigned int)s->mine.MaxConnections) == -1) { + if (asprintf(&kvp[i].value, "%hu", + s->mine.MaxConnections) == -1) { kvp[i].value = NULL; return (-1); } } + i++; } if (c->mine.MaxRecvDataSegmentLength != iscsi_conn_defaults.MaxRecvDataSegmentLength) { - i++; if (kvp && i < *nkvp) { kvp[i].key = strdup("MaxRecvDataSegmentLength"); if (kvp[i].key == NULL) return (-1); if (asprintf(&kvp[i].value, "%u", - (unsigned int)c->mine.MaxRecvDataSegmentLength) == -1) { + c->mine.MaxRecvDataSegmentLength) == -1) { kvp[i].value = NULL; return (-1); } } + i++; } *nkvp = i; diff --git a/usr.sbin/iscsid/initiator.c b/usr.sbin/iscsid/initiator.c index 99e914ab43a..a8b794d73d0 100644 --- a/usr.sbin/iscsid/initiator.c +++ b/usr.sbin/iscsid/initiator.c @@ -1,4 +1,4 @@ -/* $OpenBSD: initiator.c,v 1.11 2014/04/19 18:31:33 claudio Exp $ */ +/* $OpenBSD: initiator.c,v 1.12 2014/04/20 16:49:56 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker @@ -276,6 +276,7 @@ initiator_login_kvp(struct connection *c, u_int8_t stage) case ISCSI_LOGIN_STG_OPNEG: if (conn_gen_kvp(c, NULL, &nkvp) == -1) return NULL; + nkvp += 1; /* add slot for terminator */ if (!(kvp = calloc(nkvp, sizeof(*kvp)))) return NULL; if (conn_gen_kvp(c, kvp, &nkvp) == -1) {