Fix conn_gen_kvp and its caller to fill the kvp array properly (including
authorclaudio <claudio@openbsd.org>
Sun, 20 Apr 2014 16:49:56 +0000 (16:49 +0000)
committerclaudio <claudio@openbsd.org>
Sun, 20 Apr 2014 16:49:56 +0000 (16:49 +0000)
the NULL terminator at the end). Now iscsid does proper LoginOperational
negotiation (which will bump the MaxRecvDataSegmentLength to 64k)

usr.sbin/iscsid/connection.c
usr.sbin/iscsid/initiator.c

index dc63a3e..d9c0ad6 100644 (file)
@@ -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 <claudio@openbsd.org>
@@ -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;
index 99e914a..a8b794d 100644 (file)
@@ -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 <claudio@openbsd.org>
@@ -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) {