Denis Vlasenko spotted the lack of bounds checking in my first attempt at
[oweals/busybox.git] / libbb / qmodule.c
1 /* vi: set sw=4 ts=4: */
2 /*
3    Copyright (C) 2002 Tim Riker <Tim@Rikers.org>
4    everyone seems to claim it someplace. ;-)
5 */
6
7 #include <errno.h>
8
9 #include "libbb.h"
10
11 int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret);
12
13 int my_query_module(const char *name, int which, void **buf,
14                 size_t *bufsize, size_t *ret)
15 {
16         int my_ret;
17
18         my_ret = query_module(name, which, *buf, *bufsize, ret);
19
20         if (my_ret == -1 && errno == ENOSPC) {
21                 *buf = xrealloc(*buf, *ret);
22                 *bufsize = *ret;
23
24                 my_ret = query_module(name, which, *buf, *bufsize, ret);
25         }
26
27         return my_ret;
28 }
29
30