Ticket #20650

util.cのmy_strcpy関数でアクセスオーバーラン

Date d'ouverture: 2010-02-14 00:34 Dernière mise à jour: 2020-12-20 21:48

Rapporteur:
Propriétaire:
Type:
État:
Atteints
Composant:
(Aucun)
Priorité:
7
Sévérité:
7
Résolution:
Fixed
Fichier:
Aucun

Détails

現在のmy_strcpyの実装には問題があり、JPを定義してコンパイルした場合にバッファの範囲を超えてアクセスすることがあります。 その結果、my_strcpy関数はstrlcpy関数と同じ仕様のはずですが、意図したよりも大きな値が返ります。

以下は適切な終端処理を追加した修正パッチです。

diff -bud src_org/util.c src/util.c
--- src_org/util.c	Sat Feb 13 00:27:50 2010
+++ src/util.c	Sun Feb 14 00:06:27 2010
@@ -5221,6 +5221,7 @@
 	const char *s = src;
 	size_t len = 0;
 
+	if (bufsize != 0) {
 	/* reserve for NUL termination */
 	bufsize--;
 
@@ -5236,11 +5237,14 @@
 		}
 		else
 		{
+				if (!*s) break;
 			*d++ = *s++;
 			len++;
 		}
 	}
 	*d = '\0';
+	}
+
 	while(*s++) len++;
 
 	return len;

Ticket History (3/5 Histories)

2010-02-14 00:34 Updated by: shimitei
  • New Ticket "util.cのmy_strcpy関数でアクセスオーバーラン" created
2010-02-14 13:17 Updated by: habu
  • Ticket Close date is changed to 2010-02-14 13:17
  • État Update from Ouvert to Atteints
2010-02-14 13:19 Updated by: habu
  • État Update from Atteints to Ouvert
2010-02-14 13:20 Updated by: habu
  • Ticket Close date is changed to 2010-02-14 13:20
  • État Update from Ouvert to Atteints
Commentaire

すこし形を変えてr3078で修正しました。

2020-12-20 21:48 Updated by: deskull

Attachment File List

No attachments

Modifier

Please login to add comment to this ticket » Connexion