ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
Zbigniew Jędrzejewski-Szmek 2b6823
From 328e8daf82c4e82ebcd06ae87bb825d5060cb94b Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek 2b6823
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Zbigniew Jędrzejewski-Szmek 2b6823
Date: Thu, 18 Feb 2016 17:33:10 -0500
Zbigniew Jędrzejewski-Szmek 2b6823
Subject: [PATCH] basic/strbuf: do not call bsearch with a null argument
Zbigniew Jędrzejewski-Szmek 2b6823
Zbigniew Jędrzejewski-Szmek 2b6823
Das ist verboten!
Zbigniew Jędrzejewski-Szmek 2b6823
Zbigniew Jędrzejewski-Szmek 2b6823
src/basic/strbuf.c:162:23: runtime error: null pointer passed as argument 2,
Zbigniew Jędrzejewski-Szmek 2b6823
                           which is declared to never be null
Zbigniew Jędrzejewski-Szmek 2b6823
Zbigniew Jędrzejewski-Szmek 2b6823
(cherry picked from commit 82501b3fc40dae2660a86ab07462f33fe26347ad)
Zbigniew Jędrzejewski-Szmek 2b6823
---
Zbigniew Jędrzejewski-Szmek 2b6823
 src/basic/strbuf.c | 4 ++++
Zbigniew Jędrzejewski-Szmek 2b6823
 1 file changed, 4 insertions(+)
Zbigniew Jędrzejewski-Szmek 2b6823
Zbigniew Jędrzejewski-Szmek 2b6823
diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c
Zbigniew Jędrzejewski-Szmek 2b6823
index 77220c0251..dac2881603 100644
Zbigniew Jędrzejewski-Szmek 2b6823
--- a/src/basic/strbuf.c
Zbigniew Jędrzejewski-Szmek 2b6823
+++ b/src/basic/strbuf.c
Zbigniew Jędrzejewski-Szmek 2b6823
@@ -156,6 +156,10 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
Zbigniew Jędrzejewski-Szmek 2b6823
                         return off;
Zbigniew Jędrzejewski-Szmek 2b6823
                 }
Zbigniew Jędrzejewski-Szmek 2b6823
 
Zbigniew Jędrzejewski-Szmek 2b6823
+                /* bsearch is not allowed on a NULL sequence */
Zbigniew Jędrzejewski-Szmek 2b6823
+                if (node->children_count == 0)
Zbigniew Jędrzejewski-Szmek 2b6823
+                        break;
Zbigniew Jędrzejewski-Szmek 2b6823
+
Zbigniew Jędrzejewski-Szmek 2b6823
                 /* lookup child node */
Zbigniew Jędrzejewski-Szmek 2b6823
                 c = s[len - 1 - depth];
Zbigniew Jędrzejewski-Szmek 2b6823
                 search.c = c;