static int decode_realms(krb5_context context, const char *tr, int length, struct tr_realm **realms) { struct tr_realm *r = NULL; char *tmp; int quote = 0; const char *start = tr; int i; for(i = 0; i < length; i++){ if(quote){ quote = 0; continue; } if(tr[i] == '\\'){ quote = 1; continue; } if(tr[i] == ','){ tmp = malloc(tr + i - start + 1); if(tmp == NULL){ krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; } memcpy(tmp, start, tr + i - start); tmp[tr + i - start] = '\0'; r = make_realm(tmp); if(r == NULL){ free_realms(*realms); krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; } *realms = append_realm(*realms, r); start = tr + i + 1; } } tmp = malloc(tr + i - start + 1); if(tmp == NULL){ free(*realms); krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; } memcpy(tmp, start, tr + i - start); tmp[tr + i - start] = '\0'; r = make_realm(tmp); if(r == NULL){ free_realms(*realms); krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; } *realms = append_realm(*realms, r); return 0; }
static int decode_realms(krb5_context context, const char *tr, size_t length, struct tr_realm **realms) { struct tr_realm *r = NULL; char *tmp; int quote = 0; const char *start = tr; int i; for(i = 0; i < length; i++){ if(quote){ quote = 0; continue; } if(tr[i] == '\\'){ quote = 1; continue; } if(tr[i] == ','){ tmp = malloc(tr + i - start + 1); if(tmp == NULL) return krb5_enomem(context); memcpy(tmp, start, tr + i - start); tmp[tr + i - start] = '\0'; r = make_realm(tmp); if(r == NULL){ free_realms(*realms); return krb5_enomem(context); } *realms = append_realm(*realms, r); start = tr + i + 1; } } tmp = malloc(tr + i - start + 1); if(tmp == NULL){ free(*realms); return krb5_enomem(context); } memcpy(tmp, start, tr + i - start); tmp[tr + i - start] = '\0'; r = make_realm(tmp); if(r == NULL){ free_realms(*realms); return krb5_enomem(context); } *realms = append_realm(*realms, r); return 0; }