|
From: openocd-gerrit <ope...@us...> - 2023-04-14 15:19:15
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 91bd4313444c5a949ce49d88ab487608df7d6c37 (commit)
from 95c27731d4f76c0554147030075ab476d68f9f83 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 91bd4313444c5a949ce49d88ab487608df7d6c37
Author: Daniel Anselmi <dan...@gm...>
Date: Wed Dec 14 09:27:38 2022 +0100
pld: move file sanity checks to pld.c
Change-Id: Id64b1165b25a03634949ac22b8af16eb0e24c1fa
Signed-off-by: Daniel Anselmi <dan...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/7388
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/src/pld/pld.c b/src/pld/pld.c
index e2e0ef413..af1836907 100644
--- a/src/pld/pld.c
+++ b/src/pld/pld.c
@@ -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",
diff --git a/src/pld/xilinx_bit.c b/src/pld/xilinx_bit.c
index 792b3375b..e4cc52ef9 100644
--- a/src/pld/xilinx_bit.c
+++ b/src/pld/xilinx_bit.c
@@ -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));
-----------------------------------------------------------------------
Summary of changes:
src/pld/pld.c | 17 +++++++++++++++++
src/pld/xilinx_bit.c | 17 -----------------
2 files changed, 17 insertions(+), 17 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|