VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPR3HardenedNoCrt.cpp@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: SUPR3HardenedNoCrt.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Hardened main() no-crt routines.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#if RT_OS_WINDOWS
42# include <iprt/win/windows.h>
43#endif
44
45#include <VBox/sup.h>
46
47#include "SUPLibInternal.h"
48
49
50#ifdef SUP_HARDENED_NEED_CRT_FUNCTIONS /** @todo this crap is obsolete. */
51
52/** memcmp */
53DECLHIDDEN(int) suplibHardenedMemComp(void const *pvDst, const void *pvSrc, size_t cbToComp)
54{
55 size_t const *puDst = (size_t const *)pvDst;
56 size_t const *puSrc = (size_t const *)pvSrc;
57 while (cbToComp >= sizeof(size_t))
58 {
59 if (*puDst != *puSrc)
60 break;
61 puDst++;
62 puSrc++;
63 cbToComp -= sizeof(size_t);
64 }
65
66 uint8_t const *pbDst = (uint8_t const *)puDst;
67 uint8_t const *pbSrc = (uint8_t const *)puSrc;
68 while (cbToComp > 0)
69 {
70 if (*pbDst != *pbSrc)
71 {
72 if (*pbDst < *pbSrc)
73 return -1;
74 return 1;
75 }
76
77 pbDst++;
78 pbSrc++;
79 cbToComp--;
80 }
81
82 return 0;
83}
84
85
86/** memcpy */
87DECLHIDDEN(void *) suplibHardenedMemCopy(void *pvDst, const void *pvSrc, size_t cbToCopy)
88{
89 size_t *puDst = (size_t *)pvDst;
90 size_t const *puSrc = (size_t const *)pvSrc;
91 while (cbToCopy >= sizeof(size_t))
92 {
93 *puDst++ = *puSrc++;
94 cbToCopy -= sizeof(size_t);
95 }
96
97 uint8_t *pbDst = (uint8_t *)puDst;
98 uint8_t const *pbSrc = (uint8_t const *)puSrc;
99 while (cbToCopy > 0)
100 {
101 *pbDst++ = *pbSrc++;
102 cbToCopy--;
103 }
104
105 return pvDst;
106}
107
108
109/** memset */
110DECLHIDDEN(void *) suplibHardenedMemSet(void *pvDst, int ch, size_t cbToSet)
111{
112 uint8_t *pbDst = (uint8_t *)pvDst;
113 while (cbToSet > 0)
114 {
115 *pbDst++ = (uint8_t)ch;
116 cbToSet--;
117 }
118
119 return pvDst;
120}
121
122
123/** strcpy */
124DECLHIDDEN(char *) suplibHardenedStrCopy(char *pszDst, const char *pszSrc)
125{
126 char *pszRet = pszDst;
127 char ch;
128 do
129 {
130 ch = *pszSrc++;
131 *pszDst++ = ch;
132 } while (ch);
133 return pszRet;
134}
135
136
137/** strlen */
138DECLHIDDEN(size_t) suplibHardenedStrLen(const char *psz)
139{
140 const char *pszStart = psz;
141 while (*psz)
142 psz++;
143 return psz - pszStart;
144}
145
146
147/** strcat */
148DECLHIDDEN(char *) suplibHardenedStrCat(char *pszDst, const char *pszSrc)
149{
150 char *pszRet = pszDst;
151 while (*pszDst)
152 pszDst++;
153 suplibHardenedStrCopy(pszDst, pszSrc);
154 return pszRet;
155}
156
157
158/** strcmp */
159DECLHIDDEN(int) suplibHardenedStrCmp(const char *psz1, const char *psz2)
160{
161 for (;;)
162 {
163 char ch1 = *psz1++;
164 char ch2 = *psz2++;
165 if (ch1 != ch2)
166 return ch1 < ch2 ? -1 : 1;
167 if (ch1 == 0)
168 return 0;
169 }
170}
171
172
173/** strncmp */
174DECLHIDDEN(int) suplibHardenedStrNCmp(const char *psz1, const char *psz2, size_t cchMax)
175{
176 while (cchMax-- > 0)
177 {
178 char ch1 = *psz1++;
179 char ch2 = *psz2++;
180 if (ch1 != ch2)
181 return ch1 < ch2 ? -1 : 1;
182 if (ch1 == 0)
183 break;
184 }
185 return 0;
186}
187
188#endif /* SUP_HARDENED_NEED_CRT_FUNCTIONS */
189
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette