A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/77c02cdce2d7b8360771be35b7676a4977e070c1 below:

Prevent buffer overrun in os.symlink (GH-5989) (#5992) · python/cpython@77c02cd · GitHub

@@ -7200,90 +7200,98 @@ check_CreateSymbolicLink(void)

7200 7200

return (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA);

7201 7201

}

7202 7202 7203 -

/* Remove the last portion of the path */

7204 -

static void

7203 +

/* Remove the last portion of the path - return 0 on success */

7204 +

static int

7205 7205

_dirnameW(WCHAR *path)

7206 7206

{

7207 7207

WCHAR *ptr;

7208 +

size_t length = wcsnlen_s(path, MAX_PATH);

7209 +

if (length == MAX_PATH) {

7210 +

return -1;

7211 +

}

7208 7212 7209 7213

/* walk the path from the end until a backslash is encountered */

7210 -

for(ptr = path + wcslen(path); ptr != path; ptr--) {

7214 +

for(ptr = path + length; ptr != path; ptr--) {

7211 7215

if (*ptr == L'\\' || *ptr == L'/')

7212 7216

break;

7213 7217

}

7214 7218

*ptr = 0;

7219 +

return 0;

7215 7220

}

7216 7221 7217 -

/* Remove the last portion of the path */

7218 -

static void

7222 +

/* Remove the last portion of the path - return 0 on success */

7223 +

static int

7219 7224

_dirnameA(char *path)

7220 7225

{

7221 7226

char *ptr;

7227 +

size_t length = strnlen_s(path, MAX_PATH);

7228 +

if (length == MAX_PATH) {

7229 +

return -1;

7230 +

}

7222 7231 7223 7232

/* walk the path from the end until a backslash is encountered */

7224 -

for(ptr = path + strlen(path); ptr != path; ptr--) {

7233 +

for(ptr = path + length; ptr != path; ptr--) {

7225 7234

if (*ptr == '\\' || *ptr == '/')

7226 7235

break;

7227 7236

}

7228 7237

*ptr = 0;

7238 +

return 0;

7229 7239

}

7230 7240 7231 7241

/* Is this path absolute? */

7232 7242

static int

7233 7243

_is_absW(const WCHAR *path)

7234 7244

{

7235 -

return path[0] == L'\\' || path[0] == L'/' || path[1] == L':';

7245 +

return path[0] == L'\\' || path[0] == L'/' ||

7246 +

(path[0] && path[1] == L':');

7236 7247 7237 7248

}

7238 7249 7239 7250

/* Is this path absolute? */

7240 7251

static int

7241 7252

_is_absA(const char *path)

7242 7253

{

7243 -

return path[0] == '\\' || path[0] == '/' || path[1] == ':';

7254 +

return path[0] == '\\' || path[0] == '/' ||

7255 +

(path[0] && path[1] == ':');

7244 7256 7245 7257

}

7246 7258 7247 -

/* join root and rest with a backslash */

7248 -

static void

7259 +

/* join root and rest with a backslash - return 0 on success */

7260 +

static int

7249 7261

_joinW(WCHAR *dest_path, const WCHAR *root, const WCHAR *rest)

7250 7262

{

7251 -

size_t root_len;

7252 - 7253 7263

if (_is_absW(rest)) {

7254 -

wcscpy(dest_path, rest);

7255 -

return;

7264 +

return wcscpy_s(dest_path, MAX_PATH, rest);

7256 7265

}

7257 7266 7258 -

root_len = wcslen(root);

7267 +

if (wcscpy_s(dest_path, MAX_PATH, root)) {

7268 +

return -1;

7269 +

}

7259 7270 7260 -

wcscpy(dest_path, root);

7261 -

if(root_len) {

7262 -

dest_path[root_len] = L'\\';

7263 -

root_len++;

7271 +

if (dest_path[0] && wcscat_s(dest_path, MAX_PATH, L"\\")) {

7272 +

return -1;

7264 7273

}

7265 -

wcscpy(dest_path+root_len, rest);

7274 + 7275 +

return wcscat_s(dest_path, MAX_PATH, rest);

7266 7276

}

7267 7277 7268 -

/* join root and rest with a backslash */

7269 -

static void

7278 +

/* join root and rest with a backslash - return 0 on success */

7279 +

static int

7270 7280

_joinA(char *dest_path, const char *root, const char *rest)

7271 7281

{

7272 -

size_t root_len;

7273 - 7274 7282

if (_is_absA(rest)) {

7275 -

strcpy(dest_path, rest);

7276 -

return;

7283 +

return strcpy_s(dest_path, MAX_PATH, rest);

7277 7284

}

7278 7285 7279 -

root_len = strlen(root);

7286 +

if (strcpy_s(dest_path, MAX_PATH, root)) {

7287 +

return -1;

7288 +

}

7280 7289 7281 -

strcpy(dest_path, root);

7282 -

if(root_len) {

7283 -

dest_path[root_len] = '\\';

7284 -

root_len++;

7290 +

if (dest_path[0] && strcat_s(dest_path, MAX_PATH, "\\")) {

7291 +

return -1;

7285 7292

}

7286 -

strcpy(dest_path+root_len, rest);

7293 + 7294 +

return strcat_s(dest_path, MAX_PATH, rest);

7287 7295

}

7288 7296 7289 7297

/* Return True if the path at src relative to dest is a directory */

@@ -7295,10 +7303,14 @@ _check_dirW(WCHAR *src, WCHAR *dest)

7295 7303

WCHAR src_resolved[MAX_PATH] = L"";

7296 7304 7297 7305

/* dest_parent = os.path.dirname(dest) */

7298 -

wcscpy(dest_parent, dest);

7299 -

_dirnameW(dest_parent);

7306 +

if (wcscpy_s(dest_parent, MAX_PATH, dest) ||

7307 +

_dirnameW(dest_parent)) {

7308 +

return 0;

7309 +

}

7300 7310

/* src_resolved = os.path.join(dest_parent, src) */

7301 -

_joinW(src_resolved, dest_parent, src);

7311 +

if (_joinW(src_resolved, dest_parent, src)) {

7312 +

return 0;

7313 +

}

7302 7314

return (

7303 7315

GetFileAttributesExW(src_resolved, GetFileExInfoStandard, &src_info)

7304 7316

&& src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY

@@ -7314,10 +7326,14 @@ _check_dirA(char *src, char *dest)

7314 7326

char src_resolved[MAX_PATH] = "";

7315 7327 7316 7328

/* dest_parent = os.path.dirname(dest) */

7317 -

strcpy(dest_parent, dest);

7318 -

_dirnameA(dest_parent);

7329 +

if (strcpy_s(dest_parent, MAX_PATH, dest) ||

7330 +

_dirnameA(dest_parent)) {

7331 +

return 0;

7332 +

}

7319 7333

/* src_resolved = os.path.join(dest_parent, src) */

7320 -

_joinA(src_resolved, dest_parent, src);

7334 +

if (_joinA(src_resolved, dest_parent, src)) {

7335 +

return 0;

7336 +

}

7321 7337

return (

7322 7338

GetFileAttributesExA(src_resolved, GetFileExInfoStandard, &src_info)

7323 7339

&& src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4