Skip to content

Commit 599de0f

Browse files
authored
Merge pull request #285 from lumynou5/fix-stringop-truncation
Fix string operation truncation
2 parents fe5b1f9 + 15b9925 commit 599de0f

File tree

7 files changed

+9
-6
lines changed

7 files changed

+9
-6
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 *);

qtest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ int main(int argc, char *argv[])
14011401
}
14021402
case 'l':
14031403
strncpy(lbuf, optarg, BUFSIZE);
1404-
buf[BUFSIZE - 1] = '\0';
1404+
lbuf[BUFSIZE - 1] = '\0';
14051405
logfile_name = lbuf;
14061406
break;
14071407
default:

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

scripts/pre-commit.hook

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ cppcheck_suppressions() {
4444
"preprocessorErrorDirective:random.h"
4545
"constVariablePointer:linenoise.c"
4646
"staticFunction:linenoise.c"
47+
"unusedStructMember:linenoise.h"
4748
"nullPointerOutOfMemory:web.c"
4849
"staticFunction:web.c"
4950
"constParameterCallback:tools/fmtscan.c"

web.c

+3-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,8 @@ 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);
263+
buf[buflen] = '\0';
263264
free(p);
264265
close(web_connfd);
265266
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)