Skip to content

Commit 925bd2d

Browse files
committed
Check the parameters to auplugin_setvbuf
1 parent 96862af commit 925bd2d

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

auplugin/auplugin-fgets.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,23 @@ int auplugin_fgets(char *buf, size_t blen, int fd)
232232
return auplugin_fgets_r(&global_state, buf, blen, fd);
233233
}
234234

235-
void auplugin_setvbuf_r(struct auplugin_fgets_state *st, void *buf,
235+
int auplugin_setvbuf_r(struct auplugin_fgets_state *st, void *buf,
236236
size_t buff_size, enum auplugin_mem how)
237237
{
238-
st->buffer = buf ? buf : st->internal;
238+
if (st == NULL || buf == NULL || buff_size == 0)
239+
return 1;
240+
st->buffer = buf;
239241
st->current = st->buffer;
240242
st->eptr = st->buffer + buff_size;
241243
st->eof = 0;
242244
st->mem_type = how;
243245
st->buff_size = buff_size;
246+
return 0;
244247
}
245248

246-
void auplugin_setvbuf(void *buf, size_t buff_size, enum auplugin_mem how)
249+
int auplugin_setvbuf(void *buf, size_t buff_size, enum auplugin_mem how)
247250
{
248251
auplugin_fgets_ensure_global();
249-
auplugin_setvbuf_r(&global_state, buf, buff_size, how);
252+
return auplugin_setvbuf_r(&global_state, buf, buff_size, how);
250253
}
251254

auplugin/auplugin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int auplugin_fgets_eof(void);
5353
int auplugin_fgets_more(size_t blen);
5454
int auplugin_fgets(char *buf, size_t blen, int fd)
5555
__attr_access ((__write_only__, 1, 2));
56-
void auplugin_setvbuf(void *buf, size_t buff_size, enum auplugin_mem how)
56+
int auplugin_setvbuf(void *buf, size_t buff_size, enum auplugin_mem how)
5757
__attr_access ((__read_only__, 1, 2));
5858

5959
void auplugin_fgets_destroy(auplugin_fgets_state_t *st);
@@ -64,7 +64,7 @@ int auplugin_fgets_eof_r(auplugin_fgets_state_t *st);
6464
int auplugin_fgets_more_r(auplugin_fgets_state_t *st, size_t blen);
6565
int auplugin_fgets_r(auplugin_fgets_state_t *st, char *buf, size_t blen, int fd)
6666
__attr_access ((__write_only__, 2, 3));
67-
void auplugin_setvbuf_r(auplugin_fgets_state_t *st, void *buf, size_t buff_size,
67+
int auplugin_setvbuf_r(auplugin_fgets_state_t *st, void *buf, size_t buff_size,
6868
enum auplugin_mem how)
6969
__attr_access ((__read_only__, 2, 3));
7070

docs/auplugin_fgets.3

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ auplugin_fgets, auplugin_fgets_more, auplugin_fgets_eof, auplugin_fgets_clear, a
1212
.br
1313
.B void auplugin_fgets_clear(void);
1414
.br
15-
.BI "void auplugin_setvbuf(void *" buf ", size_t buff_size, enum auplugin_mem " how ");"
15+
.BI "int auplugin_setvbuf(void *" buf ", size_t buff_size, enum auplugin_mem " how ");"
1616
.br
17-
.BI "void auplugin_setvbuf_r(auplugin_fgets_state_t *" st ", void *" buf ", size_t buff_size, enum auplugin_mem " how ");"
17+
.BI "int auplugin_setvbuf_r(auplugin_fgets_state_t *" st ", void *" buf ", size_t buff_size, enum auplugin_mem " how ");"
1818
.SH DESCRIPTION
1919
.B auplugin_fgets
2020
reads from
@@ -69,6 +69,9 @@ return 1 for true and 0 for false.
6969
.PP
7070
.B auplugin_fgets_clear
7171
returns no value.
72+
.PP
73+
.B auplugin_setvbuf
74+
returns 0 on success and 1 on failure.
7275
.SH BACKGROUND
7376
The reason that this family of functions was created is because in auditd plugins, the event stream is stdin, which is descriptor 0. A typical pattern is to call select, poll, or epoll to wait for a record to arrive. As soon as it does, you need to read it. If you use fgets, you will wind up with big problems because you cannot mix low level descriptors with high level constructs like struct FILE. This family of functions allows you to correctly work only using descriptors but with the convenience of fgets.
7477

0 commit comments

Comments
 (0)