From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Sat, 28 Feb 2004 01:52:29 +0000 Subject: udev - safer sprintf() use Message-Id: <20040228015229.GA31877@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="5mCyUwZo2JvN/JJP" List-Id: To: linux-hotplug@vger.kernel.org --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Here is for now my last patch to the string handling for a rather theorethical case, where the node is very very very long. :) We have accordant to strfieldcat(to, from) now a strintcat(to, i) macro, which appends the ascii representation of a integer to a string in a safe way. thanks, Kay --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="01-strcat.patch" ===== namedev.c 1.116 vs edited ===== --- 1.116/namedev.c Thu Feb 26 22:29:48 2004 +++ edited/namedev.c Sat Feb 28 02:41:27 2004 @@ -263,11 +263,11 @@ dbg("substitute kernel number '%s'", udev->kernel_number); break; case 'm': - sprintf(pos, "%u", udev->minor); + strnintcat(string, udev->minor, maxsize); dbg("substitute minor number '%u'", udev->minor); break; - case 'M': - sprintf(pos, "%u", udev->major); + case 'M': + strnintcat(string, udev->major, maxsize); dbg("substitute major number '%u'", udev->major); break; case 'c': ===== udev-add.c 1.52 vs edited ===== --- 1.52/udev-add.c Fri Feb 27 00:11:36 2004 +++ edited/udev-add.c Sat Feb 28 02:41:27 2004 @@ -211,7 +211,8 @@ info("creating device partition nodes '%s[1-%i]'", filename, dev->partitions); if (!fake) { for (i = 1; i <= dev->partitions; i++) { - sprintf(partitionname, "%s%i", filename, i); + strfieldcpy(partitionname, filename); + strintcat(partitionname, i); make_node(partitionname, dev->major, dev->minor + i, dev->mode, uid, gid); } ===== udev-remove.c 1.20 vs edited ===== --- 1.20/udev-remove.c Wed Feb 25 01:04:14 2004 +++ edited/udev-remove.c Sat Feb 28 02:41:28 2004 @@ -87,7 +87,8 @@ if (dev->partitions > 0) { info("removing partitions '%s[1-%i]'", filename, dev->partitions); for (i = 1; i <= dev->partitions; i++) { - sprintf(partitionname, "%s%i", filename, i); + strfieldcpy(partitionname, filename); + strintcat(partitionname, i); unlink(partitionname); } } ===== udev.h 1.47 vs edited ===== --- 1.47/udev.h Thu Feb 26 06:14:04 2004 +++ edited/udev.h Sat Feb 28 02:41:28 2004 @@ -85,6 +85,18 @@ strncat(to, from, maxsize - strlen(to)-1); \ } while (0) +#define strintcat(to, i) \ +do { \ + to[sizeof(to)-1] = '\0'; \ + snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%u", i); \ +} while (0) + +#define strnintcat(to, i, maxsize) \ +do { \ + to[maxsize-1] = '\0'; \ + snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \ +} while (0) + static inline char *get_action(void) { char *action; --5mCyUwZo2JvN/JJP-- ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel