comparison src/unexmacosx.c @ 53737:349eb7d143cf

unexecmacos.x (unexec_copy): Do not copy more than was requested (count) to prevent overwriting during unexec.
author Steven Tamm <steventamm@mac.com>
date Wed, 28 Jan 2004 06:07:36 +0000
parents d9dc58d31ffb
children 8434603cae5b
comparison
equal deleted inserted replaced
53736:df8ff5ff116d 53737:349eb7d143cf
190 dest in outfd. Return true if successful, false otherwise. */ 190 dest in outfd. Return true if successful, false otherwise. */
191 static int 191 static int
192 unexec_copy (off_t dest, off_t src, ssize_t count) 192 unexec_copy (off_t dest, off_t src, ssize_t count)
193 { 193 {
194 ssize_t bytes_read; 194 ssize_t bytes_read;
195 ssize_t bytes_to_read;
195 196
196 char buf[UNEXEC_COPY_BUFSZ]; 197 char buf[UNEXEC_COPY_BUFSZ];
197 198
198 if (lseek (infd, src, SEEK_SET) != src) 199 if (lseek (infd, src, SEEK_SET) != src)
199 return 0; 200 return 0;
201 if (lseek (outfd, dest, SEEK_SET) != dest) 202 if (lseek (outfd, dest, SEEK_SET) != dest)
202 return 0; 203 return 0;
203 204
204 while (count > 0) 205 while (count > 0)
205 { 206 {
206 bytes_read = read (infd, buf, UNEXEC_COPY_BUFSZ); 207 bytes_to_read = count > UNEXEC_COPY_BUFSZ ? UNEXEC_COPY_BUFSZ : count;
208 bytes_read = read (infd, buf, bytes_to_read);
207 if (bytes_read <= 0) 209 if (bytes_read <= 0)
208 return 0; 210 return 0;
209 if (write (outfd, buf, bytes_read) != bytes_read) 211 if (write (outfd, buf, bytes_read) != bytes_read)
210 return 0; 212 return 0;
211 count -= bytes_read; 213 count -= bytes_read;