Issue information

Issue ID
#5367
Status
Fixed
Severity
None
Started
Hercules Elf Bot
Feb 23, 2012 19:04
Last Post
Hercules Elf Bot
Apr 19, 2012 18:30
Confirmation
Yes (2)
No (0)

Hercules Elf Bot - Feb 23, 2012 19:04

Originally posted by [b]Kazuki-Haru[/b]
[b]Issue:[/b]
Calling [b]linkdb_foreach()[/b] (db.c) with additional parameters will lead to a segfault if there are at least 2 nodes in the linked list.

[b]Cause:[/b]
This happens because after calling va_arg() to retrieve such additional parameters inside func, the va_list is left pointing to unallocated memory. A second iteration will try to read unallocated memory when calling va_arg() again leading to a segfault.

[b]Fix:[/b]
[CODE]
void linkdb_foreach( struct linkdb_node** head, LinkDBFunc func, ... )
{
- va_list args;
struct linkdb_node *node;

if( head == NULL ) return;

- va_start(args, func);
node = *head;
while ( node ) {
+ va_list args;
+ va_start(args, func);
func( node->key, node->data, args );
node = node->next;
+ va_end(args);
}
}
[/CODE]

Hercules Elf Bot - Feb 24, 2012 16:51

Originally posted by [b]Gepard[/b]
Fixed in [rev=15628].