]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: fix possible null dereference in zlog 7047/head
authorQuentin Young <qlyoung@nvidia.com>
Wed, 2 Sep 2020 21:24:54 +0000 (17:24 -0400)
committerQuentin Young <qlyoung@nvidia.com>
Tue, 8 Sep 2020 15:43:40 +0000 (11:43 -0400)
In some cases one or both of the zlog targets in use here can be null,
we need to check for that.

Interestingly it appears we don't crash even when this is the case.
Undefined behavior ftw

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
lib/zlog_targets.c

index b23ab073b45ed161294a7d6ab87276b64963406d..8f4c2a46a8e432725d3d997a8ed81df86a9d555d 100644 (file)
@@ -225,10 +225,11 @@ static bool zlog_file_cycle(struct zlog_cfg_file *zcf)
                zlt->zt.logfn_sigsafe = zlog_fd_sigsafe;
        } while (0);
 
-       old = zlog_target_replace(&zcf->active->zt, &zlt->zt);
+       old = zlog_target_replace(zcf->active ? &zcf->active->zt : NULL,
+                                 zlt ? &zlt->zt : NULL);
        zcf->active = zlt;
 
-       zlog_file_target_free(container_of(old, struct zlt_fd, zt));
+       zlog_file_target_free(container_of_null(old, struct zlt_fd, zt));
 
        return rv;
 }