Skip to content

Commit

Permalink
Cryptlib: implement strcmp() and strcasecmp()
Browse files Browse the repository at this point in the history
strcmp() and strcasecmp() are widely used in openssl. Implement those
two functions to eliminate the gcc warnings and the potential crash.

Signed-off-by: Gary Lin <glin@suse.com>
  • Loading branch information
lcp authored and vathpela committed Aug 31, 2017
1 parent 1b5dbc4 commit e06765a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cryptlib/Include/OpenSslSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ extern FILE *stdout;
#define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
#define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
#define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))
#define strcmp strcmpa
#define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
#define strcpy(strDest,strSource) AsciiStrCpy(strDest,strSource)
#define strncpy(strDest,strSource,count) AsciiStrnCpy(strDest,strSource,(UINTN)count)
Expand Down
28 changes: 28 additions & 0 deletions Cryptlib/SysCall/BaseStrings.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,32 @@ AsciiStrSize(CHAR8 *string)
return strlena(string) + 1;
}

int
strcmp (const char *str1, const char *str2)
{
return strcmpa((CHAR8 *)str1,(CHAR8 *)str2);
}

inline static char
toupper (char c)
{
return ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c);
}

/* Based on AsciiStriCmp() in edk2 MdePkg/Library/BaseLib/String.c */
int
strcasecmp (const char *str1, const char *str2)
{
char c1, c2;

c1 = toupper (*str1);
c2 = toupper (*str2);
while ((*str1 != '\0') && (c1 == c2)) {
str1++;
str2++;
c1 = toupper (*str1);
c2 = toupper (*str2);
}

return c1 - c2;
}
5 changes: 0 additions & 5 deletions Cryptlib/SysCall/CrtWrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,6 @@ int stat (const char *c, struct stat *s)
return -1;
}

int strcasecmp (const char *c, const char *s)
{
return 0;
}

int strncasecmp (const char *c, const char *s, size_t l)
{
return 0;
Expand Down

0 comments on commit e06765a

Please sign in to comment.