pm

barely a pack manager
git clone git://z3bra.org/pm
Log | Files | Refs | README | LICENSE

commit f31eb71cbd3446251a1e6ced34dffe41ec6f8525
parent e27724102e5289a10f3b5bc355b40be37d6b7b49
Author: z3bra <willyatmailoodotorg>
Date:   Fri Jan  8 18:45:54 2016

Prevent buffer overflow while reading content file

Diffstat:
 pm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pm.c b/pm.c @@ -190,6 +190,7 @@ list_content(int fd, char *name) { int meta; char tmp[PATH_MAX] = ""; + size_t len; snprintf(tmp, PATH_MAX, "%s/%s/files", PACKAGE_DATA, name); if ((meta = open(tmp, O_RDONLY)) < 0) { @@ -197,8 +198,11 @@ list_content(int fd, char *name) return -1; } - while (read(meta, tmp, LINE_MAX)) + while ((len = read(meta, tmp, PATH_MAX)) > 0) { + tmp[len] = 0; dprintf(fd, "%s", tmp); + } + return 0; }