resource-asm: better file handling in asm-bridge.
authorIsmo Puustinen <ismo.puustinen@intel.com>
Fri, 30 Nov 2012 09:35:28 +0000 (11:35 +0200)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Thu, 8 Jan 2015 16:37:09 +0000 (18:37 +0200)
src/plugins/resource-asm/asm-bridge.c

index 0b22dc4..a720ced 100644 (file)
@@ -234,9 +234,18 @@ static int send_callback_to_client(asm_to_lib_cb_t *msg, ctx_t *ctx)
 
     struct watched_file *wf = NULL;
 
-    snprintf(wr_filename, ASM_FILENAME_SIZE, "/tmp/ASM.%d.%u",
+    ret = snprintf(wr_filename, ASM_FILENAME_SIZE, "/tmp/ASM.%d.%u",
             msg->instance_id, msg->handle);
 
+    if (ret <= 0 || ret == ASM_FILENAME_SIZE)
+        goto error;
+
+    if (access(wr_filename, F_OK) < 0) {
+        mrp_log_error("error accessing file created by ASM client library: %s",
+                strerror(errno));
+        goto error;
+    }
+
     mrp_log_info("writing client preemption to file %s", wr_filename);
 
     wr_fd = open(wr_filename, O_NONBLOCK | O_WRONLY);
@@ -248,8 +257,12 @@ static int send_callback_to_client(asm_to_lib_cb_t *msg, ctx_t *ctx)
 
     if (msg->callback_expected) {
 
-        snprintf(rd_filename, ASM_FILENAME_SIZE, "/tmp/ASM.%d.%ur",
+        ret = snprintf(rd_filename, ASM_FILENAME_SIZE, "/tmp/ASM.%d.%ur",
             msg->instance_id, msg->handle);
+
+        if (ret <= 0 || ret == ASM_FILENAME_SIZE)
+            goto error;
+
         rd_fd = open(wr_filename, O_NONBLOCK | O_RDONLY);
         if (rd_fd < 0) {
             mrp_log_error("failed to open file '%s' for reading: '%s'",