Bugfix/bacnet array encoding overflows (#414)

* Add common BACnetARRAY encode function to fix Device object list buffer overflow. Refactor device, analog-output, access-door and binary-output objects to use common BACnetARRAY encoder.

* Fix non-POSIX builds (win32).

* Cleanup some ports/stm32 build warnings
---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-04-13 20:43:54 -05:00
committed by GitHub
parent 064c6f7f1c
commit e517df0d47
23 changed files with 872 additions and 834 deletions
+17 -3
View File
@@ -98,6 +98,20 @@ void BACfile_Property_Lists(
return;
}
/**
* @brief duplicate a string (replacement for POSIX strdup)
* @param s - string to duplicate
* @return a pointer to a new string on success, or a null pointer
*/
static char *bacfile_strdup(const char *s) {
size_t size = strlen(s) + 1;
char *p = malloc(size);
if (p != NULL) {
memcpy(p, s, size);
}
return p;
}
/**
* @brief For a given object instance-number, returns the pathname
* @param object_instance - object-instance number of the object
@@ -130,7 +144,7 @@ void bacfile_pathname_set(uint32_t object_instance, const char *pathname)
if (pObject->Pathname) {
free(pObject->Pathname);
}
pObject->Pathname = strdup(pathname);
pObject->Pathname = bacfile_strdup(pathname);
}
}
@@ -409,10 +423,10 @@ void bacfile_file_type_set(
if (pObject->File_Type) {
if (strcmp(pObject->File_Type, mime_type) != 0) {
free(pObject->File_Type);
pObject->File_Type = strdup(mime_type);
pObject->File_Type = bacfile_strdup(mime_type);
}
} else {
pObject->File_Type = strdup(mime_type);
pObject->File_Type = bacfile_strdup(mime_type);
}
}
}