From nobody Mon Feb 9 15:11:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49465+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49465+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572068256; cv=none; d=zoho.com; s=zohoarc; b=aycBdLGyW8zO1EX/ewUg1vzF7G/R4JS3Nkh8LBSDjlYPr83BNsNISqozeZ6g6pLru2ZgL+CkMe8QWQWrouYF1AcnD8JZrorOCudNJpwmRnqmhvhou7ikxD36WA0fh5ZuoUIGnmkl+QxM0n4zcTAv/dTL5H+Vj1Zhdw4EEoJOSpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572068256; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hsxVDPje8ZhCfR/7wTo7U73/kqfxTD2EghBiJuSjceI=; b=IlKPsgG9TlwXYPqcWZx3Hus2hp/7UAUOCyRzznpK7bvxHbbgmOnL+iVGGvhKlio2tejRCaNW6FBlFfl4alpLd+xtj3aCHD7hYr4pb4EE4r6p6dACAC+sqQ1UyxHudrd+6jnI6rlfa59I9RWZtQ+OiqVJsMc0jvAG/TX5yx9wnDI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49465+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572068256810160.87312240995607; Fri, 25 Oct 2019 22:37:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id R9i7YY1788612xJ5JVaRvY59; Fri, 25 Oct 2019 22:37:35 -0700 X-Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.120]) by mx.groups.io with SMTP id smtpd.web09.2197.1572068255253113068 for ; Fri, 25 Oct 2019 22:37:35 -0700 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-383-090onGgDOVO54dBe4EvxrQ-1; Sat, 26 Oct 2019 01:37:32 -0400 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74874107AD25; Sat, 26 Oct 2019 05:37:31 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE0625D9CA; Sat, 26 Oct 2019 05:37:29 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: David Woodhouse , Jian J Wang , Jiaxin Wu , Sivaraman Nainar , Xiaoyu Lu Subject: [edk2-devel] [PATCH v2 3/8] CryptoPkg/Crt: turn strchr() into a function (CVE-2019-14553) Date: Sat, 26 Oct 2019 07:37:14 +0200 Message-Id: <20191026053719.10453-4-lersek@redhat.com> In-Reply-To: <20191026053719.10453-1-lersek@redhat.com> References: <20191026053719.10453-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 090onGgDOVO54dBe4EvxrQ-1 X-Mimecast-Spam-Score: 0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 6phTIY0I9M7YJBOIdkVTInYtx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572068255; bh=ds9g99Tu4RJbXaKwAfY7pbxfWYMc5tIsB1MKyR0lynY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=XQW6sA6wqsd4PZGJTfihilfdRARTBznXQYJp30DE9a5mghLknkBnSDmY6PtQqUp/ujO KzQsS6DLayxGpQaNyqIhMjgGmKYbufY/rBm6ccl2rdraoNWVz+fGWiTv0DQqguf8zU19K IE+pN3Fl/EN8LFCZ1YjxeuExvTAsb8wu+2k= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" According to the ISO C standard, strchr() is a function. We #define it as a macro. Unfortunately, our macro evaluates the first argument ("str") twice. If the expression passed for "str" has side effects, the behavior may be undefined. In a later patch in this series, we're going to resurrect "inet_pton.c" (originally from the StdLib package), which calls strchr() just like that: strchr((xdigits =3D xdigits_l), ch) strchr((xdigits =3D xdigits_u), ch) To enable this kind of function call, turn strchr() into a function. Cc: David Woodhouse Cc: Jian J Wang Cc: Jiaxin Wu Cc: Sivaraman Nainar Cc: Xiaoyu Lu Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D960 CVE: CVE-2019-14553 Signed-off-by: Laszlo Ersek Reviewed-by: Jian J Wang Reviewed-by: Philippe Mathieu-Daude --- Notes: v2: - new patch CryptoPkg/Library/Include/CrtLibSupport.h | 2 +- CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/Include/CrtLibSupport.h b/CryptoPkg/Library/= Include/CrtLibSupport.h index 5806f50f7485..b90da20ff7e7 100644 --- a/CryptoPkg/Library/Include/CrtLibSupport.h +++ b/CryptoPkg/Library/Include/CrtLibSupport.h @@ -146,8 +146,9 @@ int isalnum (int); int isupper (int); int tolower (int); int strcmp (const char *, const char *); int strncasecmp (const char *, const char *, size_t); +char *strchr (const char *, int); char *strrchr (const char *, int); unsigned long strtoul (const char *, char **, int); long strtol (const char *, char **, int); char *strerror (int); @@ -187,9 +188,8 @@ void abort (void); #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_S= TRING_SIZE)) #define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_= SIZE,strSource) #define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING= _SIZE,strSource,(UINTN)count) #define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_= SIZE,strSource) -#define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrS= ize(str),(UINT8)ch) #define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,strin= g2,(UINTN)(count))) #define strcasecmp(str1,str2) (int)AsciiStriCmp(str1,str2) #define sprintf(buf,...) AsciiSPrint(buf,MAX_STRING_SIZE,= __VA_ARGS__) #define localtime(timer) NULL diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c b/CryptoPk= g/Library/BaseCryptLib/SysCall/CrtWrapper.c index 71a2ef34ed2b..42235ab96ac3 100644 --- a/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c @@ -114,8 +114,13 @@ QuickSortWorker ( // // -- String Manipulation Routines -- // =20 +char *strchr(const char *str, int ch) +{ + return ScanMem8 (str, AsciiStrSize (str), (UINT8)ch); +} + /* Scan a string for the last occurrence of a character */ char *strrchr (const char *str, int c) { char * save; --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#49465): https://edk2.groups.io/g/devel/message/49465 Mute This Topic: https://groups.io/mt/37952587/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-