| 91 |
|
mapping_t *map_end_ptr; |
| 92 |
|
|
| 93 |
|
if (mapping == NULL){ |
| 94 |
< |
mapping = malloc(sizeof(mapping_t)); |
| 94 |
> |
mapping = sg_malloc(sizeof(mapping_t)); |
| 95 |
|
if (mapping == NULL) return; |
| 96 |
|
map_ptr = mapping; |
| 97 |
|
}else{ |
| 106 |
|
/* We've reached end of list and not found the entry.. So we need to malloc |
| 107 |
|
* new mapping_t |
| 108 |
|
*/ |
| 109 |
< |
map_end_ptr->next = malloc(sizeof(mapping_t)); |
| 109 |
> |
map_end_ptr->next = sg_malloc(sizeof(mapping_t)); |
| 110 |
|
if (map_end_ptr->next == NULL) return; |
| 111 |
|
map_ptr = map_end_ptr->next; |
| 112 |
|
} |
| 155 |
|
file_name[x] = '\0'; |
| 156 |
|
if (strcmp(file_name, temp_name) == 0) { |
| 157 |
|
if (sg_update_string(&svr_name, |
| 158 |
< |
dp->d_name) < 0) { |
| 158 |
> |
dp->d_name) < 0) { |
| 159 |
|
return NULL; |
| 160 |
|
} |
| 161 |
|
closedir(dirp); |
| 267 |
|
#endif |
| 268 |
|
|
| 269 |
|
|
| 270 |
– |
|
| 270 |
|
char *sg_f_read_line(FILE *f, const char *string){ |
| 271 |
|
/* Max line length. 8k should be more than enough */ |
| 272 |
|
static char line[8192]; |
| 277 |
|
} |
| 278 |
|
} |
| 279 |
|
|
| 280 |
+ |
sg_set_error(SG_ERROR_PARSE, NULL); |
| 281 |
|
return NULL; |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
char *sg_get_string_match(char *line, regmatch_t *match){ |
| 285 |
|
int len=match->rm_eo - match->rm_so; |
| 286 |
< |
char *match_string=malloc(len+1); |
| 286 |
> |
char *match_string=sg_malloc(len+1); |
| 287 |
|
|
| 288 |
|
match_string=strncpy(match_string, line+match->rm_so, len); |
| 289 |
|
match_string[len]='\0'; |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
|
| 295 |
– |
|
| 295 |
|
#ifndef HAVE_ATOLL |
| 296 |
|
static long long atoll(const char *s) { |
| 297 |
|
long long value = 0; |
| 336 |
|
* Returns strlen(src); if retval >= siz, truncation occurred. |
| 337 |
|
*/ |
| 338 |
|
size_t sg_strlcpy(char *dst, const char *src, size_t siz){ |
| 339 |
< |
register char *d = dst; |
| 340 |
< |
register const char *s = src; |
| 341 |
< |
register size_t n = siz; |
| 339 |
> |
register char *d = dst; |
| 340 |
> |
register const char *s = src; |
| 341 |
> |
register size_t n = siz; |
| 342 |
|
|
| 343 |
< |
/* Copy as many bytes as will fit */ |
| 344 |
< |
if (n != 0 && --n != 0) { |
| 345 |
< |
do { |
| 346 |
< |
if ((*d++ = *s++) == 0) |
| 347 |
< |
break; |
| 348 |
< |
} while (--n != 0); |
| 349 |
< |
} |
| 343 |
> |
/* Copy as many bytes as will fit */ |
| 344 |
> |
if (n != 0 && --n != 0) { |
| 345 |
> |
do { |
| 346 |
> |
if ((*d++ = *s++) == 0) |
| 347 |
> |
break; |
| 348 |
> |
} while (--n != 0); |
| 349 |
> |
} |
| 350 |
|
|
| 351 |
< |
/* Not enough room in dst, add NUL and traverse rest of src */ |
| 352 |
< |
if (n == 0) { |
| 353 |
< |
if (siz != 0) |
| 354 |
< |
*d = '\0'; /* NUL-terminate dst */ |
| 355 |
< |
while (*s++) |
| 356 |
< |
; |
| 357 |
< |
} |
| 351 |
> |
/* Not enough room in dst, add NUL and traverse rest of src */ |
| 352 |
> |
if (n == 0) { |
| 353 |
> |
if (siz != 0) |
| 354 |
> |
*d = '\0'; /* NUL-terminate dst */ |
| 355 |
> |
while (*s++) |
| 356 |
> |
; |
| 357 |
> |
} |
| 358 |
|
|
| 359 |
< |
return(s - src - 1); /* count does not include NUL */ |
| 359 |
> |
return(s - src - 1); /* count does not include NUL */ |
| 360 |
|
} |
| 361 |
|
|
| 362 |
|
/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */ |
| 385 |
|
* If retval >= siz, truncation occurred. |
| 386 |
|
*/ |
| 387 |
|
size_t sg_strlcat(char *dst, const char *src, size_t siz){ |
| 388 |
< |
register char *d = dst; |
| 389 |
< |
register const char *s = src; |
| 390 |
< |
register size_t n = siz; |
| 391 |
< |
size_t dlen; |
| 388 |
> |
register char *d = dst; |
| 389 |
> |
register const char *s = src; |
| 390 |
> |
register size_t n = siz; |
| 391 |
> |
size_t dlen; |
| 392 |
|
|
| 393 |
< |
/* Find the end of dst and adjust bytes left but don't go past end */ |
| 394 |
< |
while (n-- != 0 && *d != '\0') |
| 395 |
< |
d++; |
| 396 |
< |
dlen = d - dst; |
| 397 |
< |
n = siz - dlen; |
| 393 |
> |
/* Find the end of dst and adjust bytes left but don't go past end */ |
| 394 |
> |
while (n-- != 0 && *d != '\0') |
| 395 |
> |
d++; |
| 396 |
> |
dlen = d - dst; |
| 397 |
> |
n = siz - dlen; |
| 398 |
|
|
| 399 |
< |
if (n == 0) |
| 400 |
< |
return(dlen + strlen(s)); |
| 401 |
< |
while (*s != '\0') { |
| 402 |
< |
if (n != 1) { |
| 403 |
< |
*d++ = *s; |
| 404 |
< |
n--; |
| 405 |
< |
} |
| 406 |
< |
s++; |
| 407 |
< |
} |
| 408 |
< |
*d = '\0'; |
| 399 |
> |
if (n == 0) |
| 400 |
> |
return(dlen + strlen(s)); |
| 401 |
> |
while (*s != '\0') { |
| 402 |
> |
if (n != 1) { |
| 403 |
> |
*d++ = *s; |
| 404 |
> |
n--; |
| 405 |
> |
} |
| 406 |
> |
s++; |
| 407 |
> |
} |
| 408 |
> |
*d = '\0'; |
| 409 |
|
|
| 410 |
< |
return(dlen + (s - src)); /* count does not include NUL */ |
| 410 |
> |
return(dlen + (s - src)); /* count does not include NUL */ |
| 411 |
|
} |
| 412 |
|
|
| 413 |
|
int sg_update_string(char **dest, const char *src) { |
| 420 |
|
return 0; |
| 421 |
|
} |
| 422 |
|
|
| 423 |
< |
new = realloc(*dest, strlen(src) + 1); |
| 423 |
> |
new = sg_realloc(*dest, strlen(src) + 1); |
| 424 |
|
if (new == NULL) { |
| 425 |
|
return -1; |
| 426 |
|
} |
| 449 |
|
} |
| 450 |
|
|
| 451 |
|
kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL); |
| 452 |
+ |
if(kvmd == NULL) { |
| 453 |
+ |
sg_set_error(SG_ERROR_KVM_OPENFILES, NULL); |
| 454 |
+ |
} |
| 455 |
|
return kvmd; |
| 456 |
|
} |
| 457 |
|
|
| 464 |
|
} |
| 465 |
|
|
| 466 |
|
kvmd2 = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL); |
| 467 |
+ |
if(kvmd2 == NULL) { |
| 468 |
+ |
sg_set_error(SG_ERROR_KVM_OPENFILES, NULL); |
| 469 |
+ |
} |
| 470 |
|
return kvmd2; |
| 471 |
|
} |
| 472 |
|
#endif |
| 482 |
|
mib[1] = VM_UVMEXP; |
| 483 |
|
|
| 484 |
|
if (sysctl(mib, 2, &uvm, &size, NULL, 0) < 0) { |
| 485 |
+ |
sg_set_error(SG_ERROR_SYSCTL, "CTL_VM.VM_UVMEXP"); |
| 486 |
|
return NULL; |
| 487 |
|
} |
| 488 |
|
|
| 512 |
|
} |
| 513 |
|
|
| 514 |
|
int sg_drop_privileges() { |
| 515 |
< |
if (setegid(getgid()) != 0) return -1; |
| 516 |
< |
if (seteuid(getuid()) != 0) return -1; |
| 515 |
> |
if (setegid(getgid()) != 0) { |
| 516 |
> |
sg_set_error(SG_ERROR_SETEGID, NULL); |
| 517 |
> |
return -1; |
| 518 |
> |
} |
| 519 |
> |
if (seteuid(getuid()) != 0) { |
| 520 |
> |
sg_set_error(SG_ERROR_SETEUID, NULL); |
| 521 |
> |
return -1; |
| 522 |
> |
} |
| 523 |
|
return 0; |
| 524 |
|
} |
| 525 |
|
|
| 527 |
|
void *tmp = NULL; |
| 528 |
|
tmp = realloc(ptr, size); |
| 529 |
|
if(tmp == NULL) { |
| 530 |
< |
sg_set_error(SG_ERROR_MALLOC_FAILED, NULL); |
| 530 |
> |
sg_set_error(SG_ERROR_MALLOC, NULL); |
| 531 |
|
} |
| 532 |
|
return tmp; |
| 533 |
|
} |