Re: So you think you are (or wanna be) a hacker

2004-08-13 Thread John Hasler
John Summerfield writes: If you mean something different from all of these, please clarify. It seems likely that cfgfile is a per-user configuration file for an application. If so, HOME=/ should be treated as a error. -- John Hasler [EMAIL PROTECTED] Dancing Horse Hill Elmwood, Wisconsin --

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread Jason Rennie
On Thu, Aug 12, 2004 at 10:59:36AM +0800, John Summerfield wrote: So set the ball rolling, here is a snippet from a program I found via freshmeat the other day: configfile = malloc(strlen(getenv(HOME)) + 20); sprintf(configfile,%s/%s,getenv(HOME), cfgfile); Something a bit

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread Stefan Nicolai O'Rear
On Thu, Aug 12, 2004 at 04:38:25PM -0400, Jason Rennie wrote: Something a bit safer... char *home = getenv(HOME); if (home == NULL || cfgfile == NULL) hittheuseronthehead(); int sz = strlen(home) + strlen(cfgfile) + 2; char *configfile = malloc(sizeof(char)*sz);

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread John Summerfield
Jason Rennie wrote: On Thu, Aug 12, 2004 at 10:59:36AM +0800, John Summerfield wrote: So set the ball rolling, here is a snippet from a program I found via freshmeat the other day: configfile = malloc(strlen(getenv(HOME)) + 20); sprintf(configfile,%s/%s,getenv(HOME), cfgfile); Something

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread Kirk Strauser
On Thursday 12 August 2004 15:38, Jason Rennie wrote: Something a bit safer... char *home = getenv(HOME); if (home == NULL || cfgfile == NULL) hittheuseronthehead(); int sz = strlen(home) + strlen(cfgfile) + 2; char *configfile = malloc(sizeof(char)*sz);

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread Erik Steffl
John Summerfield wrote: Jason Rennie wrote: On Thu, Aug 12, 2004 at 10:59:36AM +0800, John Summerfield wrote: So set the ball rolling, here is a snippet from a program I found via freshmeat the other day: configfile = malloc(strlen(getenv(HOME)) + 20);

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread Jason Rennie
On Thu, Aug 12, 2004 at 01:51:46PM -0700, Stefan Nicolai O'Rear wrote: Using a glibc extension, how about: char *configfile; asprintf (configfile, %s/%s, getenv (HOME), cfgfile); aprintf auto-mallocs a buffer of the right size. Be sure to free()! On Thu, Aug 12, 2004 at 04:22:46PM

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread John Hasler
John Summerfield wrote: So set the ball rolling, here is a snippet from a program I found via freshmeat the other day: configfile = malloc(strlen(getenv(HOME)) + 20); sprintf(configfile,%s/%s,getenv(HOME), cfgfile); The malloc() might fail and return NULL. You need to deal with

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread John Summerfield
John Hasler wrote: John Summerfield wrote: So set the ball rolling, here is a snippet from a program I found via freshmeat the other day: configfile = malloc(strlen(getenv(HOME)) + 20); sprintf(configfile,%s/%s,getenv(HOME), cfgfile); The malloc() might fail and return NULL. You need

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread John Hasler
John Summerfield writes: The size of cfgfile is what bothered me as soon as I saw it.Presumably properly calculating the amount of storage to request takes care of that. As I said: use snprintf or do something else. In fact, use snprintf anyway. Leading / is fine... We don't have the rest

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread John Summerfield
John Hasler wrote: John Summerfield writes: The size of cfgfile is what bothered me as soon as I saw it.Presumably properly calculating the amount of storage to request takes care of that. As I said: use snprintf or do something else. In fact, use snprintf anyway. Leading / is fine...

Re: So you think you are (or wanna be) a hacker

2004-08-12 Thread Jason Rennie
On Thu, Aug 12, 2004 at 07:28:24PM -0500, John Hasler wrote: The malloc() might fail and return NULL. You need to deal with that. Good point. Can't believe I missed that... Jason -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL

So you think you are (or wanna be) a hacker

2004-08-11 Thread John Summerfield
I found this interesting article: http://www.osnews.com/story.php?news_id=7990 As I have a pretty clear view of my limitations as a C coder I thought I'd take a look. See how you score on the examples here: http://www.nostarch.com/frameset.php?startat=hownotc So set the ball rolling, here is a

Re: So you think you are (or wanna be) a hacker

2004-08-11 Thread William Ballard
On Thu, Aug 12, 2004 at 10:59:36AM +0800, John Summerfield wrote: I found this interesting article: http://www.osnews.com/story.php?news_id=7990 As I have a pretty clear view of my limitations as a C coder I thought I'd take a look. See how you score on the examples here:

Re: So you think you are (or wanna be) a hacker

2004-08-11 Thread Stefan Nicolai O'Rear
On Wed, Aug 11, 2004 at 08:23:21PM -0700, William Ballard wrote: On Thu, Aug 12, 2004 at 10:59:36AM +0800, John Summerfield wrote: configfile = malloc(strlen(getenv(HOME)) + 20); sprintf(configfile,%s/%s,getenv(HOME), cfgfile); The length of HOME could increase between invocations.

Re: So you think you are (or wanna be) a hacker

2004-08-11 Thread John Summerfield
William Ballard wrote: So set the ball rolling, here is a snippet from a program I found via freshmeat the other day: configfile = malloc(strlen(getenv(HOME)) + 20); sprintf(configfile,%s/%s,getenv(HOME), cfgfile); The length of HOME could increase between invocations. I don't fancy