fix(plugin): Check for successful file creation (#5348)

fclose should only be called on valid FILE pointers, as fclose(0) is
undefined.
This commit is contained in:
Andreas Eckerstorfer 2022-09-26 22:28:39 +02:00 committed by GitHub
parent e1d7708052
commit 5dab29487e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 17 deletions

View File

@ -497,14 +497,18 @@ certificateVerification_verify(void *verificationContext,
UA_ByteString_clear(&thumbprint);
char *rejectedFullFileName = (char *) calloc(ci->rejectedListFolder.length + 1 /* '/' */ + strlen(rejectedFileName) + 1, sizeof(char));
if (rejectedFullFileName) {
memcpy(rejectedFullFileName, ci->rejectedListFolder.data, ci->rejectedListFolder.length);
rejectedFullFileName[ci->rejectedListFolder.length] = '/';
memcpy(&rejectedFullFileName[ci->rejectedListFolder.length + 1], rejectedFileName, strlen(rejectedFileName));
FILE * fp_rejectedFile = fopen(rejectedFullFileName, "wb");
if (fp_rejectedFile) {
fwrite(certificate->data, sizeof(certificate->data[0]), certificate->length, fp_rejectedFile);
free(rejectedFullFileName);
fclose(fp_rejectedFile);
}
free(rejectedFullFileName);
}
}
#endif
}

View File

@ -473,6 +473,7 @@ START_TEST(encryption_connect_reject_cert) {
strcat(rejectedFileName, ".der");
FILE * fp_rejectedFile = fopen(rejectedFileName, "rb");
if (fp_rejectedFile) {
UA_Byte readBuffer[CLIENT_CERTIFICATE_DER_SIZE] = {0};
fread(readBuffer, CLIENT_CERTIFICATE_DER_SIZE, 1, fp_rejectedFile);
@ -480,6 +481,7 @@ START_TEST(encryption_connect_reject_cert) {
ck_assert(readBuffer[i] == clientCertificateDer[i]);
}
fclose(fp_rejectedFile);
}
UA_Client_disconnect(client);
#endif

View File

@ -173,9 +173,11 @@ UA_debug_dumpCompleteChunk(UA_Server *const server, UA_Connection *const connect
"Dumping package %s", dumpOutputFile);
FILE *write_ptr = fopen(dumpOutputFile, "ab");
if (write_ptr) {
fwrite(messageBuffer->data, messageBuffer->length, 1, write_ptr); // write 10 bytes from our buffer
// add the available memory size. See the UA_DUMP_RAM_SIZE define for more info.
uint32_t ramSize = UA_DUMP_RAM_SIZE;
fwrite(&ramSize, sizeof(ramSize), 1, write_ptr);
fclose(write_ptr);
}
}