TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Brainfuck interpreter inside a single printf statement

82 pointsby Cieplakover 7 years ago

8 comments

vorticoover 7 years ago
I thought I knew printf format strings, but I suppose not because I have no idea what %1$.*1$d %2$hn does. Can anyone explain why that increments the value behind a pointer?
评论 #15974494 未加载
w4rh4wk5over 7 years ago
For reference, this was has been presented by Mathias Payer at 32c3.<p><a href="https:&#x2F;&#x2F;youtu.be&#x2F;n_tpc7bvPXU?t=2643" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;n_tpc7bvPXU?t=2643</a>
partycoderover 7 years ago
So printf is turing complete?
评论 #15976748 未加载
klezover 7 years ago
<p><pre><code> [ == if (*dataptr == 0) goto ] </code></pre> Isn&#x27;t this wrong? I mean, `[` starts a loop, it doesn&#x27;t mean goto `]`. Unless I&#x27;m getting the semantics wrong, at least one iteration should execute, even if the current cell is set at zero.
评论 #15977454 未加载
millstoneover 7 years ago
It&#x27;s unclear how much stack-smashing is involved here. The &quot;Control Flow Bending&quot; paper clearly requires overwriting pointers internal to printf.<p>Is this possible without invoking undefined behavior? FWIW the demos just crash with SIGILL on macOS.
评论 #15977496 未加载
AceJohnny2over 7 years ago
Well, shit.<p>&#x2F;me adds this to his embedded vsnprintf regression testsuite
digi_owlover 7 years ago
Ah yes, Brainfuck. For when assembly is too easy...
basdpover 7 years ago
No. There are a lot of lines of code that are not inside a single printf statement. This is nothing special, just an unreadable clutter of random code.
评论 #15974124 未加载