char line[MAXPATHLEN];
int l;
while ((l=read_int(f))) {
- read_buf(f,line,l);
- line[l] = 0;
- add_exclude(line);
+ if (l >= MAXPATHLEN) overflow("recv_exclude_list");
+ read_sbuf(f,line,l);
+ add_exclude(line);
}
}
bzero((char *)file,sizeof(*file));
(*fptr) = file;
+ if (l2 >= MAXPATHLEN-l1) overflow("receive_file_entry");
+
strncpy(thisname,lastname,l1);
- read_buf(f,&thisname[l1],l2);
+ read_sbuf(f,&thisname[l1],l2);
thisname[l1+l2] = 0;
strncpy(lastname,thisname,MAXPATHLEN-1);
int l = read_int(f);
file->link = (char *)malloc(l+1);
if (!file->link) out_of_memory("receive_file_entry 2");
- read_buf(f,file->link,l);
- file->link[l] = 0;
+ read_sbuf(f,file->link,l);
}
#if SUPPORT_HARD_LINKS
total_read += len;
}
+void read_sbuf(int f,char *buf,int len)
+{
+ read_buf(f,buf,len);
+ buf[len] = 0;
+}
+
unsigned char read_byte(int f)
{
unsigned char c;
id = read_int(f);
while (id != 0) {
int len = read_byte(f);
- name = (char *)malloc(len);
+ name = (char *)malloc(len+1);
if (!name) out_of_memory("recv_uid_list");
- read_buf(f, name, len);
+ read_sbuf(f, name, len);
if (!list) {
uidlist = add_list(id, name);
list = uidlist;
id = read_int(f);
while (id != 0) {
int len = read_byte(f);
- name = (char *)malloc(len);
+ name = (char *)malloc(len+1);
if (!name) out_of_memory("recv_uid_list");
- read_buf(f, name, len);
+ read_sbuf(f, name, len);
if (!list) {
gidlist = add_list(id, name);
list = gidlist;
void out_of_memory(char *str)
{
- fprintf(FERROR,"out of memory in %s\n",str);
+ fprintf(FERROR,"ERROR: out of memory in %s\n",str);
+ exit_cleanup(1);
+}
+
+void overflow(char *str)
+{
+ fprintf(FERROR,"ERROR: buffer overflow in %s\n",str);
exit_cleanup(1);
}