Navigation

User login

Browse archives

« October 2008  
Su Mo Tu We Th Fr Sa
      1 2 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Who's online

There are currently 0 users and 3 guests online.

Facepalm

The past few days I have been working on some bits and pieces of code, and I facepalmed myself at 0226 in the morning. I opened up an older part of the project, and I had totally forgotten I had written a config parser. It opens up, and it is scrolled half way down the page, so I don't see my Copyright tag on it at the top.

I look it over a few lines, and suddenly I say to myself:

"Wow, that is an interesting way of accomplishing that. I would have never thought of that"
"Interesting trick"
"Written with security in mind"
"Line counting, and even tells the user what error it has encountered!"

Wanting to know who wrote this code, figuring it was someone I was working with at the time, I read the copyright:

 * Copyright 2006 Bert JW Regeer. All rights  reserved.

Yeah, facepalm. Anyway, luckily I do remember why I was writing it, and I wrote down in the sample config file what the config parser is supposed to parse, so I know that it parses stuff like this:

# <sub-system name> {
#       id: <number>;                           # Any number that is not taken
#       program: bin/something;                 # Full path, or take workingdir/. So /usr/local/bin/something in this example.
#       arguments: -user xistence;              # Pass an arbitrary amount of arguments to the program to be executed
#       env: SPECIALSAUCE=yes,MAYO=no;          # Pass environment variables to the executing program.
# }

The config system is there to allow different programs to be run by the daemon depending on user input. So for example, this would be a valid sub-system:

adduser {
    id: 10
    program: bin/specialadduser
    arguments: --skel=/usr/local/skel
}

Anyway, I was pretty damn impressed with my own code from 2 years ago. Now that I have looked at it again, I remember writing it while I was bored during my summer vacation. That same summer vacation I wrote my own regex library, which sadly I have removed from existence, since it was too complicated to maintain. It was however able to do some of the following:

(a*) to look for a followed by any characters, and store it.
a+ to look for 1 or more occurrences of a.
(.*) { (.*) } would also work, it would store whatever it found before a " {" in an array as position 0, and then whatever was in the curly braces in array position 1. It is probably for the best that the code is gone, but it was an interesting exercise none the less. I even remember sending Geffy a text message asking him to look up function pointers for me since I was away from the Internet!

Maybe later I will post more information. I am heading back to my other code, it is nowhere near finished!

PHP 5.2.6 on FreeBSD with extensions

There seems to be an issue in PHP 5.2.6 with extensions where the extensions have to be loaded in a certain order or the PHP interpreter has a tendency to crash and fail miserably. It is weird, as depending on the system configuration the order of the extensions has to be entirely different.

Certain extensions have a dependency on other extensions and their functionality so it is understandable that they are required to be loaded before the other modules can be loaded, however this has never been an issue before. I am not entirely sure how PHP does it, but I am betting it loads all the modules and then runs an init function of sort, and since all the modules are loaded at the same time, there are no issues.

However, in this case it seems that multiple functions are clashing, or something along those lines.

Running PHP in a gdb session showed the following:

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0  0x00000000 in ?? ()
#1  0x29803544 in __do_global_dtors_aux () from /usr/local/lib/php/20060613/simplexml.so
#2  0x29807c04 in _fini () from /usr/local/lib/php/20060613/simplexml.so
#3  0x2824f558 in tls_dtv_generation () from /libexec/ld-elf.so.1
#4  0x28251558 in ?? () from /libexec/ld-elf.so.1
#5  0xbfbfe9c8 in ?? ()
#6  0x282327b6 in elf_hash () from /libexec/ld-elf.so.1
#7  0x282350a0 in dlclose () from /libexec/ld-elf.so.1
#8  0x081374e4 in zend_hash_apply_deleter ()
#9  0x0813757f in zend_hash_graceful_reverse_destroy ()
#10 0x0812da7c in zend_shutdown ()
#11 0x080f4f67 in php_module_shutdown ()
#12 0x081aa892 in main ()

So it seems that simplexml is the culprit here, lets remove it. Once removed from extensions.ini we re-run gdb and give it the same information we gave it before, this time however we see this:

 Cannot load module 'SPL' because required module 'simplexml' is not loaded in Unknown on line 0

My gut instinct is to now move simplexml ABOVE the line that says extension=spl.so. After we do this, PHP is able to run without any issues. Now, for the fun:

extension=spl.so
extension=xml.so
extension=ctype.so
extension=zlib.so
extension=session.so
extension=mbstring.so
extension=pdo.so
extension=pdo_sqlite.so
extension=ftp.so
extension=posix.so
extension=pcre.so
extension=json.so
extension=zip.so
extension=suhosin.so
extension=pdo_mysql.so
extension=bz2.so
extension=openssl.so
extension=gd.so
extension=pdf.so
extension=hash.so
extension=mhash.so
extension=curl.so
extension=mcrypt.so
extension=xmlwriter.so
extension=tokenizer.so
extension=filter.so
extension=simplexml.so
extension=iconv.so
extension=sqlite.so
extension=dom.so
extension=xmlreader.so
extension=gettext.so
extension=tidy.so
extension=mysqli.so
extension=mysql.so
extension=sockets.so
extension=pspell.so
extension=imap.so
extension=ncurses.so
extension=xsl.so

Is the extension list on one of the servers I administrate. Notice that spl.so is at the top of the file, and simplexml.so is somewhere in the middle. And this works perfectly, however the same file on a second server causes it to bomb spectacularly. However, I had kept a backup of the original extensions.ini on the second server, put it back, and then experimented with it, and this is what came out:

extension=simplexml.so
extension=spl.so
extension=suhosin.so
extension=json.so
extension=zip.so
extension=filter.so
extension=hash.so
extension=session.so
extension=sysvmsg.so
extension=gd.so
extension=pdf.so
extension=tidy.so
extension=magickwand.so
extension=odbc.so
extension=calendar.so
extension=sysvshm.so
extension=soap.so
extension=tokenizer.so
extension=mcrypt.so
extension=iconv.so
extension=readline.so
extension=sysvsem.so
extension=bz2.so
extension=zlib.so
extension=ftp.so
extension=pcntl.so
extension=ncurses.so
extension=posix.so
extension=gettext.so
extension=mhash.so
extension=pcre.so
extension=mbstring.so
extension=xmlwriter.so
extension=xml.so
extension=xmlrpc.so
extension=sqlite.so
extension=openssl.so
extension=ctype.so
extension=ming.so
extension=dom.so
extension=xmlreader.so
extension=curl.so
extension=mysqli.so
extension=mysql.so
extension=sockets.so
extension=imap.so
extension=xsl.so

Now when I tried this on the first system where that first configuration file comes from, it bombs spectacularly leaving a core-dump. I have NO IDEA what is going on. I just know that log messages like the following:

pid 54662 (php-cgi), uid 80: exited on signal 11 (core dumped)
pid 54655 (php-cgi), uid 80: exited on signal 11 (core dumped)
pid 54658 (php-cgi), uid 80: exited on signal 11 (core dumped)
pid 54661 (php-cgi), uid 80: exited on signal 11 (core dumped)
pid 54660 (php-cgi), uid 80: exited on signal 11 (core dumped)

are a thing of the past, until next time when I upgrade or re-compile PHP and the order is played with again.

If you have any hints, insights or knowledge of what is going on, and what magic order I have to place the extensions in, please let me know by sending me an email at xistence@gmail. This is going to be a mystery, for now, as I definitely don't have the time to figure out what is going on and why.

One more thing ... Near Space launch went off without a hitch

The near space launch went off without a hitch. We launched it at 0640 in the morning and recovered it a few hours later. To see the path the balloon took, please visit the Near Space CONNERY-1 page.

Yes, we really did name our first balloon flight ever CONNERY-1, read the Wiki page for information as to why :-P.

Happenings and assembly

School has started again, I am taking six classes. I am now really gearing up to finally leave UAT and go out into the work force. I have this semester, and two more to go and then comes the decision; graduate school or work? Not entirely sure yet which I want to do, but that is what life is all about, trying to figure out what the best would be, and possibly finding out it was a mistake and growing and learning.

There are others things that have been going on lately, I have been spending much time behind a computer screen programming. The intellectual challenges it provides me with are very enjoyable and great way to stay mentally fit. Also as a perfectionist by nature, it makes it really hard to start working on something and then put it down to go to sleep, it has to be perfect. That is probably also the reason why I now have a 300 line patch set instead of 500 lines. Yay for removing redundant code, and re-thinking the problem/solution.

Other things that I have been working on is a challenge that my room mate Victor (Pancho) gave me. It requires a recursion to complete the problem. In itself this does not generally present a problem, as the max recursion level is going to be limited to a fairly reasonable number, however in C/C++ there is still a massive amount of overhead when doing a function call. This includes things like setting up the stack, creating local variables, and then saving certain states. Extra garbage that you want to eliminate especially in tight loops. The problem however cannot be solved using for/while loops, or at least there is no way that I can figure out (if you want to know what it is that I am working on, contact me. Victor is going to make the challenge public later so I don't want to spoil it for everyone). So I have been writing some self-modifying code that unrolls loops on the fly. I will post code sometime in the near future when I have it partially working, not entirely sure yet how I want to proceed right now. More on that later!

Here is a bit of Intel assembly written in AT&T syntax for GCC to grok for Mac OS X/FreeBSD machines that use a stack based syscall infrastructure:

	__asm__("pushl	$21;\n"
		"pushl	%0;\n"
		"pushl	$0x1;\n"
		"movl	$4, %%eax;\n"
		"pushl	%%eax;\n"
		"int 	$0x80;\n"
		"addl	$16, %%esp;\n"
		:
		: "r" (answer)
		: "%eax");

Note that the length of the string is 21 characters (20 characters, and a newline which I appended before printing), and that answer is the char *. See my previous Intel post to see what the code does, and why. It is exactly the same printing routine, only difference is the assembly syntax. It really is too bad that GCC for Darwin does not grok the .intel_style inline assembly, it would have made things much easier.

You should be able to modify it to accept an integer to push onto the stack, however I have been unable to figure out why the following is not working:

	__asm__("pushl	%0;\n"
		"pushl	%1;\n"
		"pushl	$0x1;\n"
		"movl	$4, %%eax;\n"
		"pushl	%%eax;\n"
		"int 	$0x80;\n"
		"addl	$16, %%esp;\n"
		:
		: "r" (length), "r" (answer)
		: "%eax");

Assuming length is an integer and answer is a character pointer. It is kind of frustrating, because there are not many good resources out there on the web that explain inline assembly for GCC. The few that I have been found have been rather vague and have not explained very much. Maybe I am just using the wrong words, and or my Google-Fu is not strong enough.

Speaking of inline assembly, I have heard from some friends that are running on 64-bit systems that if you compile 64-bit binaries for Windows in Visual-C++ 2008 you are not allowed to use inline assembly, they have removed support for it. Does that seem wrong to anyone else? That seems like it would frustrate many developers of tight code that runs many times faster in assembly than using compiled code. Sure compilers have been getting better for ages, however at the same time in assembly the programmer has a lot more control over the CPU and where time is going to be spent than any other way.

Oh, Erlang is my new shiny programming language to learn.

I have the same impulses

This had me in tears. I have the exact same impulses! The want to know whether I can break the rules.

Near Space launch

This Saturday. Contact me if you want more information.

Notes are for the weak

The brain is where it is at. So after staring at the code for a good few minutes and moving some stuff around and then coming back after eating some food, I figured out where I was going, and suddenly I remembered what I was going to do. Off course, once again I changed my plans.

Currently I am sitting on a 500+ line patch for the project I am working on, luckily it is a project I myself am working on, so no-one else is waiting on my changes. There is a lot of things I have to fix before I submit this patch, I need to cherry pick certain ideas and further flesh them out and just get rid of others.

When it comes to programming I am very careful about throwing away code. While I agree with the fact that keeping every last piece of code around is a mistake, sometimes you just have this epiphany and you write a piece of code, you come back to it later and don't really need it, and thus delete it. Not to much later you come across another part of the code that could have used the exact solution you just deleted.

I was just recently looking for some code I had written almost 2 years ago when I first joined UAT, unfortunately because of bad backup practices, that code has been lost. I am thinking of moving all of that into a sub-version repository as well, so that I can easily sync the data between multiple OS's and machines, and also so that it keeps revisions in tact, so in case I would like to go back and fix something, or find something that was previously said.

Two weeks

For two weeks you made me feel like I could walk on clouds
For two weeks you made me feel like I was the only person in the world

Now, three months later it is time for me to give that feeling up. I don't think I will ever forget those two weeks. I will however forgive and forget about the three months thereafter.

It is a shame it has to end like this, it did not have to be this way. I hope that some day you too will make peace with the world, and look back upon the damage you have created and forgive yourself.

Why you need to write notes

I just today decided to pop open my Unix C++ wrapper, and I remember working on an event system last. Opening the code, it is clean, neatly written, however it does not fit in with the model that I decided upon previously. It is almost as if i went down a new road and left everything hanging. Normally I get back to programming something quickly enough that I remember my train of thought, I remember what I was doing, and why I was doing it.

In this case however the code has been sitting dormant for almost 4 months now. I have no clue where I left off, why I left off there and what I was going to do next. I do vaguely remember that I was going to go another route instead of the one I am still looking at now, I just don't remember why.

Notes are one of the most important things you can have to make you remember why you were going a certain route. Now, it'd be nice to have those notes stored in some tangible form, preferably on paper, and not in a brain which is known to forget items that are not as important to remember.

Well, here I go again, re-engineering the problem until I find a new solution!

Current mood: Unknown

The semester is over, done, and I have taken my finals, finished the work and I am now waiting to get all of my grades back. While the stress of classes is now off my back, and I have two weeks free, I am not happier. I am not feeling relieved. I don't believe that there is a shrink in the world that could describe my current mood and the way I am feeling with a single word.

Lets start off with the fact that I feel angry. I feel betrayed. Someone who I used to feel close to has cut off practically all communications, I used to trust this person. Now I can't anymore. It has become harder to ignore the bad, and just see the good. Really, I don't see why I should feel angry or betrayed about this at all. Maybe this is a good thing in the long run, shows me that humanity is not something to put ones trust into, that there is nothing good left. I am too much of an optimist to believe that, maybe I need to become more pessimistic. Revert back to my old habits of not trusting someone until they explicitly showed me that they were to be trusted.

I feel hatred towards a certain individual. For a multitude of reasons, but the most prominent one is the games she plays with peoples heads, the actions towards my good friends, and her attitude about the entire thing. We both keep it cordial now when we do have to interact. It is all an act, one that is well orchestrated and well rehearsed. Only my close friends know that anything is up, anyone outside of that would be led to believe that we are friends. I will say that although I once had a crush on this girl, it is all gone. Nothing is left. For all that matters now, she could go die in a fire. I would feel no remorse. I hope to move the feeling I have from hatred towards indifference.

The opposite of love is not hate, it's indifference - Elie Wiesel

The argument here is that if you hate someone or something you are likely to expend a lot of energy and attention thinking about the person. And I agree with that, because I hate her, I have been spending a lot of time thinking about her. Trying to figure out why she did what she did, trying to find a way to maybe get back at her. I need to move on, and become indifferent about it, just let the whole situation go. It is out of my hands now, and just because she is sabotaging her own life does not mean I have to let her take mine down with her.

I feel relieved. I know where I stand now with several people in my life. I have figured out what I can rely on other people for and who I can rely on. I know that certain people would have my back that I did not think would, and that other people who I thought would have my back definitely would not. It is a weird feeling.

I also feel happy. Another school semester is over with, just have to tie up the loose ends here and there, but it is over with. I get a break, to enjoy. Not sure what I am going to do yet for two whole weeks, I know I will probably be spending some time at school working on a project I have going on. I just got some new hardware and I now need to write the software for this hardware and actually get it to work. I am also happy because I live with a bunch of awesome people, and Black Hat and DefCon were a blast. Being able to talk to people you live with is absolutely awesome. Especially since they are willing to listen, are willing to talk back.