Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108676823
D33545.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D33545.diff
View Options
diff --git a/lib/libiscsiutil/keys.c b/lib/libiscsiutil/keys.c
--- a/lib/libiscsiutil/keys.c
+++ b/lib/libiscsiutil/keys.c
@@ -51,7 +51,10 @@
keys_delete(struct keys *keys)
{
- free(keys->keys_data);
+ for (int i = 0; i < KEYS_MAX; i++) {
+ free(keys->keys_names[i]);
+ free(keys->keys_values[i]);
+ }
free(keys);
}
@@ -59,7 +62,7 @@
keys_load(struct keys *keys, const struct pdu *pdu)
{
int i;
- char *pair;
+ char *keys_data, *name, *pair, *value;
size_t pair_len;
if (pdu->pdu_data_len == 0)
@@ -68,35 +71,36 @@
if (pdu->pdu_data[pdu->pdu_data_len - 1] != '\0')
log_errx(1, "protocol error: key not NULL-terminated\n");
- assert(keys->keys_data == NULL);
- keys->keys_data_len = pdu->pdu_data_len;
- keys->keys_data = malloc(keys->keys_data_len);
- if (keys->keys_data == NULL)
+ keys_data = malloc(pdu->pdu_data_len);
+ if (keys_data == NULL)
log_err(1, "malloc");
- memcpy(keys->keys_data, pdu->pdu_data, keys->keys_data_len);
+ memcpy(keys_data, pdu->pdu_data, pdu->pdu_data_len);
/*
* XXX: Review this carefully.
*/
- pair = keys->keys_data;
+ pair = keys_data;
for (i = 0;; i++) {
if (i >= KEYS_MAX)
log_errx(1, "too many keys received");
pair_len = strlen(pair);
- keys->keys_values[i] = pair;
- keys->keys_names[i] = strsep(&keys->keys_values[i], "=");
- if (keys->keys_names[i] == NULL || keys->keys_values[i] == NULL)
+ value = pair;
+ name = strsep(&value, "=");
+ if (name == NULL || value == NULL)
log_errx(1, "malformed keys");
+ keys->keys_names[i] = checked_strdup(name);
+ keys->keys_values[i] = checked_strdup(value);
log_debugx("key received: \"%s=%s\"",
keys->keys_names[i], keys->keys_values[i]);
pair += pair_len + 1; /* +1 to skip the terminating '\0'. */
- if (pair == keys->keys_data + keys->keys_data_len)
+ if (pair == keys_data + pdu->pdu_data_len)
break;
- assert(pair < keys->keys_data + keys->keys_data_len);
+ assert(pair < keys_data + pdu->pdu_data_len);
}
+ free(keys_data);
}
void
diff --git a/lib/libiscsiutil/libiscsiutil.h b/lib/libiscsiutil/libiscsiutil.h
--- a/lib/libiscsiutil/libiscsiutil.h
+++ b/lib/libiscsiutil/libiscsiutil.h
@@ -75,8 +75,6 @@
struct keys {
char *keys_names[KEYS_MAX];
char *keys_values[KEYS_MAX];
- char *keys_data;
- size_t keys_data_len;
};
#define CHAP_CHALLENGE_LEN 1024
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 28, 6:09 AM (4 h, 12 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16254461
Default Alt Text
D33545.diff (2 KB)
Attached To
Mode
D33545: libiscsiutil: Fix a memory leak with negotiation keys.
Attached
Detach File
Event Timeline
Log In to Comment