]> code.citadel.org Git - citadel.git/blobdiff - citadel/file_ops.c
TEXTCLIENT: getutline also belongs to the textclient. Tnx to Lightspeed for pointing...
[citadel.git] / citadel / file_ops.c
index ba4c2c3a9c533817a3843ea38e110ec3dae74656..a3e8d749859590c8ea035e51a59f9ab010ea71b0 100644 (file)
@@ -588,10 +588,15 @@ void cmd_read(char *cmdbuf)
        long start_pos;
        size_t bytes;
        char buf[SIZ];
+       int rc;
 
        /* The client will transmit its requested offset and byte count */
        start_pos = extract_long(cmdbuf, 0);
        bytes = extract_int(cmdbuf, 1);
+       if ((start_pos < 0) || (bytes <= 0)) {
+               cprintf("%d you have to specify a value > 0.\n", ERROR + ILLEGAL_VALUE);
+               return;
+       }
 
        if (CC->download_fp == NULL) {
                cprintf("%d You don't have a download file open.\n",
@@ -604,7 +609,16 @@ void cmd_read(char *cmdbuf)
                bytes = sizeof(buf);
        }
 
-       fseek(CC->download_fp, start_pos, 0);
+       rc = fseek(CC->download_fp, start_pos, 0);
+       if (rc < 0) {
+               cprintf("%d your file is smaller then %ld.\n", ERROR + ILLEGAL_VALUE, start_pos);
+               syslog(LOG_ALERT, "your file %s is smaller then %ld. [%s]\n", 
+                      CC->upl_path, 
+                      start_pos,
+                      strerror(errno));
+
+               return;
+       }
        bytes = fread(buf, 1, bytes, CC->download_fp);
        if (bytes > 0) {
                /* Tell the client the actual byte count and transmit it */