Nп/п : 25 из 100
 От   : Ralf Fassel                         2:5075/128        15 сен 23 13:12:26
 К    : The Natural Philosopher                               15 сен 23 14:14:02
 Тема : Re: Weird code crash
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <ygaedizitb9.fsf@akutech.de> bf8db041
@REPLY: 1@dont-email.me> f6ddb83e
@REPLYADDR Ralf Fassel <ralfixx@gmx.de>
@REPLYTO 2:5075/128 Ralf Fassel
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <ygaedizitb9.fsf@akutech.de>
@RFC-References: 1@dont-email.me>
<ygamsxoixhx.fsf@akutech.de>4@dont-email.me> <ygail8biyxm.fsf@akutech.de>1@dont-email.me>
@TZUTC: 0200
@PID: Gnus/5.13 (Gnus v5.13) Emacs/27.2
(gnu/linux)
@TID: FIDOGATE-5.12-ge4e8b94
You trust the contents of `outside`-files very much, do you? ;-)
I don`t know who can create files in the directory you`re scanning, but
not *assuring* the input you expect is another possible cause for
problems...

* The Natural Philosopher <tnp@invalid.invalid>
| > Further possibilities:
| > - how is `filbuf` used after the fread()?  If you use it as C-string, make
| >    sure it is 0-terminated (fread() won`t do that for you).  Maybe use
| >    fgets(3) instead?
| > 
| dir = opendir(VOLATILE_DIR);
>
| if(!dir)
| return;
| while ((dp = readdir (dir)) != NULL)
[looks good, error checks for stat() et al couldn`t hurt]
----
| if(len=strncmp(filbuf,"ZONE",4)) //supposed to reject
| a file whose contents do not start with ZONE
| goto baddata;

| // looking very much like a temperature file
| i=(int)filbuf[4] -`1`; // this is our zone from
| "ZONE2" etc. 1-4 is zone but index is 0-3 so subtract
| `1`

The access of filbuf[4] is ok (since you checked that there are at least
4 characters in the file), but what if nothing follows after the `ZONE`,
or ZONE is followed by anything but [1-4]?
=> Assert that `i` is in the valid index range here, before using it as
index into other arrays.

| p=strstr(filbuf,"
");
| if(p)
| {
| p++;
| if(q=strstr(p,"
"))
| {
| *q++=0;
| thermometers[i].name=strdup(p); //
| make a copy of the name and attach it
| to our thermometer structure

Memory leak if thermometers[i].name already contains something.

Other than that, I really would have it running under a debugger or
valgrind, since then *if* it crashes, you *know* *where* in your code it
crashes.

Good luck hunting!
R`
--- Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 * Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх