Skip to content

Commit a90c450

Browse files
committed
linux: set errno when nvme_generate_tls_key_identity() fails
If nvme_generate_tls_key_identity() fails we should set errno to return a more detailed error to the caller. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent a3995d2 commit a90c450

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/nvme/linux.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,22 +1156,29 @@ char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
11561156
int ret = -1;
11571157

11581158
identity_len = nvme_identity_len(hmac, version, hostnqn, subsysnqn);
1159-
if (identity_len < 0)
1159+
if (identity_len < 0) {
1160+
errno = EINVAL;
11601161
return NULL;
1162+
}
11611163

11621164
identity = malloc(identity_len);
1163-
if (!identity)
1165+
if (!identity) {
1166+
errno = ENOMEM;
11641167
return NULL;
1168+
}
11651169

11661170
psk = malloc(key_len);
1167-
if (!psk)
1171+
if (!psk) {
1172+
errno = ENOMEM;
11681173
goto out_free_identity;
1174+
}
11691175

11701176
memset(psk, 0, key_len);
11711177
ret = derive_nvme_keys(hostnqn, subsysnqn, identity, version, hmac,
11721178
configured_key, psk, key_len);
11731179
out_free_identity:
11741180
if (ret < 0) {
1181+
errno = -ret;
11751182
free(identity);
11761183
identity = NULL;
11771184
}

src/nvme/linux.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ long nvme_insert_tls_key_versioned(const char *keyring, const char *key_type,
413413
* generate the corresponding TLs identity.
414414
*
415415
* Return: The string containing the TLS identity. It is the responsibility
416-
* of the caller to free the returned string.
416+
* of the caller to free the returned string. On error NULL is returned with
417+
* errno set.
417418
*/
418419
char *nvme_generate_tls_key_identity(const char *hostnqn, const char *subsysnqn,
419420
int version, int hmac,

0 commit comments

Comments
 (0)