1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-12-07 02:46:36 +01:00

more thorough error checking

This commit is contained in:
Jfreegman
2014-09-23 22:51:56 -04:00
parent 48cf4ebf02
commit b071a9e992
11 changed files with 93 additions and 23 deletions

View File

@@ -629,9 +629,22 @@ static void load_data(Tox *m, char *path)
FILE *fd;
if ((fd = fopen(path, "rb")) != NULL) {
fseek(fd, 0, SEEK_END);
if (fseek(fd, 0L, SEEK_END) == -1) {
fclose(fd);
exit_toxic_err("failed in load_data", FATALERR_FILEOP);
}
int len = ftell(fd);
fseek(fd, 0, SEEK_SET);
if (len == -1) {
fclose(fd);
exit_toxic_err("failed in load_data", FATALERR_FILEOP);
}
if (fseek(fd, 0L, SEEK_SET)) {
fclose(fd);
exit_toxic_err("failed in load_data", FATALERR_FILEOP);
}
char *buf = malloc(len);
@@ -643,7 +656,7 @@ static void load_data(Tox *m, char *path)
if (fread(buf, len, 1, fd) != 1) {
free(buf);
fclose(fd);
exit_toxic_err("failed in load_data", FATALERR_FREAD);
exit_toxic_err("failed in load_data", FATALERR_FILEOP);
}
bool is_encrypted = tox_is_data_encrypted((uint8_t *) buf);