Skip to content

Commit 22ad5d6

Browse files
committed
libenv/sysinfo: Fix detected os description
Use platform context variable also for logging the os class description. Before this change, it were using loop counter variable, which is incremented again. This led to verbose logging message: verbose: CFEngine detected operating system description is qnx on Darwin/macOS. Also use already lowercased sysname from utsname struct. Fixes: e2c9f00 ("Use a proper 'bool' variable for a condition in GetNameInfo3()")
1 parent 8788bcf commit 22ad5d6

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

libenv/sysinfo.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,9 @@ static void GetNameInfo3(EvalContext *ctx)
549549
bool found = false;
550550
for (i = 0; !found && (i < PLATFORM_CONTEXT_MAX); i++)
551551
{
552-
char sysname[CF_BUFSIZE];
553-
strlcpy(sysname, VSYSNAME.sysname, CF_BUFSIZE);
554-
ToLowerStrInplace(sysname);
555-
556552
/* FIXME: review those strcmps. Moved out from StringMatch */
557-
if (!strcmp(CLASSATTRIBUTES[i][0], sysname)
558-
|| StringMatchFull(CLASSATTRIBUTES[i][0], sysname))
553+
if (!strcmp(CLASSATTRIBUTES[i][0], VSYSNAME.sysname)
554+
|| StringMatchFull(CLASSATTRIBUTES[i][0], VSYSNAME.sysname))
559555
{
560556
if (!strcmp(CLASSATTRIBUTES[i][1], VSYSNAME.machine)
561557
|| StringMatchFull(CLASSATTRIBUTES[i][1], VSYSNAME.machine))
@@ -580,16 +576,10 @@ static void GetNameInfo3(EvalContext *ctx)
580576
}
581577
}
582578

583-
if (!found)
584-
{
585-
i = 0;
586-
}
587-
588579
Log(LOG_LEVEL_VERBOSE, "%s - ready", NameVersion());
589580
Banner("Environment discovery");
590581

591-
snprintf(workbuf, CF_BUFSIZE, "%s", CLASSTEXT[i]); // See: cppcheck_suppressions.txt
592-
582+
snprintf(workbuf, CF_BUFSIZE, "%s", CLASSTEXT[VSYSTEMHARDCLASS]);
593583

594584
Log(LOG_LEVEL_VERBOSE, "Host name is: %s", VSYSNAME.nodename);
595585
Log(LOG_LEVEL_VERBOSE, "Operating System Type is %s", VSYSNAME.sysname);

tests/static-check/cppcheck_suppressions.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// suppress warnings for access to individual bytes of a uint32 in platform.h
22
objectIndex:libntech/libutils/platform.h
33

4-
// cppcheck is not clever enough to see that if (i >= PLATFORM_CONTEXT_MAX) then 'found' is false
5-
arrayIndexOutOfBounds:libenv/sysinfo.c:587
6-
74
// 'psin' is assigned to 'ai->ai_addr' and 'ai' is returned to the caller
85
memleak:libntech/libcompat/getaddrinfo.c:153
96

0 commit comments

Comments
 (0)