Skip to content

Commit b352e7a

Browse files
authored
Fix Out-of-bound read (#57)
* add check for out-of-bound read * remove unused count variable
1 parent 9bacf84 commit b352e7a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kirc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,12 @@ static int handleServerMessage(void) {
536536
}
537537

538538
static void handleUserInput(char *usrin) {
539+
if (usrin == NULL) return;
540+
539541
char *tok;
540542
size_t msg_len = strlen(usrin);
541543

542-
if (usrin[msg_len - 1] == '\n') {
544+
if (msg_len > 0 && usrin[msg_len - 1] == '\n') {
543545
usrin[msg_len - 1] = '\0';
544546
}
545547

@@ -616,7 +618,7 @@ int main(int argc, char **argv) {
616618
fds[1].events = POLLIN;
617619

618620
char usrin[MSG_MAX];
619-
int count, byteswaiting = 1;
621+
int byteswaiting = 1;
620622

621623
for (;;) {
622624
int poll_res = poll(fds, 2, -1);

0 commit comments

Comments
 (0)