Skip to content

Commit cb85746

Browse files
committed
Fix potential buffer overflow in eventmux callback
Change-Id: Ic50650107e939677a286f129251c50ce2dcbf635
1 parent db14e14 commit cb85746

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

linenoise.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ static int line_edit(int stdin_fd,
948948
char seq[5];
949949

950950
if (eventmux_callback != NULL) {
951-
int result = eventmux_callback(l.buf);
951+
int result = eventmux_callback(l.buf, l.buflen);
952952
if (result != 0)
953953
return result;
954954
}

linenoise.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct {
5454
typedef void(line_completion_callback_t)(const char *, line_completions_t *);
5555
typedef char *(line_hints_callback_t)(const char *, int *color, int *bold);
5656
typedef void(line_free_hints_callback_t)(void *);
57-
typedef int(line_eventmux_callback_t)(char *);
57+
typedef int(line_eventmux_callback_t)(char *, size_t);
5858
void line_set_completion_callback(line_completion_callback_t *);
5959
void line_set_hints_callback(line_hints_callback_t *);
6060
void line_set_free_hints_callback(line_free_hints_callback_t *);

scripts/aspell-pws

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ epoll
7777
errno
7878
etc
7979
eventfd
80+
eventmux
8081
fadvise
8182
fchdir
8283
fchmod

web.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ char *web_recv(int fd, struct sockaddr_in *clientaddr)
234234
return ret;
235235
}
236236

237-
int web_eventmux(char *buf)
237+
int web_eventmux(char *buf, size_t buflen)
238238
{
239239
fd_set listenset;
240240

@@ -259,7 +259,7 @@ int web_eventmux(char *buf)
259259
char *p = web_recv(web_connfd, &clientaddr);
260260
char *buffer = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n";
261261
web_send(web_connfd, buffer);
262-
strncpy(buf, p, strlen(p) + 1);
262+
strncpy(buf, p, buflen);
263263
free(p);
264264
close(web_connfd);
265265
return strlen(buf);

web.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ char *web_recv(int fd, struct sockaddr_in *clientaddr);
99

1010
void web_send(int out_fd, char *buffer);
1111

12-
int web_eventmux(char *buf);
12+
int web_eventmux(char *buf, size_t buflen);
1313

1414
#endif

0 commit comments

Comments
 (0)