diff options
author | mcpcpc <michaelczigler@icloud.com> | 2020-08-28 19:33:23 -0400 |
---|---|---|
committer | mcpcpc <michaelczigler@icloud.com> | 2020-08-28 19:33:23 -0400 |
commit | bf1219105d3c2ddb4e37fa45ab1a80de0dda0bad (patch) | |
tree | 4d5d5b5fc40d3eda45016cec41217a3ac1ee3444 /kirc.c | |
parent | bump version to 0.0.4 (diff) | |
download | kirc-bf1219105d3c2ddb4e37fa45ab1a80de0dda0bad.tar.gz kirc-bf1219105d3c2ddb4e37fa45ab1a80de0dda0bad.tar.bz2 kirc-bf1219105d3c2ddb4e37fa45ab1a80de0dda0bad.tar.xz kirc-bf1219105d3c2ddb4e37fa45ab1a80de0dda0bad.tar.zst kirc-bf1219105d3c2ddb4e37fa45ab1a80de0dda0bad.zip |
replace strcpy() function to prevent buffer overflow
Diffstat (limited to '')
-rw-r--r-- | kirc.c | 11 |
1 files changed, 4 insertions, 7 deletions
@@ -58,20 +58,17 @@ kbhit(void) { } /* handle keyboard strokes for command input */ -static char * -input_handler() { +static void +input_handler(char *usrin, int len) { - char *usrin = malloc(sizeof(char) * (IRC_MSG_MAX + 1)); struct termios tp, save; tcgetattr(STDIN_FILENO, &tp); save = tp; tp.c_cc[VERASE] = 127; tcsetattr(STDIN_FILENO, TCSANOW, &tp); - fgets(usrin, IRC_MSG_MAX, stdin); + fgets(usrin, len, stdin); tcsetattr(STDIN_FILENO, TCSANOW, &save); - - return usrin; } /* send command to irc server */ @@ -235,7 +232,7 @@ main(int argc, char **argv) { while (waitpid(pid, NULL, WNOHANG) == 0) { if (!kbhit()) dprintf(fd[1], ":\n"); else { - strcpy(usrin, input_handler()); + input_handler(usrin, IRC_MSG_MAX); if (sscanf(usrin, ":%[M] %s %[^\n]\n", &c1, v2, v1) == 3 || sscanf(usrin, ":%[Qnjpm] %[^\n]\n", &c1, v1) == 2 || |