]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: assert on pid in procfs_file_alloca(), use strjoina()
authorMike Yuan <me@yhndnzj.com>
Wed, 30 Apr 2025 17:43:20 +0000 (19:43 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 May 2025 04:10:26 +0000 (13:10 +0900)
src/basic/process-util.h

index fd24ee41ce2aec8534f45ef3734112988c35f110..df6daf1839da9120bc0d3a12bd163850257d100e 100644 (file)
@@ -12,6 +12,7 @@
 #include <sys/types.h>
 
 #include "alloc-util.h"
+#include "assert-util.h"
 #include "format-util.h"
 #include "macro.h"
 #include "pidref.h"
                 pid_t _pid_ = (pid);                                    \
                 const char *_field_ = (field);                          \
                 char *_r_;                                              \
-                if (_pid_ == 0) {                                       \
-                        _r_ = newa(char, STRLEN("/proc/self/") + strlen(_field_) + 1); \
-                        strcpy(stpcpy(_r_, "/proc/self/"), _field_);    \
-                } else {                                                \
+                if (_pid_ == 0)                                         \
+                        _r_ = strjoina("/proc/self/", _field_);         \
+                else {                                                  \
+                        assert(_pid_ > 0);                              \
                         _r_ = newa(char, STRLEN("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + strlen(_field_) + 1); \
                         sprintf(_r_, "/proc/" PID_FMT "/%s", _pid_, _field_); \
                 }                                                       \