Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 13, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 13, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 13, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 13, 2025

      This $4 Steam Deck game includes the most-played classics from my childhood — and it will save you paper

      May 13, 2025

      Microsoft shares rare look at radical Windows 11 Start menu designs it explored before settling on the least interesting one of the bunch

      May 13, 2025

      NVIDIA’s new GPU driver adds DOOM: The Dark Ages support and improves DLSS in Microsoft Flight Simulator 2024

      May 13, 2025

      How to install and use Ollama to run AI LLMs on your Windows 11 PC

      May 13, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Community News: Latest PECL Releases (05.13.2025)

      May 13, 2025
      Recent

      Community News: Latest PECL Releases (05.13.2025)

      May 13, 2025

      How We Use Epic Branches. Without Breaking Our Flow.

      May 13, 2025

      I think the ergonomics of generators is growing on me.

      May 13, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      This $4 Steam Deck game includes the most-played classics from my childhood — and it will save you paper

      May 13, 2025
      Recent

      This $4 Steam Deck game includes the most-played classics from my childhood — and it will save you paper

      May 13, 2025

      Microsoft shares rare look at radical Windows 11 Start menu designs it explored before settling on the least interesting one of the bunch

      May 13, 2025

      NVIDIA’s new GPU driver adds DOOM: The Dark Ages support and improves DLSS in Microsoft Flight Simulator 2024

      May 13, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Layered Like Spaghetti

    CodeSOD: Layered Like Spaghetti

    December 3, 2024

    “We use a three tier architecture,” said the tech lead on Cristian‘s new team. “It helps us keep concerns separated.”

    This statement, as it turned out, was half true. They did divide the application into three tiers- a “database layer”, a “business layer”, and a “presentation layer”. The “database layer” was a bunch of Java classes. The “business layer” was a collection of Servlets. And the “presentation layer” was a pile of JSP files.

    What they didn’t do, however, was keep the concerns separated.

    Here’s some code from their database layer:

    public synchronized StringBuffer getStocTotGest(String den, String gest) {
    		StringBuffer sb = new StringBuffer("<table width="100%"  border="1" cellspacing="1" cellpadding="1">" + "<tr bgcolor="#999999">" + "<td>Denumire</td>" + "<td>Cant</td>"
    				+ "<td>PretVanz</td>" + "</tr>");
    		try {
    			ResultSet rs = connectionManager
    					.executeQuery("select (if(length(SUBSTRING(den,1,instr(den,'(')-1))>0,SUBSTRING(den,1,instr(den,'(')-1),den)) as den,um,pret_vinz,sum(stoc) as stoc from stmarfzi_poli where den like '"
    							+ den + "%' " + gest + "  group by den  order by den");
    			while (rs.next()) {
    				sb.append("<tr><td>" + rs.getString("den") + "</td>");
    				sb.append("<td><div align="right">" + threeDecimalPlacesFormat.format(rs.getDouble("stoc")) + " " + rs.getString("um") + "</div></td>");
    				sb.append("<td><div align="right">" + teoDecimalPlacesFormat.format(rs.getDouble("pret_vinz")) + "</div></td></tr>");
    			}
    			sb.append("</table>");
    		} catch (Exception ex) {
    			ex.printStackTrace();
    		}
    		return sb;
    	}
    

    I guess a sufficiently motivated programmer can write PHP in any language.

    This just has a little bit of everything in it, doesn’t it? There’s the string-munged HTML generation in the database layer. The HTML is also wrong, as header fields are output with td tags, instead of th. There’s the SQL injection vulnerability. There’s the more-or-less useless exception handler. It’s synchronized even though it’s not doing anything thread unsafe. It’s truly a thing of beauty, at least if you don’t know what beauty is and think it means something horrible.

    This function was used in a few places. It was called from a few servlets in the “business layer”, where the resulting StringBuffer was dumped into a session variable so that JSP files could access it. At least, that was for the JSP files which didn’t invoke the function themselves- JSP files which mixed all the various layers together.

    Cristian’s first task in the code base was changing the background colors of all of the rendered table headers. Since, as you can see, they weren’t using CSS to make this easy, that involved searching through the entire codebase, in every layer, to find all the places where maybe a table was generated.

    Changing those colors was Cristian’s first task in the code base. I assume that Cristian is still working on that, and will be working on that for some time to come.

    [Advertisement]
    BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleThis Single Proton Pass Feature Saved My Inbox
    Next Article niri – scrollable-tiling Wayland compositor

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 14, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-24022 – iTop Server Code Execution Vulnerability

    May 14, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Critical PAN-OS Vulnerability Added to CISA’s Exploited List: What You Need to Know

    Development

    Switching to webview fail in Android on Mac OS

    Development

    Linux System Performance Tuning: Optimizing CPU, Memory, and Disk

    Learning Resources

    INTERPOL Pushes for “Romance Baiting” to Replace “Pig Butchering” in Scam Discourse

    Development

    Highlights

    Design Insights from a Woman of Color

    July 1, 2024

    A practicing Muslim BIPOC Designer feels a sense of belonging and pride showing up unequivocally…

    Is Google copying Microsoft’s security playbook? Chrome might get a new AI-powered tool to detect scams

    December 20, 2024

    10 Best Plugins For Adding AI to Your WordPress Website

    March 16, 2025

    Apple Patches AirPods Bluetooth Vulnerability That Could Allow Eavesdropping

    June 26, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.