fix: strlcpy usage & changes

This commit is contained in:
javalsai 2025-06-21 05:12:49 +02:00
parent 002788c693
commit 8403bfc26c
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8
2 changed files with 4 additions and 6 deletions

View File

@ -125,12 +125,10 @@ void moarEnv(char* user, struct session session, struct passwd* pw,
size_t newbuf_len = home_len + strlen(file2sourcepath) + 2; size_t newbuf_len = home_len + strlen(file2sourcepath) + 2;
char* newbuf = malloc(newbuf_len); // nullbyte and slash char* newbuf = malloc(newbuf_len); // nullbyte and slash
if (newbuf == NULL) continue; // can't bother if (newbuf == NULL) continue; // can't bother
strlcpy(newbuf, pw->pw_dir, newbuf_len); memcpy(newbuf, pw->pw_dir, newbuf_len);
newbuf[home_len] = '/'; // assume pw_dir doesn't start with '/' :P newbuf[home_len] = '/'; // assume pw_dir doesn't start with '/' :P
strlcpy(&newbuf[home_len + 1], file2sourcepath, memcpy(&newbuf[home_len + 1], file2sourcepath, newbuf_len - home_len);
newbuf_len - home_len - 1);
/* printf("DEBUG(user_source)!!!! %d %s\n", i, newbuf); */
sourceFileTry(newbuf); sourceFileTry(newbuf);
free(newbuf); free(newbuf);
} }

View File

@ -126,7 +126,7 @@ struct parser_error parse_key(enum introspection_type typ, union typ_ptr at,
aux_str = strdup(key); aux_str = strdup(key);
if (!aux_str) FAIL("allocation failure"); if (!aux_str) FAIL("allocation failure");
aux_err = parse_str_inplace(aux_str); aux_err = parse_str_inplace(aux_str);
if (aux_err.msg != NULL) { if (!aux_err.msg) {
free(aux_str); free(aux_str);
return aux_err; return aux_err;
} }
@ -157,7 +157,7 @@ struct parser_error parse_key(enum introspection_type typ, union typ_ptr at,
aux_str = strdup(key); aux_str = strdup(key);
if (!aux_str) FAIL("allocation failure"); if (!aux_str) FAIL("allocation failure");
aux_err = parse_str_inplace(aux_str); aux_err = parse_str_inplace(aux_str);
if (aux_err.msg != NULL) { if (!aux_err.msg) {
free(aux_str); free(aux_str);
return aux_err; return aux_err;
} }