* Fixed another fread() bug
authorArt Cancro <ajc@citadel.org>
Sun, 17 Jan 2010 23:12:55 +0000 (23:12 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 17 Jan 2010 23:12:55 +0000 (23:12 +0000)
citadel/config.c
citadel/file_ops.c

index 4c2509f0028d49b569814aec4fa07fa77926dcae..9d731d3e7fee51a8bfe67588c50b485f9fab649a 100644 (file)
@@ -69,7 +69,7 @@ void get_config(void) {
        }
        memset(&config, 0, sizeof(struct config));
        rv = fread((char *) &config, sizeof(struct config), 1, cfp);
-       if (rv != sizeof(struct config))
+       if (rv != 1)
        {
                fprintf(stderr, 
                        "Warning: The config file %s has unexpected size. \n",
index b81ba6bed243fdcbea64209a1798cfba23d6c5a4..b7b0cb3f32c5935f0d4af095918b3e7acee3db65 100644 (file)
@@ -621,7 +621,6 @@ void cmd_read(char *cmdbuf)
 {
        long start_pos;
        size_t bytes;
-       size_t actual_bytes;
        char *buf = NULL;
 
        start_pos = extract_long(cmdbuf, 0);
@@ -637,9 +636,13 @@ void cmd_read(char *cmdbuf)
        buf = malloc(bytes + 1);
 
        fseek(CC->download_fp, start_pos, 0);
-       actual_bytes = fread(buf, 1, bytes, CC->download_fp);
-       cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
-       client_write(buf, actual_bytes);
+       if (fread(buf, 1, bytes, CC->download_fp) == 1) {
+               cprintf("%d %d\n", BINARY_FOLLOWS, (int)bytes);
+               client_write(buf, bytes);
+       }
+       else {
+               cprintf("%d %s\n", ERROR, strerror(errno));
+       }
        free(buf);
 }