Blob Blame History Raw
From cb52be2f743a6717355445889dd3e2e265ad75fa Mon Sep 17 00:00:00 2001
From: Fabian Vogt <fabian@ritter-vogt.de>
Date: Sat, 18 Jun 2022 14:39:41 +0200
Subject: [PATCH] lmsensors: Fix buffer size passed to snprintf

Pass the actual size of the buffer to snprintf, otherwise the program aborts
if built with _FORTIFY_SOURCE=3.
---
 ksysguardd/Linux/lmsensors.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/ksysguardd/Linux/lmsensors.c b/ksysguardd/Linux/lmsensors.c
index d55c55c47..63097f7fd 100644
--- a/ksysguardd/Linux/lmsensors.c
+++ b/ksysguardd/Linux/lmsensors.c
@@ -164,10 +164,11 @@ void initLmSensors( struct SensorModul* sm )
       label = sensors_get_label( scn, sf );
       sensors_snprintf_chip_name(scnbuf, BUFFER_SIZE_LMSEN, scn);
       p = (LMSENSOR*)malloc( sizeof( LMSENSOR ) );
-      p->fullName = (char*)malloc( strlen( "lmsensors/" ) +
-                                   strlen( scnbuf ) + 1 +
-                                   strlen( label ) + 1 );
-      snprintf( p->fullName, BUFFER_SIZE_LMSEN, "lmsensors/%s/%s", scnbuf, label );
+      const int fullNameLen = strlen( "lmsensors/" ) +
+                              strlen( scnbuf ) + 1 +
+                              strlen( label ) + 1;
+      p->fullName = (char*)malloc( fullNameLen );
+      snprintf( p->fullName, fullNameLen, "lmsensors/%s/%s", scnbuf, label );
 
       /* Make sure that name contains only proper characters. */
       for ( s = p->fullName; *s; s++ )
-- 
GitLab