|
Lines 250-255
int cache_new_entry_from_ldap(char **dn,
Link Here
|
| 250 |
rv = 1; |
250 |
rv = 1; |
| 251 |
goto result; |
251 |
goto result; |
| 252 |
} |
252 |
} |
|
|
253 |
int vals = ldap_count_values_len(val); |
| 254 |
if ((cache_entry->attributes[cache_entry->attribute_count]->values = realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (vals+1)*sizeof(char*))) == NULL) { |
| 255 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed"); |
| 256 |
rv = 1; |
| 257 |
goto result; |
| 258 |
} |
| 259 |
if ((cache_entry->attributes[cache_entry->attribute_count]->length = realloc(cache_entry->attributes[cache_entry->attribute_count]->length, (vals+1)*sizeof(int))) == NULL) { |
| 260 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed"); |
| 261 |
rv = 1; |
| 262 |
goto result; |
| 263 |
} |
| 264 |
|
| 253 |
for (v = val; *v != NULL; v++) { |
265 |
for (v = val; *v != NULL; v++) { |
| 254 |
if ( (*v)->bv_val == NULL ) { |
266 |
if ( (*v)->bv_val == NULL ) { |
| 255 |
// check here, strlen behavior might be undefined in this case |
267 |
// check here, strlen behavior might be undefined in this case |
|
Lines 291-324
int cache_new_entry_from_ldap(char **dn,
Link Here
|
| 291 |
continue; |
303 |
continue; |
| 292 |
} |
304 |
} |
| 293 |
} |
305 |
} |
| 294 |
if ((cache_entry->attributes[cache_entry->attribute_count]->values = realloc(cache_entry->attributes[cache_entry->attribute_count]->values, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(char*))) == NULL) { |
306 |
if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count]=malloc(((*v)->bv_len+1)*sizeof(char))) == NULL) { |
| 295 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of values array failed"); |
307 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed"); |
| 296 |
rv = 1; |
308 |
rv = 1; |
| 297 |
goto result; |
309 |
goto result; |
| 298 |
} |
310 |
} |
| 299 |
if ((cache_entry->attributes[cache_entry->attribute_count]->length = realloc(cache_entry->attributes[cache_entry->attribute_count]->length, (cache_entry->attributes[cache_entry->attribute_count]->value_count+2)*sizeof(int))) == NULL) { |
311 |
memcpy(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count],(*v)->bv_val,(*v)->bv_len); |
| 300 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: realloc of length array failed"); |
312 |
cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count][(*v)->bv_len]='\0'; // terminate the string to be safe |
| 301 |
rv = 1; |
313 |
cache_entry->attributes[cache_entry->attribute_count]->length[cache_entry->attributes[cache_entry->attribute_count]->value_count]=(*v)->bv_len+1; |
| 302 |
goto result; |
|
|
| 303 |
} |
| 304 |
if ((*v)->bv_len == strlen((*v)->bv_val)) { |
| 305 |
if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strdup((*v)->bv_val)) == NULL) { |
| 306 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: strdup of value failed"); |
| 307 |
rv = 1; |
| 308 |
goto result; |
| 309 |
} |
| 310 |
cache_entry->attributes[cache_entry->attribute_count]->length[cache_entry->attributes[cache_entry->attribute_count]->value_count]=strlen(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count])+1; |
| 311 |
} else { // in this case something is strange about the string in bv_val, maybe contains a '\0' |
| 312 |
// the legacy approach is to copy bv_len bytes, let's stick with this and just terminate to be safe |
| 313 |
if ((cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count]=malloc(((*v)->bv_len+1)*sizeof(char))) == NULL) { |
| 314 |
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "cache_new_entry_from_ldap: malloc for value failed"); |
| 315 |
rv = 1; |
| 316 |
goto result; |
| 317 |
} |
| 318 |
memcpy(cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count],(*v)->bv_val,(*v)->bv_len); |
| 319 |
cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count][(*v)->bv_len]='\0'; // terminate the string to be safe |
| 320 |
cache_entry->attributes[cache_entry->attribute_count]->length[cache_entry->attributes[cache_entry->attribute_count]->value_count]=(*v)->bv_len+1; |
| 321 |
} |
| 322 |
cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count+1]=NULL; |
314 |
cache_entry->attributes[cache_entry->attribute_count]->values[cache_entry->attributes[cache_entry->attribute_count]->value_count+1]=NULL; |
| 323 |
cache_entry->attributes[cache_entry->attribute_count]->value_count++; |
315 |
cache_entry->attributes[cache_entry->attribute_count]->value_count++; |
| 324 |
} |
316 |
} |