[hackers] [quark] fix segfault on parsing of -v and -m || Josuah Demangeon

From: <git_AT_suckless.org>
Date: Mon, 2 Apr 2018 10:00:12 +0200 (CEST)

commit 69bb7710eb9bcc73dd0836b9b88228259c9586d3
Author: Josuah Demangeon <mail_AT_josuah.net>
AuthorDate: Mon Apr 2 02:54:59 2018 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Mon Apr 2 09:53:41 2018 +0200

    fix segfault on parsing of -v and -m
    
    The length is initially 0 so it needs to be incremented before
    reallocarray to avoid ...alloc(0); and keep some space for the element
    to insert.

diff --git a/main.c b/main.c
index 9985d31..5f1c6d9 100644
--- a/main.c
+++ b/main.c
_AT_@ -166,7 +166,7 @@ main(int argc, char *argv[])
                 if (!(tok = strdup(EARGF(usage())))) {
                         die("strdup:");
                 }
- if (!(s.vhost = reallocarray(s.vhost, s.vhost_len++,
+ if (!(s.vhost = reallocarray(s.vhost, ++s.vhost_len,
                                              sizeof(struct vhost)))) {
                         die("reallocarray:");
                 }
_AT_@ -182,7 +182,7 @@ main(int argc, char *argv[])
                 if (!(tok = strdup(EARGF(usage())))) {
                         die("strdup:");
                 }
- if (!(s.map = reallocarray(s.map, s.map_len++,
+ if (!(s.map = reallocarray(s.map, ++s.map_len,
                                            sizeof(struct map)))) {
                         die("reallocarray:");
                 }
Received on Mon Apr 02 2018 - 10:00:12 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 02 2018 - 10:00:38 CEST