VULN_CHECK_I913V6 #SJ$c~dZddlmZmZddlZddlZddlZddlmZddl m Z dZ dZ de d efd Zde d e e fd ZdS) z"Module for work with wp_config.php)absolute_importprint_functionN)Path)Listz wp-config.phpi abs_wp_pathreturnc,t|tS)z, Return path to wp-config.php file. )rWP_CONFIG_SUFFIX)rs py/clwpos/wp_config.pypathr s  - . ..ctjt|tjtjztjz} tj|}tj|j s tdt|d|j tkr(tdt|dtdtdz}g}|}|dkrEtj ||}|sn-|||t|z}|dkEtj|n#tj|wxYwd|}t|tkr(tdt|dtdt%jt%j|d 5}|cd d d S#1swxYwYd S) a- Read wp-config.php located in specified WP path. The file is tenant-owned, so open it with O_NOFOLLOW (reject a symlinked final component) and O_NONBLOCK (open() cannot block on a FIFO with no writer), fstat the opened fd to require a regular file (reject FIFO/device/socket/dir), and bound the actual read to MAX_WP_CONFIG_BYTES. The fstat st_size is only a fast-reject of an already-oversized file; it does not bound the read, because a tenant can grow (append to) the file after the fstat but before/while the bytes are consumed, so the read itself must be hard-capped: pull at most MAX_WP_CONFIG_BYTES + 1 bytes and reject if the file yielded more than the cap (a grown/sparse file), rather than returning a truncated config that would corrupt the file on write-back. The bytes are then split into lines exactly as the previous open(errors='surrogateescape').readlines() did (universal-newline text decode), so a small regular config returns the identical list of lines. Because the type check is on the actually-opened fd it also closes the stat-vs-open TOCTOU window. A symlinked path or a non-regular/oversized file raises OSError, matching the missing/unreadable semantics of the previous bare open() so callers' error handling is intact. zwp-config.php at z is not a regular filez exceeds z bytesrr surrogateescape)errorsN)osopenr O_RDONLY O_NOFOLLOW O_NONBLOCKfstatstatS_ISREGst_modeOSErrorst_sizeMAX_WP_CONFIG_BYTESreadappendlenclosejoinio TextIOWrapperBytesIO readlines) rfdstlimitchunks remainingchunkrawfs r rr s, k""BK"-$?"-$O P PB Xb\\|BJ'' YWd;.?.?WWWXX X :+ + +ed;.?.?eeJ]eeeff f $a' !mmGB **E  MM% U #I !mm   ((6  C 3xx%%%a${*;*;aaFYaaabbb "*S//2C D D D{{}}sCD;;EG22G69G6)__doc__ __future__rrr#rrpathlibrtypingrr rstrr rr r r5s)(66666666 " "/c/d////2c2d3i222222r