[systemd-devel] [PATCH] conf-parser: fix memory realloc error

Yin Kangkai kangkai.yin at intel.com
Mon Nov 25 07:14:46 PST 2013


Otherwise there is some memory corruption and undefined behavior,
e.g., in my case systemd-udev was always aborted at the
_cleanup_freep_ around that code blocks.

Signed-off-by: Yin Kangkai <kangkai.yin at intel.com>
---
 src/shared/conf-parser.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index 312315b..c194a07 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -199,7 +199,7 @@ int log_syntax_internal(const char *unit, int level,
                                 continue;                                      \
                                                                                \
                         *(xs + i) = x;                                         \
-                        xs = realloc(xs, ++i + 1);                             \
+                        xs = realloc(xs, (++i + 1) * sizeof(type));            \
                         if (!xs)                                               \
                                 return -ENOMEM;                                \
                         *(xs + i) = invalid;                                   \
-- 
1.8.2.1



More information about the systemd-devel mailing list