Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Segmentation fault related to 'dce_vsyslog' not calling 'dce_openlog' #86

Open
nullf4c3 opened this issue Aug 11, 2018 · 0 comments
Open

Comments

@nullf4c3
Copy link

Description of the problem

When calling syslog from an application loaded with DCE,
if openlog was not called before, a 'Segmentation Fault' occurs, crashing the script.

Debugging the code, i have found out that the error occurs at the following line:

vfprintf (process->syslog, message, args);

That is, when calling 'vprintf'. The failure happens because process->syslog is NULL,
since dce_openlog was not called before to initialize it:

process->syslog = dce_fopen (os.str ().c_str (), "w");


The problem is that DCE expects that openlog be called before syslog,
but according to 'https://linux.die.net/man/3/openlog':

The use of openlog() is optional; it will automatically be called by syslog() if necessary

Simple fix

To fix the problem, i believe that is just needed to call dce_openlog from dce_vsyslog
when needed. That is:

void
dce_vsyslog (int priority, const char *message, va_list args)
{
  NS_LOG_FUNCTION (Current () << UtilsGetNodeId () << priority << message);
  NS_ASSERT (Current () != 0);
  Process *process = Current ()->process;

  if(process->syslog == NULL)
  {
     //Using default values, because dce_openlog ignores it
     dce_openlog(NULL, 0, 0);
  }

  vfprintf (process->syslog, message, args);
  fprintf (process->syslog, "\n");
}

Steps to reproduce

Change the 'tenseconds.c' program (in myscripts/sleep) to:

#include <unistd.h>
#include <syslog.h>

int main(int c, char **v)
{
  syslog(LOG_WARNING, "Example");

  sleep (10);

  return 1;
}

and run the script normally: ./waf --run=dce-sleep

You can check that running the changed program (tenseconds) directly does not cause failures:

$DCE_BUILD_PATH/bin_dce/tenseconds
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant