[Asterisk-code-review] cleanup: Fix fread() and fwrite() error handling (asterisk[13])

Richard Mudgett asteriskteam at digium.com
Tue Apr 25 15:28:17 CDT 2017


Richard Mudgett has posted comments on this change. ( https://gerrit.asterisk.org/5510 )

Change subject: cleanup: Fix fread() and fwrite() error handling
......................................................................


Patch Set 2: Code-Review-1

(4 comments)

https://gerrit.asterisk.org/#/c/5510/2/apps/app_minivm.c
File apps/app_minivm.c:

PS2, Line 859: 	if ((l = fread(bio->iobuf, 1, B64_BASEMAXINLINE, fi)) != B64_BASEMAXINLINE) {
             : 		if (ferror(fi))
             : 			return -1;
             : 
             : 		bio->ateof = 1;
             : 		return 0;
             : 	}
This function is rather stupid when handling short reads.

Should be:

if ((l = fread(...)) != B64_BASEMAXINLINE) {
  bio->ateof = 1;
  if (l == 0) {
    return 0;
  }
}


https://gerrit.asterisk.org/#/c/5510/2/apps/app_voicemail.c
File apps/app_voicemail.c:

PS2, Line 4748: 	if ((l = fread(bio->iobuf, 1, BASEMAXINLINE, fi)) != BASEMAXINLINE) {
              : 		if (ferror(fi))
              : 			return -1;
              : 
              : 		bio->ateof = 1;
              : 		return 0;
              : 	}
Same as app_minivm

if ((l = fread(...)) != BASEMAXINLINE) {
  bio->ateof = 1;
  if (l == 0) {
    return 0;
  }
}


https://gerrit.asterisk.org/#/c/5510/2/channels/chan_unistim.c
File channels/chan_unistim.c:

PS2, Line 2256: 	if (fwrite(line1, 1, TEXT_LENGTH_MAX, f) != TEXT_LENGTH_MAX) {
              : 		display_last_error("Unable to write history entry - date.");
              : 		return -1;
              : 	}
              : 	if (fwrite(pte->device->lst_cid, 1, TEXT_LENGTH_MAX, f) != TEXT_LENGTH_MAX) {
              : 		display_last_error("Unable to write history entry - callerid.");
              : 		return -1;
              : 	}
              : 	if (fwrite(pte->device->lst_cnm, 1, TEXT_LENGTH_MAX, f) != TEXT_LENGTH_MAX) {
These were correct before.  The code is creating records of TEXT_LENGTH_MAX not variable length records.

This entire file was correct before because the code reads/writes records of TEXT_LENGTH_MAX.


https://gerrit.asterisk.org/#/c/5510/2/formats/format_wav.c
File formats/format_wav.c:

PS2, Line 390: 	if (bytes < 0)
             : 		bytes = 0;
Probably should return NULL rather than attempt to read zero bytes.


-- 
To view, visit https://gerrit.asterisk.org/5510
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I8ca1cd47c20b2c0b72088bd13b9046f6977aa872
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-HasComments: Yes



More information about the asterisk-code-review mailing list