ppp, slip: Validate VJ compression slot parameters completely
[pandora-kernel.git] / drivers / net / slip / slhc.c
index 0a0a664..042425e 100644 (file)
@@ -85,8 +85,9 @@ static long decode(unsigned char **cpp);
 static unsigned char * put16(unsigned char *cp, unsigned short x);
 static unsigned short pull16(unsigned char **cpp);
 
-/* Initialize compression data structure
+/* Allocate compression data structure
  *     slots must be in range 0 to 255 (zero meaning no compression)
+ * Returns pointer to structure or ERR_PTR() on error.
  */
 struct slcompress *
 slhc_init(int rslots, int tslots)
@@ -95,11 +96,14 @@ slhc_init(int rslots, int tslots)
        register struct cstate *ts;
        struct slcompress *comp;
 
+       if (rslots < 0 || rslots > 255 || tslots < 0 || tslots > 255)
+               return ERR_PTR(-EINVAL);
+
        comp = kzalloc(sizeof(struct slcompress), GFP_KERNEL);
        if (! comp)
                goto out_fail;
 
-       if ( rslots > 0  &&  rslots < 256 ) {
+       if (rslots > 0) {
                size_t rsize = rslots * sizeof(struct cstate);
                comp->rstate = kzalloc(rsize, GFP_KERNEL);
                if (! comp->rstate)
@@ -107,7 +111,7 @@ slhc_init(int rslots, int tslots)
                comp->rslot_limit = rslots - 1;
        }
 
-       if ( tslots > 0  &&  tslots < 256 ) {
+       if (tslots > 0) {
                size_t tsize = tslots * sizeof(struct cstate);
                comp->tstate = kzalloc(tsize, GFP_KERNEL);
                if (! comp->tstate)
@@ -142,7 +146,7 @@ out_free2:
 out_free:
        kfree(comp);
 out_fail:
-       return NULL;
+       return ERR_PTR(-ENOMEM);
 }