[hackers] [quark] encode(): fix buffer-overflow and NUL terminate it || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sat, 22 Jul 2017 13:27:06 +0200 (CEST)

commit c20aa17ae842149c0f6d5edaf64b67977b16cd3d
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Sat Jul 22 12:29:58 2017 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Sat Jul 22 13:23:10 2017 +0200

    encode(): fix buffer-overflow and NUL terminate it

diff --git a/quark.c b/quark.c
index 99c873b..c4fa937 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -141,7 +141,7 @@ encode(char src[PATH_MAX], char dest[PATH_MAX])
         size_t i;
         char *s;
 
- for (s = src, i = 0; *s; s++) {
+ for (s = src, i = 0; *s && i < (PATH_MAX - 4); s++) {
                 if (iscntrl(*s) || (unsigned char)*s > 127) {
                         i += snprintf(dest + i, PATH_MAX - i, "%%%02X",
                                       (unsigned char)*s);
_AT_@ -150,6 +150,7 @@ encode(char src[PATH_MAX], char dest[PATH_MAX])
                         i++;
                 }
         }
+ dest[i] = '\0';
 }
 
 static enum status
Received on Sat Jul 22 2017 - 13:27:06 CEST

This archive was generated by hypermail 2.3.0 : Sat Jul 22 2017 - 13:36:57 CEST