dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
594167
From 83845c85669084c4cd69fa8bfe60c57d36bb8713 Mon Sep 17 00:00:00 2001
594167
From: Frantisek Sumsal <frantisek@sumsal.cz>
594167
Date: Fri, 28 Jan 2022 21:44:32 +0100
594167
Subject: [PATCH] shared: be extra paranoid and check if argc > 0
594167
594167
and also if argv[0] is non-empty as a precaution for issues similar to
594167
CVE-2021-4034.
594167
594167
(cherry picked from commit 1637e757070a61b12b26a2a4ef547330562dc77f)
594167
594167
Related: #2017035
594167
---
594167
 src/shared/main-func.h | 1 +
594167
 1 file changed, 1 insertion(+)
594167
594167
diff --git a/src/shared/main-func.h b/src/shared/main-func.h
594167
index 05cdffeec0..09103bace9 100644
594167
--- a/src/shared/main-func.h
594167
+++ b/src/shared/main-func.h
594167
@@ -15,6 +15,7 @@
594167
 #define _DEFINE_MAIN_FUNCTION(intro, impl, ret)                         \
594167
         int main(int argc, char *argv[]) {                              \
594167
                 int r;                                                  \
594167
+                assert(argc > 0 && !isempty(argv[0]));                  \
594167
                 save_argc_argv(argc, argv);                             \
594167
                 intro;                                                  \
594167
                 r = impl;                                               \