Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
shrughes
Oct 11, 2008

(call/cc call/cc)
I wanted to burn down the battery on a laptop so to help it along I tried writing a program that had an infinite loop:

code:
int main(void) {
    for (long long i = 0; i < 1000000000000LL; ++i) { }
}

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

Why go the roundabout way to introduce security vulnerabilities?

PHP code:
<?
foreach ( $_POST as $k1 => $v1 )
   eval("$"."$k1 = \"$v1\";");
foreach ( $_GET as $k1 => $v1 )
   eval("$"."$k1 = \"$v1\";");
?>

Doctor w-rw-rw-
Jun 24, 2008

shrughes posted:

I wanted to burn down the battery on a laptop so to help it along I tried writing a program that had an infinite loop:

code:
int main(void) {
    for (long long i = 0; i < 1000000000000LL; ++i) { }
}

Wouldn't that get optimized out?

Vanadium posted:

Why go the roundabout way to introduce security vulnerabilities?

PHP code:
<?
foreach ( $_POST as $k1 => $v1 )
   eval("$"."$k1 = \"$v1\";");
foreach ( $_GET as $k1 => $v1 )
   eval("$"."$k1 = \"$v1\";");
?>

I think $$ would be more easily missed than eval. And at least cargo-culting some random php.ini might disable eval for you, but probably not $$.

Doctor w-rw-rw- fucked around with this message at 09:50 on Jun 25, 2012

Doctor w-rw-rw-
Jun 24, 2008
E: accidental double-post sorry

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Doctor w-rw-rw- posted:

Wouldn't that get optimized out?

I think so (not a C/++ programmer). I think shrughes is poking fun at his/her failing to spot that ahead of time.

pseudorandom name
May 6, 2007

Doctor w-rw-rw- posted:

Wouldn't that get optimized out?

gcc wouldn't for a fairly long time under the assumption that such loops were there for timing purposes, but they reversed that position somewhat recently.

Vanadium
Jan 8, 2005

Compiling C++ programs is probably as good a way to kill your battery as any, though.

KaneTW
Dec 2, 2011

code:
while true; do
gcc -pipe -O3 -fexpensive-optimizations -o batterydie stuff.c
done

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Just spent half an hour combing through routines that write to and read from FRAM and my SD card to figure out why data dumps had the byte order of integers swapped before realizing that ARM chips default to little endian. I am the coding horror :(

KaneTW
Dec 2, 2011

Otto Skorzeny posted:

Just spent half an hour combing through routines that write to and read from FRAM and my SD card to figure out why data dumps had the byte order of integers swapped before realizing that ARM chips default to little endian. I am the coding horror :(

Well half an hour isn't that much, I know people who literally spent weeks trying to figure it out until somebody pointed it out to them that big endian exists.

Slash
Apr 7, 2011

Otto Skorzeny posted:

Just spent half an hour combing through routines that write to and read from FRAM and my SD card to figure out why data dumps had the byte order of integers swapped before realizing that ARM chips default to little endian. I am the coding horror :(

Don't ARM processors let you change the endianness?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

StorrowS posted:

Don't ARM processors let you change the endianness?

Yes although some parts of the toolchain that my vendor provides make endianness assumptions so I can't just poke a register and change it without breaking other things. Besides that, now that I know that the CPU is little endian I can live with it, as I know my code wasn't hosed and I just have to squint a little at the hex dumps.

PrBacterio
Jul 19, 2000

Otto Skorzeny posted:

Yes although some parts of the toolchain that my vendor provides make endianness assumptions so I can't just poke a register and change it without breaking other things. Besides that, now that I know that the CPU is little endian I can live with it, as I know my code wasn't hosed and I just have to squint a little at the hex dumps.
Why'd you want or assume for it to be big endian anyway? Your development machine is probably an Intel box, which is also little endian, anyway. I thought endianness only ever caused trouble anymore when dealing with one of the remaining embedded platforms that still use big endian, because everything else that matters had settled on little endian by now.

Progressive JPEG
Feb 19, 2003

Zhentar posted:

Spoken like someone who hasn't had a co-worker try to sneak a for loop implemented with goto through a code review.

How about the other direction; implementing gotos with a for loop? I've seen this a couple times before, actually seemed pretty reasonable at the time, though it also hinted that the code needed some restructuring:
code:
for (;;) {//only run once
    do_stuff();

    if (err) { handle(err); break; }

    more_stuff();

    if (other_err) { handle(other_err); break; }

    etc();

    break;
}
Edit add: A slightly better(?) version would be:
code:
do {
    ...
} while (false);

Progressive JPEG fucked around with this message at 17:57 on Jun 25, 2012

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal
Java is big endian and so is network byte order, so it definitely still comes up.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
This is powering Wikipedia, the Free Encyclopedia.

Progressive JPEG
Feb 19, 2003

Suspicious Dish posted:

This is powering Wikipedia, the Free Encyclopedia.

Looks like it's at least just a fallback for "MWTidy"? Though maybe that fallback should be inside MWTidy itself, given its apparent purpose of wrapping "Tidy".

Progressive JPEG fucked around with this message at 18:03 on Jun 25, 2012

Zamujasa
Oct 27, 2010



Bread Liar

KaneTW posted:

How do these people even learn to code jeez. "Oh look let's just allow any variable to be controlled by the user! I have no idea how this can go wrong :downs:"

I have to support some really ancient code that still uses register globals (granted it was written last decade -- it just hasn't been upgraded aside from security fixes because it, well, works, and isn't a pressing issue ever), but... why in the world wouldn't you use something like

php:
<?
// smart people would order based on [url]http://www.php.net/manual/en/ini.core.php#ini.variables-order[/url]
// smarter people wouldn't even touch this in the first place
$a = array($_ENV, $_SERVER, $_GET, $_POST, $_COOKIE);
foreach ($a as $v) {
  extract($v, EXTR_SKIP);
}?>
Boom, same thing but incredibly less dangerous, since "index.php?includepath=http://bad.com/blooey.php" isn't going to gently caress up your poo poo. (Assuming that you defined it earlier.)

Slash
Apr 7, 2011

Zamujasa posted:

... last decade ...

Only ~2.5 years ago! Seems relatively young code to me.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Suspicious Dish posted:

This is powering Wikipedia, the Free Encyclopedia.
Ever looked at their templates/template language?
http://en.wikipedia.org/wiki/Template:Convert
This converts between units, like from kg to pounds.
Control function:
{{#ifeq:{{{sortable|}}}|on|{{ntsh|{{FORMATNUM:{{{1}}}|R}}}}}}{{convert/{{#if:1|{{{2}}}}}|{{FORMATNUM:{{{1}}}|R}}|{{#ifeq:{{#expr:{{{3|0}}}*0}}|0|0}}|{{{3|}}}|{{{4|}}}|{{{5|}}}|{{{6|}}}|{{{7|}}}|{{{8|}}}|r={{#ifeq:{{{sp}}}|us|er|re}}|d=L{{{lk|off}}}A{{#switch:{{{abbr}}}|off=none|def=off|{{{abbr|off}}}}}D{{{disp|b}}}S{{{adj|{{{sing|off}}}}}}|s={{{sigfig|}}}}}

Implementation pages:
http://en.wikipedia.org/w/index.php?title=Special%3APrefixIndex&prefix=Template%3AConvert&namespace=0

Zamujasa
Oct 27, 2010



Bread Liar

StorrowS posted:

Only ~2.5 years ago! Seems relatively young code to me.

Okay, you got me -- it was actually over 10 years ago. Still ticking along today, with a few parts that haven't been touched in about as long.




Oh god, Mediawiki templates. I never understood why they didn't just open up the whole extension interface; writing a simple <convert value="3.1" unit="kg" tounit="lb" abbr /> would've been easier.

But then most of MediaWiki's internals are just :barf:

shrughes
Oct 11, 2008

(call/cc call/cc)

Hammerite posted:

I think so (not a C/++ programmer). I think shrughes is poking fun at his/her failing to spot that ahead of time.

The horror was that the "infinite" loop only had 1000 billion cycles, which would only last, at 1 GHz, under 1000 seconds, or 17 minutes.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

PrBacterio posted:

I thought endianness only ever caused trouble anymore when dealing with one of the remaining embedded platforms that still use big endian, because everything else that matters had settled on little endian by now.

As I said before, I was inspecting hex dumps from said embedded platform :)

Doctor w-rw-rw-
Jun 24, 2008

shrughes posted:

The horror was that the "infinite" loop only had 1000 billion cycles, which would only last, at 1 GHz, under 1000 seconds, or 17 minutes.

But it's not a horror for that reason. What kind of assembly only takes one instruction to loop? :psyduck:

increment
comparison
jump if done
jump to increment

Even assuming a relatively compact loop and one instruction per clock cycle, it would take at least an hour.

Unless the loop looked like this:
increment
jump if not equal

in which case it'd still take twice as long, and we're not even taking into account CPU scheduling, and the fact that compilers don't usually produce fully optimal code. Depending on the battery, it's not inconceivable that it might run down the battery significantly.

EDIT: Ran into a coding horror of my own. Since Google's EasyTracker uses an activity subclass, guess what I get to write? This gem: TrackedRoboSherlockFragmentActivity. Adding EasyTracker, which inherits from RoboSherlockFragmentActivity, which adds RoboGuice, which inherits from SherlockFragmentActivity, which adds ActionBarSherlock, which inherits from FragmentActivity, which adds Fragment support, which inherits from the Activity base class.

Doctor w-rw-rw- fucked around with this message at 00:56 on Jun 26, 2012

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I wouldn't put it past shrughes to have a VAX laptop. :v:

"Add, Compare and Branch":

quote:

The addend operand is added to the index operand and the index operand is replaced by the result. The index operand is compared with the limit operand. If the addend operand is positive (or zero) and the comparison is less than or equal to zero, or if the addend is negative and the comparison is greater than or equal to zero, the sign-extended branch displacement is added to the program counter (PC), and the PC is replaced by the result.

edit: Although in that case you might use AOBLSS. (Add One, Branch Less Than)

Internet Janitor fucked around with this message at 01:17 on Jun 26, 2012

Zhentar
Sep 28, 2003

Brilliant Master Genius

Doctor w-rw-rw- posted:

Even assuming ... one instruction per clock cycle,

I feel sorry for anyone using a CPU where 1 IPC is optimistic, particularly when it's a trivial loop. I think for a loop like that, a CPU that shrughes is likely to be using peaks out at 3 IPC, and would cut down the size of the loop a bit by fusing cmp + jne into a single instruction.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

The microop fusion is likely to be much more helpful than the multiple issue for this sort of thing. I think it's also a pretty safe assumption that the 1GHz figure thrown out in the example did not reflect the actual clock rate of his hardware.

ToxicFrog
Apr 26, 2008


And even if all of that were the case and it did actually take an hour, that doesn't change the underlying horror, which is that the "infinite" loop is anything but and on a modern laptop won't last long enough to wear down the battery even if you run it once on each core.

shrughes
Oct 11, 2008

(call/cc call/cc)
One cycle per loop iteration is reasonable for any modern CPU.

On my machine, with a 1.6 GHz E-350 CPU, setting the loop limit to 2 billion makes the program last 11.3 seconds.

With -O1 it lasts 3.772s. 2.0 / 3.772 = 0.530. So it's doing 530 million rounds of the loop per second. So that's three CPU cycles per iteration.

The main itself in -O1 gets compiled to these instructions:

code:
<main>:
    mov $0x77359400,%eax
label:
    sub $0x1,%rax
    jne label
    mov $0x0,%eax
    retq
On an i7-3612QM with -O1 and the same assembly code we get 0.757s. That gives us 2.64 GHz. One cycle per iteration.

Edit: By the way, if we add another sub $0x1, %rax into the loop, we still get 0.747s. So that's 2 cycles per loop (that does two decrements).

Add a third, fourth, fifth, we get the same running time.

Add four decrements to %rdx interspersed among those to %rax and you get the same running time. Add a fifth and you get 0.808s. Add a sixth and you get 0.9s.

shrughes fucked around with this message at 04:49 on Jun 26, 2012

floWenoL
Oct 23, 2002

Why not just spawn n instances of 'yes > /dev/null'?

Doctor w-rw-rw-
Jun 24, 2008
I stand corrected. I thought multiple microcode operations could happen per cycle, but not multiple instructions. Eep.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

man yes posted:

yes -- be repetitively affirmative

Easily the best man page.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
http://pedromadias.wordpress.com/2012/06/25/all-your-asus-servers-ikvmipmi-may-belong-to-other/

code:
$ cat /conf/clearpasswd
root:superuser
anonymous:anonymous
user1:user1passwordincleartext
...

quote:

Holy crap ASUS store user passwords in plain text!

Holy crap all ASUS servers have the same root and anonymous passwords (tested in 10+ servers)

Holy crap root gives SMASH access! (able to change users passwords, server power management…)

HOLY CRAP anonymous has shell access which can be used to check /conf/clearpasswd file, which contains all users passwords in plaintext!!!

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
It's too hot today.

That Turkey Story
Mar 30, 2003

It's so hotta here.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Opinion Haver
Apr 9, 2007

Janin posted:

http://pedromadias.wordpress.com/2012/06/25/all-your-asus-servers-ikvmipmi-may-belong-to-other/

code:
$ cat /conf/clearpasswd
root:superuser
anonymous:anonymous
user1:user1passwordincleartext
...

I refuse to loving believe this.

Huragok
Sep 14, 2011
Oh my.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction
:stare:

Adbot
ADBOT LOVES YOU

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I can't wrap my head around ASUS servers in the first place :wtc:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply