Xilinx-CNS / solarcapture

SolarCapture network packet capture suite
Other
13 stars 8 forks source link

Fix filename limit in unit-test harness #7

Open abrunnin-xilinx opened 5 months ago

abrunnin-xilinx commented 5 months ago

The test harnesses all have a maximum length of the filename hardcoded in (512) but don't protect against overrunning this. e.g. in ut_arista7150_ts.c :

  suite_add_tcase(s, tc_node);
  SRunner *sr = srunner_create(s);
  const char *progname;
  char logfile[512];

  progname = strrchr(argv[0], '/');
  if (progname) {
    progname++;
  } else {
    progname = argv[0];
  }
  snprintf(logfile, sizeof(logfile), "%s.out", progname);

  srunner_set_log(sr, logfile);
  srunner_run_all(sr, CK_VERBOSE);
  number_failed = srunner_ntests_failed(sr);
  srunner_free(sr);

We ought to check the output code from snprintf. It's almost certainly not a problem in practice, but we ought to do the right thing.