fixed some crash bugs in the nt forms parsing
authorAndrew Tridgell <tridge@samba.org>
Tue, 18 Apr 2000 02:17:46 +0000 (02:17 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 18 Apr 2000 02:17:46 +0000 (02:17 +0000)
(This used to be commit e505a6ddf3df37ca485cae117c53fa96d736f897)

source3/lib/util_file.c
source3/printing/nt_printing.c

index f3e28795874211661e67ceb9c028a15ad901ee87..c3b444ffa16880e4b8cce5aff8d784ed25a8dfb6 100644 (file)
@@ -371,6 +371,8 @@ char *file_load(char *fname, size_t *size)
        int fd;
        SMB_STRUCT_STAT sbuf;
        char *p;
+
+       if (!fname || !*fname) return NULL;
        
        fd = open(fname,O_RDONLY);
        if (fd == -1) return NULL;
index 7cb2e9aab5a1fb93f2799b5562e5d7a9002f92aa..44f228880a8e51fe011c23a208d13765fe464bae 100644 (file)
@@ -42,7 +42,9 @@ static BOOL parse_form_entry(char *line, nt_forms_struct *buf)
        char *tok[MAXTOK];
        int count = 0;
 
-       tok[count] = strtok(line,":");
+       tok[0] = strtok(line,":");
+
+       if (!tok[0]) return False;
        
        /* strip the comment lines */
        if (tok[0][0]=='#') return (False);     
@@ -53,7 +55,7 @@ static BOOL parse_form_entry(char *line, nt_forms_struct *buf)
                count++;
        }
 
-       DEBUG(106,("Found [%d] tokens\n", count));
+       if (count < MAXTOK-1) return False;
 
        StrnCpy(buf->name,tok[NAMETOK],sizeof(buf->name)-1);
        buf->flag=atoi(tok[FLAGTOK]);
@@ -83,11 +85,11 @@ int get_ntforms(nt_forms_struct **list)
                return(0);
        }
 
+       *list = NULL;
+
        for (i=0; lines[i]; i++) {
                char *line = lines[i];
 
-               DEBUG(105,("%s\n",line));
-               
                *list = Realloc(*list, sizeof(nt_forms_struct)*(total+1));
                if (! *list)
                {
@@ -104,8 +106,6 @@ int get_ntforms(nt_forms_struct **list)
 
        file_lines_free(lines);
 
-       DEBUG(104,("%d info lines on %d\n",total, grandtotal));
-
        return(total);
 }