Skip to content

Commit 559a2f3

Browse files
committed
Prefer smprintf instead of unsafe sprintf
Previously checking fans >= 10 overflowed the buffer and corrupted the heap. Found via AddressSanitizer. Regression from 968133e.
1 parent 272ef08 commit 559a2f3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/mbpfan.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ t_sensors *retrieve_sensors()
167167
int counter;
168168
for (counter = 0; counter < NUM_HWMONS; counter++) {
169169

170-
char hwmon_path[strlen(path_begin)+2];
171-
172-
sprintf(hwmon_path, "%s%d", path_begin, counter);
170+
char *hwmon_path = smprintf("%s%d", path_begin, counter);
173171

174172
int res = access(hwmon_path, R_OK);
175173
if (res == 0) {
@@ -186,8 +184,11 @@ t_sensors *retrieve_sensors()
186184

187185
}
188186

187+
free(hwmon_path);
189188
break;
190189
}
190+
191+
free(hwmon_path);
191192
}
192193

193194
int core = 0;

0 commit comments

Comments
 (0)