tPrevent buffer overflow while reading content file - pm - barely a pack manager
 (HTM) git clone git://z3bra.org/pm
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f31eb71cbd3446251a1e6ced34dffe41ec6f8525
 (DIR) parent e27724102e5289a10f3b5bc355b40be37d6b7b49
 (HTM) Author: z3bra <willyatmailoodotorg>
       Date:   Fri,  8 Jan 2016 18:45:54 +0100
       
       Prevent buffer overflow while reading content file
       
       Diffstat:
         M pm.c                                |       6 +++++-
       
       1 file changed, 5 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/pm.c b/pm.c
       t@@ -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) {
       t@@ -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;
        }