Zum Hauptinhalt springen
LIVE
CVSS 7.0CVE-2026-138158 | libgphoto2 through 2.5.34 contains a stack buffer overflow in sierra_get_string_register() that lets a malicious sierra-protocol camera or USB device overwrite stack memory. When files are listed, the device can answer the file-name register with an oversized packet, writing up to 32 KB past small stack buffers to cause crashes or possible code execution.CVSS 7.7CVE-2026-138159 | edbrowse through 3.8.19 contains an integer overflow in stringAndBytes() that allows malicious servers to write past a heap buffer by sending response bodies larger than 2 GB. When a user browses to an attacker-controlled HTTP, FTP, or gopher server, the oversized body skips reallocation and corrupts the heap, causing crashes or potentially code execution.CVSS 8.5CVE-2026-138160 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ReadBackupTextLen() that allows attackers to overwrite stack memory via crafted backup files. Attackers can supply overlong quoted text values decoded into a 10,000-byte stack array during convertbackup, restore, or GSM_ReadBackupFile calls, causing crashes or potential code execution.CVSS 8.5CVE-2026-138161 | Gammu before 1.45.2 contains a buffer overflow vulnerability in LoadBackup() that allows attackers to corrupt memory by supplying an overlong MD5 value in a crafted backup file. Attackers can overwrite adjacent phonebook and calendar entry pointers via strcpy() into MD5Original when files are loaded with convertbackup or restore, causing crashes or potential code execution.CVSS 7.3CVE-2026-138162 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ALCATEL_EncodeString() that allows attackers to overwrite stack memory via oversized encoded phonebook text. Attackers can supply a crafted backup restored with gammu restore or addnew to an attached Alcatel phone, using GSM extension characters to crash Gammu or potentially execute code.CVSS 8.5CVE-2026-138163 | Gammu before 1.45.2 contains a heap-based buffer overflow in ReadWAPSettingsEntry() that allows attackers to corrupt heap memory via crafted backup files with excess WAP or MMS settings entries. Attackers can supply a backup with more than four TitleNN keys in a [WAPSettings] or [MMSSettings] section, loaded via convertbackup, restore, or GSM_ReadBackupFile, causing crashes or potential code execution.CVSS 4.8CVE-2026-138164 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in SaveBackupText() in backtext.c that allows attackers to corrupt stack memory by supplying long text fields. Attackers can craft a backup with long calendar or note fields that, when converted with gammu convertbackup, writes hex digits past the 10,000-byte stack buffer.CVSS 9.3CVE-2026-138154 | POSTAL 2 before build 26810491 contains a sandbox escape vulnerability that allows malicious Steam Workshop mods to execute code by calling ConsoleCommand with a start file URI. Attackers can ship a batch file in a mod at the predictable workshop install path and launch it via ShellExecuteW, executing commands as the player on Windows.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

Refactoring Legacy Code: A Jedi’s Guide to Clean Code

The Quest Begins (The "Why") I still remember the first time I opened a legacy service that had been untouched for three years. The file was a monolithic…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 5 Min. Lesezeit
Quelle: dev.to
Rubrik: Secure Programming




The Quest Begins (The "Why")



I still remember the first time I opened a legacy service that had been untouched for three years. The file was a monolithic 2,000‑line beast, littered with numbers like 42, 0xFF, and 3.14159 scattered everywhere. I spent an afternoon tracing a bug only to discover that someone had changed the timeout value in one place but missed the other three copies. The feeling? Like trying to defeat a boss in Dark Souls without ever learning its attack pattern—frustrating, endless, and you keep dying for the same stupid reason.



That experience taught me a hard truth: magic numbers are silent saboteurs. They make code hard to read, harder to test, and almost impossible to change safely. If you’ve ever felt like you’re reading ancient runes instead of plain English, you know exactly what I mean.






The Revelation (The Insight)



The breakthrough came when I stumbled upon a simple, yet powerful rule: replace every literal value that isn’t self‑explanatory with a named constant. It sounds trivial, but the impact is massive. By giving intention to those numbers, the code starts to tell a story instead of hiding it.



Why does this work?





  • Readability – A name like MAX_RETRY_ATTEMPTS instantly conveys purpose; a bare 3 leaves you guessing.


  • Safety – Change the value in one place, and every usage updates automatically. No more “did I miss one?” panic.


  • Testability – Constants can be overridden in test stubs or config files without digging through logic.


  • Documentation – The constant itself becomes a piece of documentation that lives right next to the code that uses it.



In short, naming your literals turns a cryptic spell into a clear incantation.






Wielding the Power (Code & Examples)



Let’s look at a real‑world snippet I inherited—a function that processed user uploads.






Before: The Chaos






def handle_upload(file):
if file.size > 10 * 1024 * 1024: # 10 MB limit
raise ValueError("File too large")

if file.type not in ['image/jpeg', 'image/png', 'image/gif']:
raise ValueError("Unsupported file type")

if file.name.endswith('.tmp'):
# skip temporary files
return None

# generate a thumbnail
thumb = create_thumbnail(file, width=128, height=128)

# store metadata
meta = {
'owner': file.owner_id,
'uploaded_at': datetime.utcnow(),
'size': file.size,
'type': file.type,
'checksum': compute_md5(file)
}

# retry logic for flaky storage
for attempt in range(3):
try:
save_to_storage(file, meta)
break
except StorageError:
if attempt == 2:
raise
time.sleep(0.5 * (2 ** attempt)) # exponential backoff

return thumb






See the problems?





  • 10 * 1024 * 1024 – what’s that? A comment helps, but the comment can drift.

  • The list ['image/jpeg', 'image/png', 'image/gif'] appears nowhere else; if we add a format we have to hunt it down.

  • Hard‑coded 128 for thumbnail dimensions—what if the UI changes?

  • The retry loop uses 3 and 0.5 * (2 ** attempt)—magic numbers that hide the intent (max attempts, base delay, backoff factor).



A small change in one place could easily be missed, leading to oversized uploads slipping through or thumbnails being the wrong size.






After: The Clarity






# constants.py
MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024 # 10 MB
ALLOWED_MIME_TYPES = {'image/jpeg', 'image/png', 'image/gif'}
THUMBNAIL_WIDTH = 128
THUMBNAIL_HEIGHT = 128
MAX_UPLOAD_ATTEMPTS = 3
BASE_RETRY_DELAY_SECONDS = 0.5
BACKOFF_FACTOR = 2

# upload_handler.py
from .constants import (
MAX_FILE_SIZE_BYTES,
ALLOWED_MIME_TYPES,
THUMBNAIL_WIDTH,
THUMBNAIL_HEIGHT,
MAX_UPLOAD_ATTEMPTS,
BASE_RETRY_DELAY_SECONDS,
BACKOFF_FACTOR,
)

def handle_upload(file):
if file.size > MAX_FILE_SIZE_BYTES:
raise ValueError("File too large")

if file.type not in ALLOWED_MIME_TYPES:
raise ValueError("Unsupported file type")

if file.name.endswith('.tmp'):
return None

thumb = create_thumbnail(file, width=THUMBNAIL_HEIGHT, height=THUMBNAIL_WIDTH)

meta = {
'owner': file.owner_id,
'uploaded_at': datetime.utcnow(),
'size': file.size,
'type': file.type,
'checksum': compute_md5(file)
}

for attempt in range(MAX_UPLOAD_ATTEMPTS):
try:
save_to_storage(file, meta)
break
except StorageError:
if attempt == MAX_UPLOAD_ATTEMPTS - 1:
raise
time.sleep(BASE_RETRY_DELAY_SECONDS * (BACKOFF_FACTOR ** attempt))

return thumb






What changed?




  • Every numeric literal now has a name that explains why it exists.

  • The set of allowed MIME types is a constant—adding a new format is a single line edit.

  • Thumbnail dimensions are grouped; if the design team wants 150 px, we adjust two constants.

  • The retry policy is self‑documenting: “we try three times, starting with half a second and doubling each wait.”



The function is now a straightforward narrative. If a bug appears, I can point to the exact constant that’s suspect, rather than hunting through arithmetic expressions.






Why This New Power Matters



Adopting the “name your literals” habit reshapes how I write code from the ground up.





  • Fewer regression bugs – I no longer worry about forgetting a hidden copy of a number.


  • Faster onboarding – New teammates glance at the constants file and instantly grasp the system’s limits and tuning knobs.


  • Easier experimentation – Tuning a timeout or a batch size becomes a config tweak, not a code dive.


  • Confidence in refactoring – When I extract a method or introduce a new service, I can safely reuse existing constants, knowing they represent the same concept everywhere.



In short, this tiny discipline turned my legacy‑code anxiety into a sense of control—like finally mastering the lightsaber after years of swinging a blunt stick.






Your Turn



Pick a file you’ve been avoiding because it’s full of “magic numbers.” Spend ten minutes extracting those literals into clearly named constants. Run the tests, watch the green lights, and feel the relief of not having to decipher cryptic math every time you read the code.



What’s the first constant you’ll extract? Share your before/after snippets in the comments—I’d love to see how this simple practice transforms your codebase! 🚀

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Community discussion & comments

🌐 Join the main chat

Start the discussion in the Social Chat broadcast stream or submit an expert contribution via the supplement form above.

Community Rating & Social Proof
⭐ Reader Rating
–
Ø / 5.0
No reader ratings yet
Was this article helpful?
0
Submit your rating
Detailed rating (optional)
Content & Quality
Source & Credibility
Freshness
Security Briefing Free · 1-Click Unsubscribe

Intelligence Digest — free

The top security news daily · unsubscribe anytime

Related story clusters & sources (vector AI)

1 Cluster
2 sources
'King-sized' Black Friday deal: Save 79% off Paramount+
tsecurity.de 34 min. ago
1 more source
Similar posts
🔍 Verwandte News

Auch interessante Nachrichten Refactoring Legacy Code: A Jedi’s Guide to Clean Code

Thematisch verwandte Begriffe: Refactoring, Legacy, Code, Jedis · 6 Treffer

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

💬 Loading comments…
Pull to refresh
Widgets & Topics
Loading widgets…
Nächster Beitrag