mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Bug 944, SMB: Fix leaks and libsmbclient 3.0.10 compatibility.
This commit is contained in:
parent
5289a840d8
commit
11e6aa8d97
@ -185,22 +185,44 @@ sort_and_display_entries(int dir, unsigned char dircolor[])
|
|||||||
if (!strcmp(fentry->name, "."))
|
if (!strcmp(fentry->name, "."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
new_entry = mem_alloc(length);
|
/* Preallocate a @table element, but don't increment
|
||||||
if (fentry->comment) {
|
* @size yet. This way, we need not explicitly free
|
||||||
char *comment = mem_alloc(fentry->commentlen + 1);
|
* the element if something goes wrong. It may cause
|
||||||
|
* CHECK_USELESS_REALLOC to complain, though. */
|
||||||
if (comment) memcpy(comment, fentry->comment, fentry->commentlen + 1);
|
|
||||||
fentry->comment = comment;
|
|
||||||
}
|
|
||||||
if (!new_entry)
|
|
||||||
continue;
|
|
||||||
new_table = mem_realloc(table, (size + 1) * sizeof(*table));
|
new_table = mem_realloc(table, (size + 1) * sizeof(*table));
|
||||||
if (!new_table)
|
if (!new_table)
|
||||||
continue;
|
continue;
|
||||||
memcpy(new_entry, fentry, length);
|
|
||||||
table = new_table;
|
table = new_table;
|
||||||
table[size] = new_entry;
|
|
||||||
size++;
|
new_entry = mem_alloc(length);
|
||||||
|
if (!new_entry)
|
||||||
|
continue;
|
||||||
|
memcpy(new_entry, fentry, length);
|
||||||
|
|
||||||
|
/* In libsmbclient 3.0.10, @smbc_dirent.namelen and
|
||||||
|
* @smbc_dirent.commentlen include the null characters
|
||||||
|
* (tested with GDB). In libsmbclient 3.0.24, they
|
||||||
|
* don't. This is related to Samba bug 3030. Adjust
|
||||||
|
* the lengths to exclude the null characters, so that
|
||||||
|
* other code need not care. */
|
||||||
|
if (new_entry->commentlen > 0
|
||||||
|
&& new_entry->comment[new_entry->commentlen - 1] == '\0')
|
||||||
|
new_entry->commentlen--;
|
||||||
|
if (new_entry->namelen > 0
|
||||||
|
&& new_entry->name[new_entry->namelen - 1] == '\0')
|
||||||
|
new_entry->namelen--;
|
||||||
|
|
||||||
|
if (new_entry->comment) {
|
||||||
|
/* memacpy appends a null character. */
|
||||||
|
new_entry->comment = memacpy(new_entry->comment,
|
||||||
|
new_entry->commentlen);
|
||||||
|
if (new_entry->comment == NULL) {
|
||||||
|
mem_free(new_entry);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table[size++] = new_entry;
|
||||||
}
|
}
|
||||||
qsort(table, size, sizeof(*table),
|
qsort(table, size, sizeof(*table),
|
||||||
(int (*)(const void *, const void *)) compare);
|
(int (*)(const void *, const void *)) compare);
|
||||||
|
Loading…
Reference in New Issue
Block a user