/etc/issue hang bug

This patch fixes a bug where cfagent hangs if the directory /etc/vmware exists and the file /etc/issue exists and is of zero length.

This patch was merged into cfengine 2.2.2.

Download

/etc/issue hang bug fix for cfengine 2.2.1

Description

When cfagent finds the directory /etc/vmware it concludes that the host machine is a VMware server, defines the VMware class and calls VM_version(). This function then tries to open /etc/issue and define classes based on its contents.

However, if /etc/issue is of zero length, cfagent will hang forever.

This patch corrects this behaviour.

Discussion

The cause of the bug is revealed in misc.c.

do
   {
   fgets(buffer,sizeof(buffer), fp);
   Chop(buffer);
   len = strlen(buffer);
   }
while (len == 0);

If the file is non-empty, buffer will be filled, len will be non-zero and the loop will exit. But if the file is empty the loop will repeat forever.

The fix is to loop until the return value of fgets() is a null pointer.