LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2019, 07:13 PM   #16
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083

Quote:
Originally Posted by Andy Alt View Post
Hmm.. I think of it like... it's not detected because it hasn't happened. The program for some reason encountered a string that was longer than the destination array,
I mean, the buffer overrun has already happened. If you are find the string is longer than the array, then you've written past the end (the only way to avoid writing past the end is to truncate the string: then the string wouldn't be longer than the array). It's true that if you make it into the bufck function and detect the overrun, that you are avoiding a segfault or worse.
 
1 members found this post helpful.
Old 06-27-2019, 12:14 PM   #17
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
@ntubski, after a good night's sleep, I finally understood!
 
Old 07-19-2019, 11:00 PM   #18
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Original Poster
Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by ntubski View Post
Okay, interesting. I was thinking about suggesting a safer API (e.g., see http://www.and.org/vstr/comparison and http://www.and.org/vstr/security), but on the other hand, if most of your string manipulation is just reading and writing fixed-length strings like timestamps it might not be worth the trouble.
I didn't actually understand this completely - what other types of strings are there besides "fixed-length"? To my thinking, all strings are fixed length as they have to have memory allocated by using [x] or malloc/calloc, etc. ?

Quote:
Originally Posted by NevemTeve View Post
Maybe it would be more robust if you stored unix-timestamp instead of just day-of-month. (Or you could go for human-readable timestamp (strftime("%Y%m%d%H%M%S")), but then you have to choose from UTC/localtime. I'd suggest UTC.)
I've switched to using the value returned by time(NULL). Seems like that should accomplish what you're suggesting, right?
 
Old 07-20-2019, 12:07 AM   #19
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by Andy Alt View Post
I didn't actually understand this completely - what other types of strings are there besides "fixed-length"? To my thinking, all strings are fixed length as they have to have memory allocated by using [x] or malloc/calloc, etc. ?
I mean strings where you know the (maximum) length at compile time, so you don't have to use malloc/calloc.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How much swap area is enough/too much? Beowulf questions tnandy Linux - Software 4 06-14-2019 03:30 PM
LXer: My Nerd Life: Too Loud, Too Funny, Too Smart, Too Fat LXer Syndicated Linux News 0 01-24-2014 05:21 AM
How much swap usage is too much? sneakyimp Linux - Hardware 3 11-30-2006 04:48 PM
Well well well..what do we have here? DaBlade Linux - News 4 10-03-2005 10:07 AM
How well is FAT32 handled? GAWd Linux - Newbie 3 12-13-2003 05:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration