summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dump.c8
-rw-r--r--src/fpid.c7
-rw-r--r--src/hash.c4
-rw-r--r--src/qmode.c49
-rw-r--r--src/squeue/squeue.c7
5 files changed, 41 insertions, 34 deletions
diff --git a/src/dump.c b/src/dump.c
index 9fc0a86..02025e5 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -69,17 +69,14 @@ __rf_extract_exit:
* This function was covardly copied from nanddump.c @ mtd-utils-20060907
*/
#define _GNU_SOURCE
-#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/types.h>
-#include <sys/stat.h>
//#include <asm/types.h>
#include <mtd/mtd-user.h>
#ifndef loff_t
@@ -172,6 +169,9 @@ int check_badblocks(char *mtddev)
return 1;
}
+ memset(&stat1, 0, sizeof(stat1));
+ memset(&stat2, 0, sizeof(stat2));
+
fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
fprintf(stderr, "Size %u, flags %u, type 0x%x\n",
@@ -513,7 +513,7 @@ int dump_config()
break;
if (!memcmp(buf,"ConF", 4)) {
loop:
- read(fd, buf, 4);
+ ret = read(fd, buf, 4);
if (ret == -1) break;
printf("\n0x%08x : ConF %02x %02x %02x %02x : ", i,
buf[0], buf[1], buf[2], buf[3]);
diff --git a/src/fpid.c b/src/fpid.c
index 60c1381..7126719 100644
--- a/src/fpid.c
+++ b/src/fpid.c
@@ -42,7 +42,12 @@ long fpid_size(const char *filename)
{
long sz;
FILE *fd = fopen(filename, "r");
- fseek(fd, 0, SEEK_END);
+ if (fd == NULL)
+ return -1;
+ if (fseek(fd, 0, SEEK_END) != 0) {
+ fclose(fd);
+ return -1;
+ }
sz = ftell(fd);
fclose(fd);
return sz;
diff --git a/src/hash.c b/src/hash.c
index 9090bad..cc17492 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -44,8 +44,10 @@ usho do_hash_file(const char *filename, const char *type)
do {
ret = fread(&buf, 1, BSIZE, fd);
- if (ret == -1)
+ if (ret == -1) {
+ fclose(fd);
return 0;
+ }
hash ^= do_hash((usho *)&buf, ret);
} while(ret);
diff --git a/src/qmode.c b/src/qmode.c
index 64ee94a..e23e457 100644
--- a/src/qmode.c
+++ b/src/qmode.c
@@ -43,38 +43,33 @@ void process_message(char *msg)
{
char *str;
char *arg;
- int c=1;
if (msg == NULL)
return;
printf("[x] (%s)\n", msg);
str = strdup(msg);
arg = strchr(str, ':');
- if (c!=0) {
- arg[0]='\0';
- arg = arg +1;
- if (!strcmp(str, "flash")) {
- const char *type = fpid_file(arg);
- if (type == NULL) {
- squeue_push2(p, "error", "Unknown piece format", 1);
- } else flash_image(arg, type, NULL, NULL, NULL);
- } else
- if (!strcmp(str, "reset")) {
- if (reboot_board() == 0) {
- squeue_push2(p,"info", "Device reboots", 1);
- } else squeue_push2(p,"error", "Cannot reboot device", 1);
- } else
- if (!strcmp(str, "info")) {
- get_rd_flags();
- squeue_push2(p, "info", strbuf, 1);
- get_nolo_version();
- squeue_push2(p, "info", strbuf, 1);
- get_usb_mode();
- squeue_push2(p, "info", strbuf, 1);
- } else
- squeue_push2(p, "error", "invalid command", 0);
- } else {
- squeue_push2(p, "error", "invalid command format", 0);
- }
+ arg[0]='\0';
+ arg = arg +1;
+ if (!strcmp(str, "flash")) {
+ const char *type = fpid_file(arg);
+ if (type == NULL) {
+ squeue_push2(p, "error", "Unknown piece format", 1);
+ } else flash_image(arg, type, NULL, NULL, NULL);
+ } else
+ if (!strcmp(str, "reset")) {
+ if (reboot_board() == 0) {
+ squeue_push2(p,"info", "Device reboots", 1);
+ } else squeue_push2(p,"error", "Cannot reboot device", 1);
+ } else
+ if (!strcmp(str, "info")) {
+ get_rd_flags();
+ squeue_push2(p, "info", strbuf, 1);
+ get_nolo_version();
+ squeue_push2(p, "info", strbuf, 1);
+ get_usb_mode();
+ squeue_push2(p, "info", strbuf, 1);
+ } else
+ squeue_push2(p, "error", "invalid command", 0);
free(str);
}
diff --git a/src/squeue/squeue.c b/src/squeue/squeue.c
index 69bd595..0ed8815 100644
--- a/src/squeue/squeue.c
+++ b/src/squeue/squeue.c
@@ -40,13 +40,18 @@ struct squeue_t *squeue_open(const char *file, int mode)
struct squeue_t *q;
char *pool;
int shmid;
+ int fd;
key_t k;
k = ftok(file, 0x34);
if (k == -1) {
perror("ftok");
squeue_release(file);
- close(creat(file, 0666));
+ if ((fd = creat(file, 0666)) == -1) {
+ perror("creat");
+ return NULL;
+ }
+ close(fd);
chmod(file, 0666);
k = ftok(file, 0xa3);
if (k == -1) {