Bugfix/codeql initial fixes (#195)
* Fix to BVLC6 bounds checking * Convert MSTP capture to use datetime library * Convert timesync app to use datetime and mstimer library * fix workflow per warning * fix BSD mstimer init function name Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -3,9 +3,9 @@ name: CodeQL
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- '*'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- '*'
|
- '*'
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '36 11 * * 6'
|
- cron: '36 11 * * 6'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#Makefile to build BACnet Application
|
#Makefile to build BACnet Application
|
||||||
|
|
||||||
# Executable file name
|
# Executable file name
|
||||||
TARGET = mstpcap
|
TARGET = mstpcap
|
||||||
@@ -8,13 +8,16 @@ TARGET = mstpcap
|
|||||||
SRCS = main.c \
|
SRCS = main.c \
|
||||||
${BACNET_PORT_DIR}/rs485.c \
|
${BACNET_PORT_DIR}/rs485.c \
|
||||||
${BACNET_PORT_DIR}/mstimer-init.c \
|
${BACNET_PORT_DIR}/mstimer-init.c \
|
||||||
|
${BACNET_PORT_DIR}/datetime-init.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/bacdcode.c \
|
${BACNET_SRC_DIR}/bacnet/bacdcode.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/bacint.c \
|
${BACNET_SRC_DIR}/bacnet/bacint.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/bacreal.c \
|
${BACNET_SRC_DIR}/bacnet/bacreal.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/bacstr.c \
|
${BACNET_SRC_DIR}/bacnet/bacstr.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/iam.c \
|
${BACNET_SRC_DIR}/bacnet/iam.c \
|
||||||
|
${BACNET_SRC_DIR}/bacnet/datetime.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/indtext.c \
|
${BACNET_SRC_DIR}/bacnet/indtext.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/npdu.c \
|
${BACNET_SRC_DIR}/bacnet/npdu.c \
|
||||||
|
${BACNET_SRC_DIR}/bacnet/basic/sys/days.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/basic/sys/debug.c \
|
${BACNET_SRC_DIR}/bacnet/basic/sys/debug.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/basic/sys/fifo.c \
|
${BACNET_SRC_DIR}/bacnet/basic/sys/fifo.c \
|
||||||
${BACNET_SRC_DIR}/bacnet/basic/sys/filename.c \
|
${BACNET_SRC_DIR}/bacnet/basic/sys/filename.c \
|
||||||
|
|||||||
+6
-6
@@ -42,6 +42,7 @@
|
|||||||
#include "bacnet/bytes.h"
|
#include "bacnet/bytes.h"
|
||||||
#include "bacnet/iam.h"
|
#include "bacnet/iam.h"
|
||||||
#include "bacnet/version.h"
|
#include "bacnet/version.h"
|
||||||
|
#include "bacnet/datetime.h"
|
||||||
/* basic datalink, timer, and filename */
|
/* basic datalink, timer, and filename */
|
||||||
#include "bacnet/datalink/dlmstp.h"
|
#include "bacnet/datalink/dlmstp.h"
|
||||||
#include "bacnet/basic/sys/mstimer.h"
|
#include "bacnet/basic/sys/mstimer.h"
|
||||||
@@ -532,15 +533,14 @@ static size_t data_write_header(
|
|||||||
|
|
||||||
static void filename_create(char *filename)
|
static void filename_create(char *filename)
|
||||||
{
|
{
|
||||||
time_t my_time;
|
BACNET_DATE bdate;
|
||||||
struct tm *today;
|
BACNET_TIME btime;
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
my_time = time(NULL);
|
datetime_local(&bdate, &btime, NULL, NULL);
|
||||||
today = localtime(&my_time);
|
|
||||||
sprintf(filename, "mstp_%04d%02d%02d%02d%02d%02d.cap",
|
sprintf(filename, "mstp_%04d%02d%02d%02d%02d%02d.cap",
|
||||||
1900 + today->tm_year, 1 + today->tm_mon, today->tm_mday,
|
(int)bdate.year, (int)bdate.month, (int)bdate.day,
|
||||||
today->tm_hour, today->tm_min, today->tm_sec);
|
(int)btime.hour, (int)btime.min, (int)btime.sec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-30
@@ -29,7 +29,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <time.h> /* for time */
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "bacnet/basic/binding/address.h"
|
#include "bacnet/basic/binding/address.h"
|
||||||
#include "bacnet/bactext.h"
|
#include "bacnet/bactext.h"
|
||||||
@@ -37,12 +36,14 @@
|
|||||||
#include "bacnet/bacdef.h"
|
#include "bacnet/bacdef.h"
|
||||||
#include "bacnet/npdu.h"
|
#include "bacnet/npdu.h"
|
||||||
#include "bacnet/apdu.h"
|
#include "bacnet/apdu.h"
|
||||||
|
#include "bacnet/datetime.h"
|
||||||
#include "bacnet/basic/object/device.h"
|
#include "bacnet/basic/object/device.h"
|
||||||
#include "bacport.h"
|
#include "bacport.h"
|
||||||
#include "bacnet/datalink/datalink.h"
|
#include "bacnet/datalink/datalink.h"
|
||||||
#include "bacnet/timesync.h"
|
#include "bacnet/timesync.h"
|
||||||
#include "bacnet/version.h"
|
#include "bacnet/version.h"
|
||||||
/* some demo stuff needed */
|
/* some demo stuff needed */
|
||||||
|
#include "bacnet/basic/sys/mstimer.h"
|
||||||
#include "bacnet/basic/sys/filename.h"
|
#include "bacnet/basic/sys/filename.h"
|
||||||
#include "bacnet/basic/services.h"
|
#include "bacnet/basic/services.h"
|
||||||
#include "bacnet/basic/services.h"
|
#include "bacnet/basic/services.h"
|
||||||
@@ -152,15 +153,10 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
BACNET_ADDRESS src = { 0 }; /* address where message came from */
|
BACNET_ADDRESS src = { 0 }; /* address where message came from */
|
||||||
uint16_t pdu_len = 0;
|
uint16_t pdu_len = 0;
|
||||||
unsigned timeout = 100; /* milliseconds */
|
const unsigned timeout = 100; /* milliseconds */
|
||||||
time_t elapsed_seconds = 0;
|
|
||||||
time_t last_seconds = 0;
|
|
||||||
time_t current_seconds = 0;
|
|
||||||
time_t timeout_seconds = 0;
|
|
||||||
time_t rawtime;
|
|
||||||
struct tm *my_time;
|
|
||||||
BACNET_DATE bdate;
|
BACNET_DATE bdate;
|
||||||
BACNET_TIME btime;
|
BACNET_TIME btime;
|
||||||
|
struct mstimer apdu_timer;
|
||||||
long dnet = -1;
|
long dnet = -1;
|
||||||
BACNET_MAC_ADDRESS mac = { 0 };
|
BACNET_MAC_ADDRESS mac = { 0 };
|
||||||
BACNET_MAC_ADDRESS adr = { 0 };
|
BACNET_MAC_ADDRESS adr = { 0 };
|
||||||
@@ -246,40 +242,25 @@ int main(int argc, char *argv[])
|
|||||||
Init_Service_Handlers();
|
Init_Service_Handlers();
|
||||||
dlenv_init();
|
dlenv_init();
|
||||||
atexit(datalink_cleanup);
|
atexit(datalink_cleanup);
|
||||||
/* configure the timeout values */
|
mstimer_init();
|
||||||
last_seconds = time(NULL);
|
|
||||||
timeout_seconds = apdu_timeout() / 1000;
|
|
||||||
/* send the request */
|
/* send the request */
|
||||||
time(&rawtime);
|
datetime_local(&bdate, &btime, NULL, NULL);
|
||||||
my_time = localtime(&rawtime);
|
|
||||||
bdate.year = my_time->tm_year + 1900;
|
|
||||||
bdate.month = my_time->tm_mon + 1;
|
|
||||||
bdate.day = my_time->tm_mday;
|
|
||||||
bdate.wday = my_time->tm_wday ? my_time->tm_wday : 7;
|
|
||||||
btime.hour = my_time->tm_hour;
|
|
||||||
btime.min = my_time->tm_min;
|
|
||||||
btime.sec = my_time->tm_sec;
|
|
||||||
btime.hundredths = 0;
|
|
||||||
Send_TimeSync_Remote(&dest, &bdate, &btime);
|
Send_TimeSync_Remote(&dest, &bdate, &btime);
|
||||||
|
mstimer_set(&apdu_timer, apdu_timeout());
|
||||||
/* loop forever - not necessary for time sync, but we can watch */
|
/* loop forever - not necessary for time sync, but we can watch */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* increment timer - exit if timed out */
|
|
||||||
current_seconds = time(NULL);
|
|
||||||
/* returns 0 bytes on timeout */
|
/* returns 0 bytes on timeout */
|
||||||
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
|
||||||
/* process */
|
/* process */
|
||||||
if (pdu_len) {
|
if (pdu_len) {
|
||||||
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
npdu_handler(&src, &Rx_Buf[0], pdu_len);
|
||||||
}
|
}
|
||||||
if (Error_Detected)
|
if (Error_Detected) {
|
||||||
break;
|
break;
|
||||||
/* increment timer - exit if timed out */
|
}
|
||||||
elapsed_seconds += (current_seconds - last_seconds);
|
if (mstimer_expired(&apdu_timer)) {
|
||||||
if (elapsed_seconds > timeout_seconds) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* keep track of time for next check */
|
|
||||||
last_seconds = current_seconds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ unsigned long mstimer_now(void)
|
|||||||
/**
|
/**
|
||||||
* @brief Initialization for timer
|
* @brief Initialization for timer
|
||||||
*/
|
*/
|
||||||
void timer_init(void)
|
void mstimer_init(void)
|
||||||
{
|
{
|
||||||
#ifdef __MACH__
|
#ifdef __MACH__
|
||||||
clock_serv_t cclock;
|
clock_serv_t cclock;
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ int bvlc6_encode_original_broadcast(uint8_t *pdu,
|
|||||||
pdu, pdu_size, BVLC6_ORIGINAL_BROADCAST_NPDU, length);
|
pdu, pdu_size, BVLC6_ORIGINAL_BROADCAST_NPDU, length);
|
||||||
if (bytes_encoded == 4) {
|
if (bytes_encoded == 4) {
|
||||||
encode_unsigned24(&pdu[4], vmac);
|
encode_unsigned24(&pdu[4], vmac);
|
||||||
if (npdu && length) {
|
if (npdu && npdu_len) {
|
||||||
for (i = 0; i < npdu_len; i++) {
|
for (i = 0; i < npdu_len; i++) {
|
||||||
pdu[7 + i] = npdu[i];
|
pdu[7 + i] = npdu[i];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user