Skip to content

Commit dfbf9f1

Browse files
committed
for -> do while
1 parent a8b4075 commit dfbf9f1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

kernel/throne_tracker.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,18 @@ FILLDIR_RETURN_TYPE user_de_actor(MY_ACTOR_CTX_ARG, const char *name,
184184
if (strncmp(name, ".", namelen) == 0 || strncmp(name, "..", namelen) == 0)
185185
return FILLDIR_ACTOR_CONTINUE;
186186

187-
uid_t uid = 0;
188-
for (int i = 0; i < namelen; i++) {
189-
if (name[i] < '0' || name[i] > '9')
190-
return FILLDIR_ACTOR_CONTINUE;
191-
uid = uid * 10 + (name[i] - '0');
192-
}
187+
// oops!
188+
if (namelen == 0)
189+
return FILLDIR_ACTOR_CONTINUE;
190+
191+
uid_t uid = 0;
192+
int i = 0;
193+
do {
194+
if (name[i] < '0' || name[i] > '9')
195+
return FILLDIR_ACTOR_CONTINUE;
196+
uid = uid * 10 + (name[i] - '0');
197+
i++;
198+
} while (i < namelen);
193199

194200
if (data->count >= data->max_users)
195201
return FILLDIR_ACTOR_STOP;
@@ -385,8 +391,13 @@ int scan_user_data_for_uids(struct list_head *uid_list)
385391
return -ENOENT;
386392
}
387393

394+
// probably wont happen
395+
if (active_users == 0)
396+
return 0;
397+
388398
// Scan each user's data directory
389-
for (size_t i = 0; i < active_users; i++) {
399+
size_t i = 0;
400+
do {
390401
uid_t user_id = user_ids[i];
391402
size_t packages_found = 0;
392403
size_t errors_count = 0;
@@ -401,7 +412,8 @@ int scan_user_data_for_uids(struct list_head *uid_list)
401412

402413
total_packages += packages_found;
403414
total_errors += errors_count;
404-
}
415+
i++;
416+
} while ( i < active_users);
405417

406418
if (total_errors > 0) {
407419
pr_warn("UserDE UID: Encountered %zu errors while scanning user data directories\n",

0 commit comments

Comments
 (0)