Skip to main content

CodeSOD: Stripped of Magic

3 months 2 weeks ago

A Representative Line is a short snippet that makes you think, "wow, I'd hate to see the rest of the code." A CodeSOD is a longer snippet, which also frequently makes you think, "wow, I'd hate to see the rest of the code," but also is bad in ways that require you to look at the relationship between the lines in the code.

I bring that up, because today's code sample is a long section, but really, it's just a collection of representative lines. Each line in this just makes me die a little on the inside.

Belda found this:

## helper functions function stripmagic($x) { return get_magic_quotes_gpc() ? stripslashes($x) : $x; } function pre_r(&$x) { return '<pre>'.PHSC(print_r($x, true)).'</pre>'; } function PSS($x) { return str_replace('\\"','"',$x); } function PVS($x) { return preg_replace("/\n[^\\S\n]*(?=\n)/", "\n<:vspace>", $x); } function PVSE($x) { return PVS(PHSC($x, ENT_NOQUOTES)); } function PZZ($x,$y='') { return ''; } function PRR($x=NULL) { if ($x || is_null($x)) $GLOBALS['RedoMarkupLine']++; return $x; } function PUE($x) { return preg_replace('/[\\x80-\\xff \'"<>]/e', "'%'.dechex(ord('$0'))", $x); } function SDV(&$v,$x) { if (!isset($v)) $v=$x; } function SDVA(&$var,$val) { foreach($val as $k=>$v) if (!isset($var[$k])) $var[$k]=$v; }

This collection of one-line "helper" functions has it all. Cryptic function names. PRR mutates global variables. PZZ just… returns an empty string. I don't know what PHSC does, and I don't want to, but it's called inside of pre_r and PVSE. Which I also don't know what they do. Speaking of PVSE, I note the regex is using backreferences, which is some advanced regex but I still have no idea what it's doing. I could figure it out, but I don't want to. PUE looks like it might be handling some misencoded characters, maybe. SDV is maybe kinda a coalesce function.

Each line is its own representative line. None of this is code I'd want to maintain.

On the flip side, the abbreviated function names, when read in reverse order, are exactly the sounds I made when I read this code: "SDVASDVPUEPRRPZZPVSEPVSPSS".

It's okay, the doctors say I'll make a full recovery.

[Advertisement] Plan Your .NET 9 Migration with Confidence
Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
Remy Porter

Beijing picking up some of the bill for iPhones sold in China

3 months 2 weeks ago
What? Why? Xi wants people spending, so has extended a subsidy scheme to phones, tabs, and smartwatches

If you want a cheap iPhone, China’s the place to be right now thanks to a government subsidy scheme that means resellers are discounting the devices to make sure Beijing helps to pick up the bill.…

Simon Sharwood

DHS Terminates All Its Advisory Committees, Ending Its Investigation Into Chinese Telecom Hack

3 months 2 weeks ago
An anonymous reader quotes a report from Ars Technica: The Department of Homeland Security has terminated all members of advisory committees, including one that has been investigating a major Chinese hack of large US telecom firms. "The Cyber Safety Review Board -- a Department of Homeland Security investigatory body stood up under a Biden-era cybersecurity executive order to probe major cybersecurity incidents -- has been cleared of non-government members as part of a DHS-wide push to cut costs under the Trump administration, according to three people familiar with the matter," NextGov/FCW reported yesterday. A memo sent Monday by DHS Acting Secretary Benjamine Huffman said that in order to "eliminate[e] the misuse of resources and ensur[e] that DHS activities prioritize our national security, I am directing the termination of all current memberships on advisory committees within DHS, effective immediately. Future committee activities will be focused solely on advancing our critical mission to protect the homeland and support DHS's strategic priorities." The memo said advisory board members terminated this week "are welcome to reapply." The Cyber Safety Review Board's list of members included security experts from the private sector and lead cybersecurity officials from multiple government agencies. "The CSRB was 'less than halfway' done with its Salt Typhoon investigation, according to a now-former member," wrote freelance cybersecurity reporter Eric Geller, who quoted an anonymous source as saying the Cyber Safety Review Board's review of Salt Typhoon is "dead." The former member was also quoted as saying, "There are still professional staff for the CSRB and I hope they will continue some of the work in the interim." The Cyber Safety Review Board operates under (PDF) the DHS's Cybersecurity and Infrastructure Security Agency (CISA), notes Ars. The review board previously investigated a 2023 hack of Microsoft Exchange Online and more recently has been investigating how the Chinese hacking group called Salt Typhoon infiltrated major telecom providers such as Verizon and AT&T.

Read more of this story at Slashdot.

BeauHD