Always fill in a NULL for a zero-length char string or octet string in
authorTheodore Tso <tytso@mit.edu>
Thu, 29 Sep 1994 18:44:51 +0000 (18:44 +0000)
committerTheodore Tso <tytso@mit.edu>
Thu, 29 Sep 1994 18:44:51 +0000 (18:44 +0000)
asn1_remove_charstring or asn1_remove_octetstring.  This means we do
the same thing no matter whether the system returns NULL for malloc(0) or not.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4376 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/asn.1/ChangeLog
src/lib/krb5/asn.1/asn1buf.c

index 139d5bfbd02a526467f219917501b380a1520bf8..d4883a35ebc37d9c91c3c306f598d71833c3af3c 100644 (file)
@@ -1,3 +1,11 @@
+Thu Sep 29 14:26:34 1994  Theodore Y. Ts'o  (tytso@dcl)
+
+       * asn1buf.c (asn1buf_remove_octetstring, asn1buf_remove_charstring): 
+               If the length is zero, don't call calloc(0,1); instead
+               return a NULL pointer.  This way, we get consistent
+               behavior even on systems where malloc(0) returns a
+               non-null pointer.
+
 Tue Sep 27 23:31:50 1994  Theodore Y. Ts'o  (tytso@dcl)
 
        * krb5_encode.c (encode_krb5_enc_kdc_rep_part): = should have been
index 393014dddf497269a19f329cbcee12d95daa3c0f..81c7df309078c5b37056ab03c945953ce59a7890 100644 (file)
@@ -173,8 +173,13 @@ asn1_error_code asn1buf_remove_octetstring(DECLARG(asn1buf *, buf),
   int i;
 
   if(buf->next + len - 1 > buf->bound) return ASN1_OVERRUN;
+  if (len == 0) {
+      *s = 0;
+      return 0;
+  }
   *s = (asn1_octet*)calloc(len,sizeof(asn1_octet));
-  if((*s == NULL) && len) return ENOMEM;
+  if (*s == NULL)
+      return ENOMEM;
   for(i=0; i<len; i++)
     (*s)[i] = (asn1_octet)(buf->next)[i];
   buf->next += len;
@@ -190,9 +195,13 @@ asn1_error_code asn1buf_remove_charstring(DECLARG(asn1buf *, buf),
 {
   int i;
 
-  if(buf->next + len - 1 > buf->bound) return ASN1_OVERRUN;
+  if (buf->next + len - 1 > buf->bound) return ASN1_OVERRUN;
+  if (len == 0) {
+      *s = 0;
+      return 0;
+  }
   *s = (char*)calloc(len,sizeof(char));
-  if((*s == NULL) && len) return ENOMEM;
+  if (*s == NULL) return ENOMEM;
   for(i=0; i<len; i++)
     (*s)[i] = (char)(buf->next)[i];
   buf->next += len;