EXSPLRN has asked for the wisdom of the Perl Monks concerning the following question:

I have been writing a Perl script that accepts input from a form on a web page and then creates files/folders in my file system based on that input. Let me state now that I had not yet reached the point where I was actually doing anything with the file system... I was only processing form input and error checking. So I made a small change to my code (added an if block that would check a string representing a file path against two regexs and then add a leading / to the beginning of the string or remove trailing /'s from the end of the string), ran the script again, and got a 500 error... I checked my error logs and Apache gave me this line:
[Thu Oct 30 16:09:49 2003] [error] (8)Exec format error: exec of /opt/ +www/conf/dot/cgi-bin/create_volume.pl failed
So then I opened my source code with vi and it came up looking completely unlike Perl. Below is a small sample from the beginning. Does this look like anything to anybody? Is there some way to get my source code out of this? I was able to restore a backup from yesterday, but still, that is a day's work wasted... Most of all, I would really like to know what the heck could have happened. I am running Perl v5.6.1 on SunOS 5.8 with Apache v.1.3.26.
L#^S/\364\363\313\211\342\357\373-\336\250o\263&^O\277\212\271\233^E\3 +12\277-\305)^S\206\204S\327^]\303^Y\201\236\227\353\264\372D\271\341\ +317B\353\3122\37 6@\215\224\332PI1I\326Du\356\307^T;\300a\237[J^U\322L^R\247M\232f\320^ +P\370b^C*/^U\361^S\224\237\221K\224\223g\377\210Ecb\210\206B\215\212\ +2024\313S\256\20 6\231\247\246^^^]^]^O\234^F^S@^W^O\353t\302\300\345\305xA\352H^T'm^O\3 +77^_\222\235\321\335&\355\201 r\325\355as\257\215KC\271z\250J^E/L\217 +\262\322EH\215\3 76h^G\207=.^QXX\2361n\225\331]f\204f8\272#^P$\373\212^R^K^Z^Q\230;\260 +9^Uxg3s ^H\243\334\262^O\237Py\371\367=\222\221\272\221\341\220\235\344K<\202: +\330A\225\305k\367c\265?\244\317\216\213^S^YT\252\350\222\266\202WR\3 +32,\321^_\234\25 5\231\326^\6b^YA\236?7X^\m\242^]m\204\217\207\325\333O\343\243^G\210\2 +07^E\225\246\240\352\340\322s~Ir{K\370^Lj9\346\272\326%T\276%^AX=\234 +\327B\260^T\273\ 202\246\221\317N\341*.\263^Ae\24540\202\241pq4m\213\254jQ`\272\325\323 +\253\333\260\323\252Wj\272^^\307`\275\335\372\212^CYe\357\256ikt\351q +\257\215\331\353 \2757\273C\370\336\325*\226^F\325\320\270Z\266\357}|\235w)\367\333\360 +G\366b;!^]E\306_S{5\254$\367\206\261\314\276YSW\262~\242u\232\2602^Y\ +336\276D\264\230 \325^^Bf\304^^V"\257\222\211\370\272\250\233\324^F\255\314\324^U3\264\ +204\3222\207\310w\374\202^\245\306}\241$?\223=^N^?\346^N\335^Q)_\361^ +Q^L^C\^A\345\270 \267\233\316\255.a\211\376&,\3060\264\304ll\317\371q^H\310n\327(HE\373 +\242\233B\237\345\205^T^\370\326\264\223\320\305\202}\223\355D*^B\262 +f\212]=p;\g\2616 z^X\353g\261_9e^W\332"\247\352\326\314\337\273i\273\233\271\203\302\26 +6\215/^N\374\311w\307[z~M^R\314\342\252\364\365\243G\3230x^O\305%W\32 +7\\325\263^G^UD\ 375^\\367\223\356^Q\243^B\247^P\365\267\361i\324^N3"\225\372+\244\345e +yW^A\214\216a\255\206\224\222\\233Z,x\226q\255E\260r^]\351\215\253>zk +\326\305\360#4\3 30\354\240\200\373^Q\372\370\204y|\307\260\257#\255q^N^^=^ZY\246\250^X +_\271G^T(^D<^B*\375\374e0\212hi^U^]?\20410k.^E\377\243\232^T\322\256\ +266\357\356#\354 '^Of+^^K)\262\344[9\235\202\355TK^?^R"0m\203\270\257\233%~\322|\326\37 +3*\335\232Vf^N^H\351\315gv^Y^G^PD^_$^O\255^[\\251\371K\273\313^T\270' +\200Q\222'\240\3 35\240^B^K\362\232\343V\342\226V\332^U\330\307^V^U}^T\270\306\2715\246 +\322\2654\366g\250 y\215\254\2273zF\304\366#\303\205\240U^_m\222%fD|\ +307\325^Q*\2755\ 320^G\3168\333t\356G\227\235\325$o^S\230\220\205\316N:\253^Pg\321\247\ +215\303^\223\227\324\220"a\376\272\226# \373\342

Replies are listed 'Best First'.
Re: Ran my script, got a 500, and now the code is encoded???
by sauoq (Abbot) on Oct 31, 2003 at 00:09 UTC

    Uh... Bummer.

    I don't think we'll be able to tell you exactly what happened. The apache error indicates that the file was probably already corrupted when you tried to invoke it as a CGI.

    Does this look like anything to anybody?

    Yes, it looks like you cut and pasted a binary file out of vi or less. Try running file(1) and/or strings(1) on it and you may learn what it is.

    -sauoq
    "My two cents aren't worth a dime.";
    
      I guess I should have asked "Does this look like any kind of file representation that you have seen before?" Anyway... I ran file and just got "data". Oh well.
Re: Ran my script, got a 500, and now the code is encoded???
by castaway (Parson) on Oct 31, 2003 at 11:35 UTC
    Umm.. Actually that looks like it got somehow converted to a unicode representation of your file.. With some weird control codes thrown in.. I've no idea how though.

    Just for the interest, what happens if you de-unicode that somehow? (Although, the numbers are too high, arent they? hmm, mebbe I dont know after all.. :)

    Sure looks fun tho.

    C.

      I attempted to convert it back from Unicode and got nothing... Oh well. It was worth a shot. Luckily I had a lot of meetings yesterday and a department lunch so I really only had about 4 hours of work into it at the time, and it's nothing that can't be quickly rewritten. I just don't want it to happen again. I'll have to start backing up more frequently.
Re: Ran my script, got a 500, and now the code is encoded???
by Molt (Chaplain) on Oct 31, 2003 at 11:05 UTC

    Finger in the air guess here, but are you manipulating an output file's name, and if so could the regexes have been subtly broken and accidentally set the name of the output file to be the same as the script?

    In short, 'Is this your output file'?

    Yes, I appreciate this would involve quite a few nasty configuration mistakes.. especially with permissions in the cgi-bin directory, but I know I managed to do this kind of mistake in my first job.

      No, I was not using any output files at the time. Only input from a form.