pld: move file sanity checks to pld.c 88/7388/8
authorDaniel Anselmi <danselmi@gmx.ch>
Wed, 14 Dec 2022 08:27:38 +0000 (09:27 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Fri, 14 Apr 2023 15:18:40 +0000 (15:18 +0000)
Change-Id: Id64b1165b25a03634949ac22b8af16eb0e24c1fa
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/7388
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/pld/pld.c
src/pld/xilinx_bit.c

index e2e0ef41387df1ebdac822499ec75455a6000d9b..af1836907408c47286f53991d9d88c34b1092424 100644 (file)
@@ -10,6 +10,7 @@
 #endif
 
 #include "pld.h"
+#include <sys/stat.h>
 #include <helper/log.h>
 #include <helper/replacements.h>
 #include <helper/time_support.h>
@@ -134,6 +135,22 @@ COMMAND_HANDLER(handle_pld_load_command)
                return ERROR_OK;
        }
 
+       struct stat input_stat;
+       if (stat(CMD_ARGV[1], &input_stat) == -1) {
+               LOG_ERROR("couldn't stat() %s: %s", CMD_ARGV[1], strerror(errno));
+               return ERROR_PLD_FILE_LOAD_FAILED;
+       }
+
+       if (S_ISDIR(input_stat.st_mode)) {
+               LOG_ERROR("%s is a directory", CMD_ARGV[1]);
+               return ERROR_PLD_FILE_LOAD_FAILED;
+       }
+
+       if (input_stat.st_size == 0) {
+               LOG_ERROR("Empty file %s", CMD_ARGV[1]);
+               return ERROR_PLD_FILE_LOAD_FAILED;
+       }
+
        retval = p->driver->load(p, CMD_ARGV[1]);
        if (retval != ERROR_OK) {
                command_print(CMD, "failed loading file %s to pld device %u",
index 792b3375b62217e30ce7a5785aeea53019b3b797..e4cc52ef9720510db2501876d7f516aa96665c73 100644 (file)
@@ -13,7 +13,6 @@
 #include "pld.h"
 #include <helper/log.h>
 
-#include <sys/stat.h>
 #include <helper/system.h>
 
 static int read_section(FILE *input_file, int length_size, char section,
@@ -60,27 +59,11 @@ static int read_section(FILE *input_file, int length_size, char section,
 int xilinx_read_bit_file(struct xilinx_bit_file *bit_file, const char *filename)
 {
        FILE *input_file;
-       struct stat input_stat;
        int read_count;
 
        if (!filename || !bit_file)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       if (stat(filename, &input_stat) == -1) {
-               LOG_ERROR("couldn't stat() %s: %s", filename, strerror(errno));
-               return ERROR_PLD_FILE_LOAD_FAILED;
-       }
-
-       if (S_ISDIR(input_stat.st_mode)) {
-               LOG_ERROR("%s is a directory", filename);
-               return ERROR_PLD_FILE_LOAD_FAILED;
-       }
-
-       if (input_stat.st_size == 0) {
-               LOG_ERROR("Empty file %s", filename);
-               return ERROR_PLD_FILE_LOAD_FAILED;
-       }
-
        input_file = fopen(filename, "rb");
        if (!input_file) {
                LOG_ERROR("couldn't open %s: %s", filename, strerror(errno));

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)