From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mx.groups.io with SMTP id smtpd.web08.672.1623082911127348438 for ; Mon, 07 Jun 2021 09:21:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=RRcKTiqR; spf=pass (domain: nuviainc.com, ip: 209.85.210.175, mailfrom: rebecca@nuviainc.com) Received: by mail-pf1-f175.google.com with SMTP id u18so13444308pfk.11 for ; Mon, 07 Jun 2021 09:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HSyl+m56mqfK2M6mvMk//KUJCXWcSRs6yHy/C+cMnCU=; b=RRcKTiqR1kV3ILUVabHcgJq+c3waUm04t8f9enrgKDDDOSmeCG0a8k/7OvDPDwlSOs ZwN0yXTsIKwgMImOqnooIfFBjIr9aP5UfBza5x2rV6tRXe4FsYj2p0V6W+f1dy9xWsiW 3DzPZRAaWreyqKNvaRVaT/GHyc9Te/I5cSZxeWukP29tyaqFRfVJ7xbC6j6GoFSwQ2wr vtLvHZHCDmqe7yhyOzYElDMBbnwhrPkJkJpV/vAHwwQYDWlI5Oi8sjNYTXfUeM12Y4Zo LjCMbCILCK/4nsy0iBuWw8ROi2hYZwKogUztYERjo3w2N1kK6W7HlN/3yFWHSbXtPbdt 7q0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HSyl+m56mqfK2M6mvMk//KUJCXWcSRs6yHy/C+cMnCU=; b=Ac7OVBC9s7ZGoCvexXXvQIzYTspupEbwrJY3UAwj/9VD8l4Qj+a6IPcMjo5blxIDD+ mYfgwHzIPA8J57HrviRYJWE08k97h1n/Cf7chbxpYnocGXm7nMIM+FUkU+Plv8t4jkc8 u5rvQ7QrehpbgJ3g1qveD+aA6T7skYgWoHPu6jMARTVLXlf6VLXllsJWOtZLVvWvf2Bj umjJJzoV0Z9CXpIrHbXtuJinpVP4fnrgig0OY1Oc1kcxTHx19SflT9XZC3yj1DOEk4h9 Wm9jrsTwLJB3qTE4rtMBdsJ2nbU5yhZDguiqvBKGlscLfhFKzTe5ol/T/YPS1dzawkBS WlOw== X-Gm-Message-State: AOAM533t1cC4p+/PkCNO2/NKm5/owO2RKvOQvmWfJoYdXJPKmmb/LBlG w0uSI5K/WboSrqliOu7xb9/OuExyUjwLRfb4zDbElyy3eSiUy/Qvhk40l9J/ssGadpbbMn4gyBK SzzTcx9dE45pyzoR0sTvtuwR/0BzlLsXRASS3acfpUfqLuldC8tQXyyjI3pBJdXVYQr7E4TW3 X-Google-Smtp-Source: ABdhPJyVpJr73lijPcaNfHBJ3vHqyciylW5Wx4DzoMNcZRc9Ld6CvsTupx/1VTZyQEPPSkRdF3ZN/w== X-Received: by 2002:a65:4bce:: with SMTP id p14mr18285883pgr.408.1623082910283; Mon, 07 Jun 2021 09:21:50 -0700 (PDT) Return-Path: Received: from linbox.int.bluestop.org.com (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id q23sm9351296pgj.61.2021.06.07.09.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 09:21:49 -0700 (PDT) From: "Rebecca Cran" To: devel@edk2.groups.io, Daryl McDaniel , Jaben Carsey Cc: Rebecca Cran Subject: [edk2-libc PATCH 1/1] Update LibC to use safe string functions Date: Mon, 7 Jun 2021 10:21:45 -0600 Message-Id: <20210607162145.14377-1-rebecca@nuviainc.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The insecure string functions such as StrCpy were removed a while ago, breaking the StdLib build. Migrate StdLib/LibC to the safe string versions. Signed-off-by: Rebecca Cran --- StdLib/LibC/StdLib/Environs.c | 11 ++++++----- StdLib/LibC/StdLib/realpath.c | 5 +++-- StdLib/LibC/String/Concatenation.c | 7 +++++-- StdLib/LibC/String/Copying.c | 7 +++++-- StdLib/LibC/Uefi/Devices/Utility/Path.c | 3 ++- StdLib/LibC/Uefi/SysCalls.c | 5 +++-- StdLib/LibC/Wchar/Concatenation.c | 6 ++++-- StdLib/LibC/Wchar/Copying.c | 4 ++-- 8 files changed, 30 insertions(+), 18 deletions(-) diff --git a/StdLib/LibC/StdLib/Environs.c b/StdLib/LibC/StdLib/Environs.c index a29cb9954cf9..ad56629554df 100644 --- a/StdLib/LibC/StdLib/Environs.c +++ b/StdLib/LibC/StdLib/Environs.c @@ -151,7 +151,7 @@ system(const char *string) if( string == NULL) { return 1; } - (void)AsciiStrToUnicodeStr( string, gMD->UString); + (void)AsciiStrToUnicodeStrS (string, gMD->UString, UNICODE_STRING_MAX); OpStat = ShellExecute( &MyHandle, gMD->UString, FALSE, NULL, &CmdStat); if(OpStat == RETURN_SUCCESS) { EFIerrno = CmdStat; @@ -177,10 +177,11 @@ char *getenv(const char *name) const CHAR16 *EfiEnv; char *retval = NULL; - (void)AsciiStrToUnicodeStr( name, gMD->UString); + (void)AsciiStrToUnicodeStrS (name, gMD->UString, UNICODE_STRING_MAX); EfiEnv = ShellGetEnvironmentVariable(gMD->UString); if(EfiEnv != NULL) { - retval = UnicodeStrToAsciiStr( EfiEnv, gMD->ASgetenv); + (void)UnicodeStrToAsciiStrS (EfiEnv, gMD->ASgetenv, UNICODE_STRING_MAX); + retval = gMD->ASgetenv; } return retval; @@ -238,8 +239,8 @@ setenv ( // // Convert the strings // - AsciiStrToUnicodeStr ( name, UName ); - AsciiStrToUnicodeStr ( value, UValue ); + AsciiStrToUnicodeStrS (name, UName, UNICODE_STRING_MAX); + AsciiStrToUnicodeStrS (value, UValue, UNICODE_STRING_MAX); // // Determine if the string is already present diff --git a/StdLib/LibC/StdLib/realpath.c b/StdLib/LibC/StdLib/realpath.c index 6d75f17a394d..a8ff1e9d5b1d 100644 --- a/StdLib/LibC/StdLib/realpath.c +++ b/StdLib/LibC/StdLib/realpath.c @@ -14,6 +14,7 @@ #include #include #include +#include /** The realpath() function shall derive, from the pathname pointed to by file_name, an absolute pathname that names the same file, whose resolution @@ -47,8 +48,8 @@ realpath( errno = ENOMEM; return (NULL); } - AsciiStrToUnicodeStr(file_name, Temp); + AsciiStrToUnicodeStrS (file_name, Temp, UNICODE_STRING_MAX); PathCleanUpDirectories(Temp); - UnicodeStrToAsciiStr(Temp, resolved_name); + UnicodeStrToAsciiStrS (Temp, resolved_name, UNICODE_STRING_MAX); return (resolved_name); } diff --git a/StdLib/LibC/String/Concatenation.c b/StdLib/LibC/String/Concatenation.c index e76bea0bf858..f78836fbe0d6 100644 --- a/StdLib/LibC/String/Concatenation.c +++ b/StdLib/LibC/String/Concatenation.c @@ -15,6 +15,7 @@ #include +#include #include /** The strcat function appends a copy of the string pointed to by s2 @@ -28,7 +29,8 @@ char * strcat(char * __restrict s1, const char * __restrict s2) { - return AsciiStrCat( s1, s2); + AsciiStrCatS (s1, UNICODE_STRING_MAX, s2); + return s1; } /** The strncat function appends not more than n characters (a null character @@ -43,7 +45,8 @@ strcat(char * __restrict s1, const char * __restrict s2) char * strncat(char * __restrict s1, const char * __restrict s2, size_t n) { - return AsciiStrnCat( s1, s2, n); + AsciiStrnCatS (s1, UNICODE_STRING_MAX, s2, n); + return s1; } /** The strncatX function appends not more than n characters (a null character diff --git a/StdLib/LibC/String/Copying.c b/StdLib/LibC/String/Copying.c index 3234eccf0808..cc2077a5b80a 100644 --- a/StdLib/LibC/String/Copying.c +++ b/StdLib/LibC/String/Copying.c @@ -16,6 +16,7 @@ #include +#include #include #include @@ -73,7 +74,8 @@ strcpy(char * __restrict s1, const char * __restrict s2) //while ( *s1++ = *s2++) /* Empty Body */; //return(s1ret); - return AsciiStrCpy( s1, s2); + AsciiStrCpyS (s1, UNICODE_STRING_MAX, s2); + return s1; } /** The strncpy function copies not more than n characters (characters that @@ -89,7 +91,8 @@ strcpy(char * __restrict s1, const char * __restrict s2) **/ char *strncpy(char * __restrict s1, const char * __restrict s2, size_t n) { - return AsciiStrnCpy( s1, s2, n); + AsciiStrnCpyS (s1, UNICODE_STRING_MAX, s2, n); + return s1; //char *dest = s1; //while(n != 0) { diff --git a/StdLib/LibC/Uefi/Devices/Utility/Path.c b/StdLib/LibC/Uefi/Devices/Utility/Path.c index 96392e018dac..d6728d3a647e 100644 --- a/StdLib/LibC/Uefi/Devices/Utility/Path.c +++ b/StdLib/LibC/Uefi/Devices/Utility/Path.c @@ -110,7 +110,8 @@ NormalizePath( const char *path) wchar_t *NewPath; size_t Length; - OldPath = AsciiStrToUnicodeStr(path, gMD->UString); + AsciiStrToUnicodeStrS (path, gMD->UString, UNICODE_STRING_MAX); + OldPath = gMD->UString; Length = wcslen(OldPath) + 1; NewPath = calloc(Length, sizeof(wchar_t)); diff --git a/StdLib/LibC/Uefi/SysCalls.c b/StdLib/LibC/Uefi/SysCalls.c index faa73ed7a4ee..e83b72308fbe 100644 --- a/StdLib/LibC/Uefi/SysCalls.c +++ b/StdLib/LibC/Uefi/SysCalls.c @@ -1320,7 +1320,8 @@ char errno = ERANGE; return (NULL); } - return (UnicodeStrToAsciiStr(Cwd, buf)); + UnicodeStrToAsciiStrS (Cwd, buf, UNICODE_STRING_MAX); + return buf; } /** Change the current working directory. @@ -1358,7 +1359,7 @@ chdir (const char *path) errno = ENOMEM; return -1; } - AsciiStrToUnicodeStr(path, UnicodePath); + AsciiStrToUnicodeStrS (path, UnicodePath, UNICODE_STRING_MAX); Status = gEfiShellProtocol->SetCurDir(NULL, UnicodePath); FreePool(UnicodePath); if (EFI_ERROR(Status)) { diff --git a/StdLib/LibC/Wchar/Concatenation.c b/StdLib/LibC/Wchar/Concatenation.c index cf595a461f0e..7289240951aa 100644 --- a/StdLib/LibC/Wchar/Concatenation.c +++ b/StdLib/LibC/Wchar/Concatenation.c @@ -31,7 +31,8 @@ **/ wchar_t *wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2) { - return (wchar_t *)StrCat( (CHAR16 *)s1, (CONST CHAR16 *)s2); + StrCatS ((CHAR16 *)s1, UNICODE_STRING_MAX, (CONST CHAR16 *)s2); + return s1; } /** The wcsncat function appends not more than n wide characters (a null wide @@ -44,5 +45,6 @@ wchar_t *wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2) **/ wchar_t *wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n) { - return (wchar_t *)StrnCat( (CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n); + StrnCatS ((CHAR16 *)s1, UNICODE_STRING_MAX, (CONST CHAR16 *)s2, (UINTN)n); + return s1; } diff --git a/StdLib/LibC/Wchar/Copying.c b/StdLib/LibC/Wchar/Copying.c index 7075437965ad..848c83419ddb 100644 --- a/StdLib/LibC/Wchar/Copying.c +++ b/StdLib/LibC/Wchar/Copying.c @@ -29,7 +29,7 @@ **/ wchar_t *wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2) { - return (wchar_t *)StrCpy( (CHAR16 *)s1, (CONST CHAR16 *)s2); + return (wchar_t *)StrCpyS ((CHAR16 *)s1, UNICODE_STRING_MAX, (CONST CHAR16 *)s2); } /** The wcsncpy function copies not more than n wide characters (those that @@ -44,7 +44,7 @@ wchar_t *wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2) **/ wchar_t *wcsncpy(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n) { - return (wchar_t *)StrnCpy( (CHAR16 *)s1, (CONST CHAR16 *)s2, (UINTN)n); + return (wchar_t *)StrnCpyS ((CHAR16 *)s1, UNICODE_STRING_MAX, (CONST CHAR16 *)s2, (UINTN)n); } /** The wmemcpy function copies n wide characters from the object pointed to by -- 2.26.2