bakaid commented on a change in pull request #613: Minificpp 927 Nanofi 
tailfile delimited processor
URL: https://github.com/apache/nifi-minifi-cpp/pull/613#discussion_r303875250
 
 

 ##########
 File path: nanofi/src/api/ecu.c
 ##########
 @@ -0,0 +1,271 @@
+#include "api/ecu.h"
+#include "api/nanofi.h"
+#include "core/string_utils.h"
+#include "core/cstructs.h"
+#include "core/file_utils.h"
+#include "core/flowfiles.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+#include <signal.h>
+#include <sys/stat.h>
+
+nifi_instance * instance = NULL;
+standalone_processor * proc = NULL;
+flow_file_list * ff_list = NULL;
+uint64_t curr_offset = 0;
+volatile sig_atomic_t stopped = 0;
+int flow_file_exists = 0;
+flow_file_record * ffr_delim = NULL;
+
+void signal_handler(int signum) {
+    if (signum == SIGINT || signum == SIGTERM) {
+        stopped = 1;
+    }
+}
+
+void set_offset(uint64_t offset) {
+    curr_offset = offset;
+}
+
+uint64_t get_offset() {
+    return curr_offset;
+}
+
+void on_trigger_tailfilechunk(processor_session * ps, processor_context * ctx) 
{
+    char file_path[4096];
+    char chunk_size[50];
+
+    free_flow_file_list(&ff_list);
+
+    if (get_property(ctx, "file_path", file_path, sizeof(file_path)) != 0) {
+        return;
+    }
+
+    if (get_property(ctx, "chunk_size", chunk_size, sizeof(chunk_size)) != 0) {
+        return;
+    }
+
+    errno = 0;
+    unsigned long chunk_size_value = strtoul(chunk_size, NULL, 10);
+
+    if (errno != 0) {
+        printf("Invalid chunk size specified\n");
+        return;
+    }
+
+    FILE * fp = fopen(file_path, "rb");
+
+    if (!fp) {
+        printf("Unable to open file. {file: %s, reason: %s}\n", file_path, 
strerror(errno));
+        return;
+    }
+
+    char buff[chunk_size_value + 1];
 
 Review comment:
   As `chunk_size_value` is a potentially large value supplied by the user, 
allocating the buffer for it on stack with a variable length array can easily 
make us run out of stack space. I think this should be allocated on the heap 
with malloc.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to