Skip to content

Commit

Permalink
ioctl_tree: Avoid node list overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpitt committed Jan 18, 2022
1 parent 71b0806 commit 96b42a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ioctl_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <errno.h>
#include <linux/ioctl.h>
Expand Down Expand Up @@ -338,8 +339,9 @@ void
ioctl_node_list_append(ioctl_node_list * list, ioctl_tree * element)
{
if (list->n == list->capacity) {
assert(list->capacity < SIZE_MAX / 2);
list->capacity *= 2;
list->items = realloc(list->items, list->capacity * sizeof(ioctl_tree *));
list->items = reallocarray(list->items, list->capacity, sizeof(ioctl_tree *));
assert(list->items != NULL);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ioctl_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef struct {

typedef struct {
ssize_t n;
ssize_t capacity;
size_t capacity;
ioctl_tree **items;
} ioctl_node_list;

Expand Down

0 comments on commit 96b42a3

Please sign in to comment.