Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
User Journal

Journal Journal: Lame JE 3

So, Bethanie wants to know why I don't keep a journal.

Well, I do, but it is so infrequently updated that effectively I don't. I'm lazy, and don't have a lot to say, aside from smart-ass comments in reply to other people. I suppose I also keep pretty busy.

Let's see, what else is new? My latest book should be available in a couple of days, Hardware Hacking. That was a bit painful, I couldn't get the chapter I did done in any reasonable amount of time... I kept finding more and more stuff I wanted to cover. I think it wanted to be its own book. It was a chapter on HTPCs, and I built a Windows and a Linux HTPC. If anyone wants to know anything about HTPCs, I'll take a shot. :)

I'm working on the next book, "Stealing the Network: How to Own a Continent". We're shooting for that to be done in April.

Other than that, the usual stuff. Work, family... my teenager is having problems with his schoolwork (i.e. not doing it, and then lying about it.) He got soooo busted.

What else would people like to hear from me? I think I've covered my musical tastes pretty well in other people's journals. I read a fair amount. I had my publisher send me a copy of each of their Lego Mindstorms books, so I've been enjoying perusing those. I was very happy that the Mindstorms cancellation was a false alarm. My kids participate in the FLL.

User Journal

Journal Journal: My new favorite hotkey 13

OK, I suck keeping up on the bug puzzles, maybe I'll try regular prattling on like most journal entries. :) As I mentioned, I post the bug puzzles when I make them, but I don't write code for a living anymore, so I don't make them so often.

So I accidentally discovered a new hotkey: Alt-Home. Works in Mozilla and IE, takes you to your homepage (whatever your "home" button maps to in your browser.) Mine's Slashdot, BTW.

This is great, one more thing I don't have to take my hand off the keyboard and reach for the mouse to do. I prefer the keyboard for most stuff, and do a fair bit of my file management, program launching, etc... from the cmd prompt on my Windows boxen. Yes, I'm a geek.

That is all.

User Journal

Journal Journal: Bug Puzzle #4 6

OK, since you probably had to look at my stupid C questions, I might as well produce a bug puzzle.

What's wrong with this code snippet?

char *dest;
char src[] = "Hello";

dest = (char *)malloc (strlen(src));
strcpy (dest, src);

(This one should be relatively easy for most people, I think.)

User Journal

Journal Journal: I have some stupid C questions 13

OK, so I have some C questions that I don't know the answer to. You didn't think that just because I've been lecturing on bugs that I know what I'm doing, did you? :) I'm hoping someone knows the answers.

Doing structs. I'll have something like the following:

typedef struct _structname
{
    int member1;
    int member2;
} structname;

Now, as I understand it, _structname is a type definition, and structname is an instance. In other words, I can do stuff like:

_structname mystruct;

or

structname.member1 = 10;

Being that you don't always need a type definition or an instance (yet), then you can leave either _structname or structname out (but not both).

No problem, I'm following fine so far. (Assuming I've described it correctly, anyway.)

Now, I want to do a linked list:

typedef struct queuenode *qptr;

typedef struct queuenode
{
    time_t time;
    unsigned long address;
    qptr next;
} Queue;

In the above example, I would want to leave out the instance Queue. I don't have a use for Queue at that level, and I don't like it polluting my global namespace. In my experience, the compiler complains unless I have it in. Can anyone tell me why?

Second question. Is there a way to get back to a "regular" name when passing pointers between functions? This is hard to explain, which is probably part of the reason why I have difficulty searching for the answer on my own. Here's an example:

#include
#include
#include

void myalloc (char **buf);

int main()
{
    char *buf;
    myalloc (&buf);
    printf ("%s\n", buf);
    return 0;
}

void myalloc (char **buf)
{
    *buf = (char *)malloc (100);
      strcpy (*buf, "hello");
}

In the function myalloc, I'd like to refer to *buf by the simple name buf. I.e. I'd rather write:

buf = (char *)malloc (100);
strcpy (buf, "hello");

I have to do *buf, because that's the way it's declared in the function header. I have to declare it that way in the function header, because I have to pass the address of a pointer (as opposed to the value of a pointer) to the function if I need to modify the contents of the pointer.

I *think* the answer is that I have to do it this way. I know, I'm picky, deal. It just gets uglier when you've got structs, and you have to do stuff like *buf->member1 .

Any C wizards got a clue?

User Journal

Journal Journal: Bug Puzzle #3 15

Quick one this time.

typedef struct _BUF
{
    int size;
    char buf[1024];
} BUF;

int main ()
{
    BUF *buf;
    buf = (BUF *)malloc (sizeof (BUF));
    memset (&buf, 0, sizeof (buf));
    buf->size = 10;
    return 0;
}

# gcc bug3.c
# ./a.out
Segmentation fault (core dumped)

If you're paying attention, you'll find 2 bugs there.

User Journal

Journal Journal: Book Plug (-1, Offtopic) 5

No debugging this time, I need to hammer out some code and make some more mistakes first. :) You might also check out the recent thread on the vuln-dev mailing list (which I used to run) about security bugs. It's similar in spirit to my previous two entries.

Anyway, it seems like the in thing to do to make a journal entry when your new book comes out. :) There are a couple of recent ones that I've been involved with.

The first is Snort 2.0 Intrusion Detection

I'm really pleased that this one is doing so well. It's written by some of the Snort project guys and friends of mine. I wasn't heavily involved in this one, just asked as technical advisor.

The second is Stealing The Network

This one is more fun. It's fiction set in the hacker/infosec world. I conceived most of the scenarios, acted as tech editor, and wrote one of the chapters. Amazon just got their shipment, and aren't registering any sales to speak of yet. I'm hoping that changes soon. :)

If any of you happen to read one of them at some point, I'd love to hear what you think.

Also, if anyone is interested in doing a Slashdot review of either of these (or really, any Syngress book) e-mail me, and we'll see about getting a review copy to you.

Programming

Journal Journal: Bug Puzzle #2 4

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>

struct
{
  struct in_addr src;
  struct in_addr dest;
} addrs;

int main()
{
  inet_aton ("10.0.0.1", &addrs.src);
  inet_aton ("172.16.0.1", &addrs.dest);

  printf ("src: %s, dest: %s\n", inet_ntoa(addrs.src), inet_ntoa(addrs.dest));
}

[root@scutter root]# gcc bug.c
[root@scutter root]# ./a.out
src: 10.0.0.1, dest: 10.0.0.1

wtf?
Programming

Journal Journal: Bug Puzzle #1 6

#include <stdio.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>

int main (int argc, char *argv[])
{
  int i = 0;
  struct in_addr *inp;
  int result;

  if (argc < 2)
  {
    exit (1);
  }
  result = inet_aton (argv[1], inp);
  printf ("%x\n", *inp);
}

[root@scutter]# gcc bug.c
[root@scutter]# ./a.out 10.1.1.1
Segmentation fault

wtf?

(I know wtf actually, the point is to give people some entertainment by giving them a programming error to solve, in the spirit of the pclint ads.)

Compiled on Red Hat 8.0 if it's important to someone, but the error should be fairly platform independent. :)

Post answers or questions below.
User Journal

Journal Journal: Just testing 5

Nothing interesting to say. I've been reading other people's journals, and was just curious as to what the process is. I've been buried in work, I hope to get a break soon. If you care to, post a reply and say "hi".

Slashdot Top Deals

Do you suffer painful elimination? -- Don Knuth, "Structured Programming with Gotos"

Working...