j
: Next unread message k
: Previous unread message j a
: Jump to all threads
j l
: Jump to MailingList overview
Author: mcayland Date: Fri Apr 2 10:33:07 2010 New Revision: 722 URL: http://tracker.coreboot.org/trac/openbios/changeset/722
Log: Switch the bootinfo-loader over to using strncasecmp rather than strcasecmp which should be much safer on binary buffersi of unknown content/length.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk
Modified: trunk/openbios-devel/include/libc/string.h trunk/openbios-devel/libc/string.c trunk/openbios-devel/packages/bootinfo-loader.c
Modified: trunk/openbios-devel/include/libc/string.h ============================================================================== --- trunk/openbios-devel/include/libc/string.h Fri Apr 2 01:40:21 2010 (r721) +++ trunk/openbios-devel/include/libc/string.h Fri Apr 2 10:33:07 2010 (r722) @@ -52,6 +52,7 @@
extern char *strdup( const char *str ); extern int strcasecmp( const char *cs, const char *ct ); +extern int strncasecmp( const char *cs, const char *ct, size_t count );
extern char *strncpy_nopad( char *dest, const char *src, size_t n );
Modified: trunk/openbios-devel/libc/string.c ============================================================================== --- trunk/openbios-devel/libc/string.c Fri Apr 2 01:40:21 2010 (r721) +++ trunk/openbios-devel/libc/string.c Fri Apr 2 10:33:07 2010 (r722) @@ -511,3 +511,18 @@ } return __res; } + +int +strncasecmp( const char *cs, const char *ct, size_t count ) +{ + register signed char __res; + + while (count--) { + char ch1 = toupper(*cs), ch2 = toupper(*ct); + ct++; + if ((__res = ch1 - ch2) != 0 || !*cs++) + break; + } + return __res; +} +
Modified: trunk/openbios-devel/packages/bootinfo-loader.c ============================================================================== --- trunk/openbios-devel/packages/bootinfo-loader.c Fri Apr 2 01:40:21 2010 (r721) +++ trunk/openbios-devel/packages/bootinfo-loader.c Fri Apr 2 10:33:07 2010 (r722) @@ -167,13 +167,13 @@ } else if (c == '>') { tag = 0; tagbuf[taglen] = '\0'; - if (strcasecmp(tagbuf, "chrp-boot") == 0) { + if (strncasecmp(tagbuf, "chrp-boot", 9) == 0) { chrp = 1; } else if (chrp == 1) { - if (strcasecmp(tagbuf, "boot-script") == 0) { + if (strncasecmp(tagbuf, "boot-script", 11) == 0) { script = 1; scriptlen = 0; - } else if (strcasecmp(tagbuf, "/boot-script") == 0) { + } else if (strncasecmp(tagbuf, "/boot-script", 12) == 0) {
script = 0; bootscript[scriptlen] = '\0'; @@ -184,7 +184,7 @@ feval("-1 state-valid !");
break; - } else if (strcasecmp(tagbuf, "/chrp-boot") == 0) + } else if (strncasecmp(tagbuf, "/chrp-boot", 10) == 0) break; } } else if (tag && taglen < sizeof(tagbuf)) { @@ -195,26 +195,26 @@ } else if (entity && c ==';') { entity = 0; tagbuf[taglen] = '\0'; - if (strcasecmp(tagbuf, "lt") == 0) { + if (strncasecmp(tagbuf, "lt", 2) == 0) { bootscript[scriptlen++] = '<'; - } else if (strcasecmp(tagbuf, "gt") == 0) { + } else if (strncasecmp(tagbuf, "gt", 2) == 0) { bootscript[scriptlen++] = '>'; - } else if (strcasecmp(tagbuf, "device") == 0) { + } else if (strncasecmp(tagbuf, "device", 6) == 0) { strcpy(bootscript + scriptlen, device); scriptlen += strlen(device); - } else if (strcasecmp(tagbuf, "partition") == 0) { + } else if (strncasecmp(tagbuf, "partition", 9) == 0) { if (partition != -1) sprintf(bootscript + scriptlen, "%d", partition); else *(bootscript + scriptlen) = 0; scriptlen = strlen(bootscript); - } else if (strcasecmp(tagbuf, "directory") == 0) { + } else if (strncasecmp(tagbuf, "directory", 9) == 0) { strcpy(bootscript + scriptlen, directory); scriptlen += strlen(directory); - } else if (strcasecmp(tagbuf, "filename") == 0) { + } else if (strncasecmp(tagbuf, "filename", 8) == 0) { strcpy(bootscript + scriptlen, filename); scriptlen += strlen(filename); - } else if (strcasecmp(tagbuf, "full-path") == 0) { + } else if (strncasecmp(tagbuf, "full-path", 9) == 0) { strcpy(bootscript + scriptlen, bootpath); scriptlen += strlen(bootpath); } else { /* unknown, keep it */