summaryrefslogtreecommitdiff
path: root/application/boottable
diff options
context:
space:
mode:
authorBenjamin Decavel2009-05-04 10:33:08 +0200
committerBenjamin Decavel2009-05-04 10:33:08 +0200
commit8459631566fd5473d146e62c590a98ff654060d2 (patch)
tree2cd826e37adad9cafc84a71bb7e77618af630546 /application/boottable
parent2a78a6e28ea39f7537029fc892c87265b4e4b679 (diff)
bt secure fix so that current image is not erased if an md5 error occurs
Diffstat (limited to 'application/boottable')
-rw-r--r--application/boottable/src/bt.c2
-rwxr-xr-xapplication/boottable/src/commands.c39
-rw-r--r--application/boottable/src/ftp.c2
3 files changed, 27 insertions, 16 deletions
diff --git a/application/boottable/src/bt.c b/application/boottable/src/bt.c
index 6418c91bcc..acc10c24e3 100644
--- a/application/boottable/src/bt.c
+++ b/application/boottable/src/bt.c
@@ -44,7 +44,7 @@ int main(int argc, char **argv) {
else if(!strcmp(argv[1], "secure_create"))
if (secure_create(argc - 1, &argv[1]) != 0)
- printf("Error during secure_create process, see syslog");
+ printf("Error during secure_create process, see syslog\n");
else
goto NOK;
diff --git a/application/boottable/src/commands.c b/application/boottable/src/commands.c
index 2b3a55c724..096a71ef8f 100755
--- a/application/boottable/src/commands.c
+++ b/application/boottable/src/commands.c
@@ -380,6 +380,7 @@ int secure_create(int argc, char **argv) {
image_desc_t img;
int len, n = 3, v, i;
int already_exist = false;
+ int temp = 0;
if(argc < 5){
printf("%s <name> <ftp_server> <file> <md5_file>\n", argv[0]);
@@ -404,12 +405,12 @@ int secure_create(int argc, char **argv) {
/* Receive file */
if (argc == 5)
- img.size = ftp_secure_main(argv[2], argv[3], argv[4], fd, md5, NULL, NULL, 0);
+ temp = ftp_secure_main(argv[2], argv[3], argv[4], fd, md5, NULL, NULL, 0);
else if (argc == 8)
{
unsigned int port = 0;
sscanf(argv[7], "%u", &port);
- img.size = ftp_secure_main(argv[2], argv[3], argv[4], fd, md5, argv[5], argv[6], port);
+ temp = ftp_secure_main(argv[2], argv[3], argv[4], fd, md5, argv[5], argv[6], port);
}
else
{
@@ -417,6 +418,16 @@ int secure_create(int argc, char **argv) {
return -1;
}
+ if (temp < 0)
+ {
+ syslog(LOG_WARNING, "Error during FTP transfer\n");
+ return -1;
+ }
+ else
+ {
+ img.size = temp;
+ }
+
/* Time measure */
t = time (NULL);
@@ -441,19 +452,19 @@ int secure_create(int argc, char **argv) {
while(n--){
/* Write file to flash */
- if(bt_image_secure_write(&img, fd, img.size, md5) != -1){
-
- printf("Updating table in flash memory...\n");
-
- if(add_entry(argv[1], &img) < 0)
- {
- syslog(LOG_WARNING, "Error: %s\n", image_table_error());
- return -1;
- }
+ if(bt_image_secure_write(&img, fd, img.size, md5) != -1)
+ {
+ printf("Updating table in flash memory...\n");
+
+ if(add_entry(argv[1], &img) < 0)
+ {
+ syslog(LOG_WARNING, "Error: %s\n", image_table_error());
+ return -1;
+ }
- printf("Created image \"%s\" in %d secs\n", argv[1], time (NULL) - t);
- close(fd);
- return 0;
+ printf("Created image \"%s\" in %d secs\n", argv[1], time (NULL) - t);
+ close(fd);
+ return 0;
}
}
diff --git a/application/boottable/src/ftp.c b/application/boottable/src/ftp.c
index 9dcc19599d..7fcb78dfa2 100644
--- a/application/boottable/src/ftp.c
+++ b/application/boottable/src/ftp.c
@@ -198,7 +198,7 @@ static int ftp_secure_receive(ftp_host_info_t *server,
MD5_Final(md5, &c);
if(!!memcmp(md5, md, sizeof(md5)))
{
- syslog(LOG_WARNING, "ftp md5 error");
+ syslog(LOG_WARNING, "ftp md5 comparison error");
return -1;
}