summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2011-06-09 09:39:21 +0000
committerAmaury Pouly <pamaury@rockbox.org>2011-06-09 09:39:21 +0000
commit4cfb5da35b196251e0f55aa745b750a3569750bd (patch)
tree604b0fc1ba24f58f639c70bb76670a69296df43c /utils
parent2d2246ed7d9da43948ec9282323189a7c25da8c7 (diff)
downloadrockbox-4cfb5da35b196251e0f55aa745b750a3569750bd.tar.gz
rockbox-4cfb5da35b196251e0f55aa745b750a3569750bd.tar.bz2
rockbox-4cfb5da35b196251e0f55aa745b750a3569750bd.zip
sbtools: always check the result of getenv against NULL, use strcasecmp instead of strcmp more greater flexibility
Thanks TheLemonMan for spotting that. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29989 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/sbtools/elftosb.c9
-rw-r--r--utils/sbtools/sbtoelf.c12
2 files changed, 17 insertions, 4 deletions
diff --git a/utils/sbtools/elftosb.c b/utils/sbtools/elftosb.c
index 1b47cb58a0..3d53fb76d5 100644
--- a/utils/sbtools/elftosb.c
+++ b/utils/sbtools/elftosb.c
@@ -32,6 +32,7 @@
#include <ctype.h>
#include <time.h>
#include <stdarg.h>
+#include <strings.h>
#include "crypto.h"
#include "elf.h"
@@ -48,6 +49,12 @@ bool g_debug = false;
* Misc
*/
+char *s_getenv(const char *name)
+{
+ char *s = getenv(name);
+ return s ? s : "";
+}
+
void generate_random_data(void *buf, size_t sz)
{
static int rand_fd = -1;
@@ -968,7 +975,7 @@ int main(int argc, const char **argv)
return 1;
}
- if(getenv("SB_DEBUG") != NULL && strcmp(getenv("SB_DEBUG"), "YES") == 0)
+ if(strcasecmp(s_getenv("SB_DEBUG"), "YES") == 0)
g_debug = true;
g_key_array = read_keys(argv[2], &g_nr_keys);
diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c
index 52d7179f2e..854af2851e 100644
--- a/utils/sbtools/sbtoelf.c
+++ b/utils/sbtools/sbtoelf.c
@@ -38,6 +38,7 @@
#include <string.h>
#include <ctype.h>
#include <time.h>
+#include <strings.h>
#include "crypto.h"
#include "elf.h"
@@ -76,6 +77,12 @@ uint8_t *g_buf; /* file content */
char out_prefix[PREFIX_SIZE];
const char *key_file;
+char *s_getenv(const char *name)
+{
+ char *s = getenv(name);
+ return s ? s : "";
+}
+
void *xmalloc(size_t s) /* malloc helper, used in elf.c */
{
void * r = malloc(s);
@@ -338,7 +345,7 @@ static void extract(unsigned long filesize)
if(sb_header->header_size * BLOCK_SIZE != sizeof(struct sb_header_t))
bugp("Bad header size");
if((sb_header->major_ver != IMAGE_MAJOR_VERSION ||
- sb_header->minor_ver != IMAGE_MINOR_VERSION) && strcmp(getenv("SB_IGNORE_VER"), "YES"))
+ sb_header->minor_ver != IMAGE_MINOR_VERSION) && strcasecmp(s_getenv("SB_IGNORE_VER"), "YES"))
bugp("Bad file format version");
if(sb_header->sec_hdr_size * BLOCK_SIZE != sizeof(struct sb_section_header_t))
bugp("Bad section header size");
@@ -497,8 +504,7 @@ static void extract(unsigned long filesize)
}
/* sections */
- char *raw_cmd_env = getenv("SB_RAW_CMD");
- if(raw_cmd_env == NULL || strcmp(raw_cmd_env, "YES") != 0)
+ if(strcasecmp(s_getenv("SB_RAW_CMD"), "YES") != 0)
{
color(BLUE);
printf("Sections\n");