diff options
author | Christian Gonzalez <gondchri@amazon.com> | 2023-02-23 22:43:14 +0000 |
---|---|---|
committer | Andrew Hutchings <andrew@linuxjedi.co.uk> | 2023-03-08 10:36:25 +0000 |
commit | 8b0f766c6c65a4c4260876688090e2b390014a60 (patch) | |
tree | 33e5f342958d89234aaac08da3c3a76740a9fe3a /mysys | |
parent | e240e2749eeaadc594b05dc600440f316d50eaee (diff) | |
download | mariadb-git-8b0f766c6c65a4c4260876688090e2b390014a60.tar.gz |
Minimize unsafe C functions usage
Replace calls to `sprintf` and `strcpy` by the safer options `snprintf`
and `safe_strcpy` in the following directories:
- libmysqld
- mysys
- sql-common
- strings
All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer
Amazon Web Services, Inc.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_atomic_writes.c | 16 | ||||
-rw-r--r-- | mysys/my_conio.c | 2 | ||||
-rw-r--r-- | mysys/my_likely.c | 2 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 2 |
4 files changed, 13 insertions, 9 deletions
diff --git a/mysys/my_atomic_writes.c b/mysys/my_atomic_writes.c index b383af11ba8..357448d10d2 100644 --- a/mysys/my_atomic_writes.c +++ b/mysys/my_atomic_writes.c @@ -112,7 +112,7 @@ static my_bool test_if_shannon_card_exists() char path[32]; struct stat stat_buff; - sprintf(path, "/dev/df%c", dev_part); + snprintf(path, sizeof(path), "/dev/df%c", dev_part); #ifdef TEST_SHANNON if (lstat(path, &stat_buff) < 0) { @@ -121,8 +121,10 @@ static my_bool test_if_shannon_card_exists() } #endif shannon_devices[shannon_found_devices].st_dev= stat_buff.st_rdev; - sprintf(shannon_devices[shannon_found_devices].dev_name, "/dev/sct%c", - dev_part); + snprintf(shannon_devices[shannon_found_devices].dev_name, + sizeof(shannon_devices[shannon_found_devices].dev_name), + "/dev/sct%c", + dev_part); #ifdef TEST_SHANNON printf("%s(): i=%d, stat_buff.st_dev=0x%lx, stat_buff.st_rdev=0x%lx, st_rdev=0x%lx, dev_name=%s\n", @@ -145,13 +147,15 @@ static my_bool test_if_shannon_card_exists() for (dev_no= 1 ; dev_no < 9 ; dev_no++) { - sprintf(path, "/dev/df%c%d", dev_part, dev_no); + snprintf(path, sizeof(path), "/dev/df%c%d", dev_part, dev_no); if (lstat(path, &stat_buff) < 0) break; shannon_devices[shannon_found_devices].st_dev= stat_buff.st_rdev; - sprintf(shannon_devices[shannon_found_devices].dev_name, "/dev/sct%c%d", - dev_part, dev_no); + snprintf(shannon_devices[shannon_found_devices].dev_name, + sizeof(shannon_devices[shannon_found_devices].dev_name), + "/dev/sct%c%d", + dev_part, dev_no); #ifdef TEST_SHANNON printf("%s(): i=%d, st_dev=0x%lx, st_rdev=0x%lx, dev_name=%s\n", diff --git a/mysys/my_conio.c b/mysys/my_conio.c index 04750635dd3..ec30b9dc6c7 100644 --- a/mysys/my_conio.c +++ b/mysys/my_conio.c @@ -50,7 +50,7 @@ int my_pthread_auto_mutex_lock(HANDLE* ph, const char* name, int id, int time) DWORD res; char tname[FN_REFLEN]; - sprintf(tname, "%s-%08X", name, id); + snprintf(tname, sizeof(tname), "%s-%08X", name, id); *ph= CreateMutex(NULL, FALSE, tname); if (*ph == NULL) diff --git a/mysys/my_likely.c b/mysys/my_likely.c index c6fca5b7146..b63e5f4211e 100644 --- a/mysys/my_likely.c +++ b/mysys/my_likely.c @@ -77,7 +77,7 @@ void end_my_likely(FILE *out) if (!(likely_file= out)) { char name[80]; - sprintf(name, "/tmp/unlikely-%lu.out", (ulong) getpid()); + snprintf(name, sizeof(name), "/tmp/unlikely-%lu.out", (ulong) getpid()); if ((likely_file= my_fopen(name, O_TRUNC | O_WRONLY, MYF(MY_WME)))) do_close= 1; else diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 66c2543c51d..57ac2d228fb 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -426,7 +426,7 @@ const char *my_thread_name(void) if (!tmp->name[0]) { my_thread_id id= my_thread_dbug_id(); - sprintf(name_buff,"T@%lu", (ulong) id); + snprintf(name_buff, sizeof(name_buff), "T@%lu", (ulong) id); strmake_buf(tmp->name, name_buff); } return tmp->name; |