aboutsummaryrefslogtreecommitdiffstats
path: root/kirc.c
diff options
context:
space:
mode:
authormcpcpc <michaelczigler@icloud.com>2020-08-28 19:33:23 -0400
committermcpcpc <michaelczigler@icloud.com>2020-08-28 19:33:23 -0400
commitbf1219105d3c2ddb4e37fa45ab1a80de0dda0bad (patch)
tree4d5d5b5fc40d3eda45016cec41217a3ac1ee3444 /kirc.c
parentbump version to 0.0.4 (diff)
downloadkirc-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.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/kirc.c b/kirc.c
index 1762054..d6ed55d 100644
--- a/kirc.c
+++ b/kirc.c
@@ -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 ||