Carl Shapiro pushed to branch master at cmucl / cmucl
Commits: 06958230 by Carl Shapiro at 2024-04-25T12:45:59-07:00 Fix the retry limit for resizing password entry buffer
The previous version checked that the buffer had not exceeded the limit of 1MiB after the buffer was resized. In otherwords, the buffer is allowed to grow past the limit before the retry loop is exited.
This change moves the check of the buffer size before the allocation occurs. Now, the retry loop is exited before the buffer would grow past the limit.
- - - - - 520213dd by Carl Shapiro at 2024-04-26T02:00:30+00:00 Merge branch 'retry-limit' into 'master'
Fix the retry limit for resizing password entry buffer
See merge request cmucl/cmucl!212 - - - - -
1 changed file:
- src/lisp/os-common.c
Changes:
===================================== src/lisp/os-common.c ===================================== @@ -753,26 +753,27 @@ os_file_author(const char *path) * Keep trying with larger buffers until a maximum is reached. We * assume (1 << 20) is large enough for any OS. */ - while (size <= (1 << 20)) { - switch (getpwuid_r(sb.st_uid, &pwd, buffer, size, &ppwd)) { - case 0: - /* Success, though we might not have a matching entry */ - result = (ppwd == NULL) ? NULL : strdup(pwd.pw_name); - goto exit; - case ERANGE: - /* Buffer is too small, double its size and try again */ - size *= 2; - if ((buffer = realloc(obuffer, size)) == NULL) { - goto exit; - } - obuffer = buffer; - continue; - default: - /* All other errors */ - goto exit; - } +again: + switch (getpwuid_r(sb.st_uid, &pwd, buffer, size, &ppwd)) { + case 0: + /* Success, though we might not have a matching entry */ + result = (ppwd == NULL) ? NULL : strdup(pwd.pw_name); + break; + case ERANGE: + /* Buffer is too small, double its size and try again */ + size *= 2; + if (size > (1 << 20)) { + break; + } + if ((buffer = realloc(obuffer, size)) == NULL) { + break; + } + obuffer = buffer; + goto again; + default: + /* All other errors */ + break; } -exit: free(obuffer);
return result;
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/99abb703b68b67143b6a774...