Fossil SCM

Potential fix for [746a5106f92287036c12c945d9d7358a1263301e].

stephan 2023-05-15 16:43 trunk
Commit d6a4ab227644cadb977c3e5e0b8d31bbe5c560e4041dd833405d33890fafa276
3 files changed +21 +13 +9 -4
+21
--- src/th.c
+++ src/th.c
@@ -1269,10 +1269,31 @@
12691269
return TH_ERROR;
12701270
}
12711271
12721272
return Th_SetResult(interp, pValue->zData, pValue->nData);
12731273
}
1274
+
1275
+/*
1276
+** If interp has a variable with the given name, its value is returned
1277
+** and its length is returned via *nOut if nOut is not NULL. If
1278
+** interp has no such var then NULL is returned without setting any
1279
+** error state and *nOut, if not NULL, is set to -1. The returned value
1280
+** is owned by the interpreter and may be invalidated the next time
1281
+** the interpreter is modified.
1282
+*/
1283
+const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName,
1284
+ int *nOut){
1285
+ Th_Variable *pValue;
1286
+
1287
+ pValue = thFindValue(interp, zVarName, -1, 0, 0, 1, 0);
1288
+ if( !pValue || !pValue->zData ){
1289
+ if( nOut!=0 ) *nOut = -1;
1290
+ return NULL;
1291
+ }
1292
+ if( nOut!=0 ) *nOut = pValue->nData;
1293
+ return pValue->zData;
1294
+}
12741295
12751296
/*
12761297
** Return true if variable (zVar, nVar) exists.
12771298
*/
12781299
int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){
12791300
--- src/th.c
+++ src/th.c
@@ -1269,10 +1269,31 @@
1269 return TH_ERROR;
1270 }
1271
1272 return Th_SetResult(interp, pValue->zData, pValue->nData);
1273 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1274
1275 /*
1276 ** Return true if variable (zVar, nVar) exists.
1277 */
1278 int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){
1279
--- src/th.c
+++ src/th.c
@@ -1269,10 +1269,31 @@
1269 return TH_ERROR;
1270 }
1271
1272 return Th_SetResult(interp, pValue->zData, pValue->nData);
1273 }
1274
1275 /*
1276 ** If interp has a variable with the given name, its value is returned
1277 ** and its length is returned via *nOut if nOut is not NULL. If
1278 ** interp has no such var then NULL is returned without setting any
1279 ** error state and *nOut, if not NULL, is set to -1. The returned value
1280 ** is owned by the interpreter and may be invalidated the next time
1281 ** the interpreter is modified.
1282 */
1283 const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName,
1284 int *nOut){
1285 Th_Variable *pValue;
1286
1287 pValue = thFindValue(interp, zVarName, -1, 0, 0, 1, 0);
1288 if( !pValue || !pValue->zData ){
1289 if( nOut!=0 ) *nOut = -1;
1290 return NULL;
1291 }
1292 if( nOut!=0 ) *nOut = pValue->nData;
1293 return pValue->zData;
1294 }
1295
1296 /*
1297 ** Return true if variable (zVar, nVar) exists.
1298 */
1299 int Th_ExistsVar(Th_Interp *interp, const char *zVar, int nVar){
1300
+13
--- src/th.h
+++ src/th.h
@@ -56,10 +56,23 @@
5656
int Th_GetVar(Th_Interp *, const char *, int);
5757
int Th_SetVar(Th_Interp *, const char *, int, const char *, int);
5858
int Th_LinkVar(Th_Interp *, const char *, int, int, const char *, int);
5959
int Th_UnsetVar(Th_Interp *, const char *, int);
6060
61
+/*
62
+** If interp has a variable with the given name, its value is returned
63
+** and its length is returned via *nOut if nOut is not NULL. If
64
+** interp has no such var then NULL is returned without setting any
65
+** error state and *nOut, if not NULL, is set to 0. The returned value
66
+** is owned by the interpreter and may be invalidated the next time
67
+** the interpreter is modified.
68
+**
69
+** zVarName must be NUL-terminated.
70
+*/
71
+const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName,
72
+ int *nOut);
73
+
6174
typedef int (*Th_CommandProc)(Th_Interp *, void *, int, const char **, int *);
6275
6376
/*
6477
** Register new commands.
6578
*/
6679
--- src/th.h
+++ src/th.h
@@ -56,10 +56,23 @@
56 int Th_GetVar(Th_Interp *, const char *, int);
57 int Th_SetVar(Th_Interp *, const char *, int, const char *, int);
58 int Th_LinkVar(Th_Interp *, const char *, int, int, const char *, int);
59 int Th_UnsetVar(Th_Interp *, const char *, int);
60
 
 
 
 
 
 
 
 
 
 
 
 
 
61 typedef int (*Th_CommandProc)(Th_Interp *, void *, int, const char **, int *);
62
63 /*
64 ** Register new commands.
65 */
66
--- src/th.h
+++ src/th.h
@@ -56,10 +56,23 @@
56 int Th_GetVar(Th_Interp *, const char *, int);
57 int Th_SetVar(Th_Interp *, const char *, int, const char *, int);
58 int Th_LinkVar(Th_Interp *, const char *, int, int, const char *, int);
59 int Th_UnsetVar(Th_Interp *, const char *, int);
60
61 /*
62 ** If interp has a variable with the given name, its value is returned
63 ** and its length is returned via *nOut if nOut is not NULL. If
64 ** interp has no such var then NULL is returned without setting any
65 ** error state and *nOut, if not NULL, is set to 0. The returned value
66 ** is owned by the interpreter and may be invalidated the next time
67 ** the interpreter is modified.
68 **
69 ** zVarName must be NUL-terminated.
70 */
71 const char * Th_MaybeGetVar(Th_Interp *interp, const char *zVarName,
72 int *nOut);
73
74 typedef int (*Th_CommandProc)(Th_Interp *, void *, int, const char **, int *);
75
76 /*
77 ** Register new commands.
78 */
79
+9 -4
--- src/tkt.c
+++ src/tkt.c
@@ -997,11 +997,11 @@
997997
** when you press submit - it just prints the ticket artifact at the
998998
** top of the screen.
999999
*/
10001000
void tktnew_page(void){
10011001
const char *zScript;
1002
- char *zEmail = 0, *zNewUuid = 0;
1002
+ char *zNewUuid = 0;
10031003
int uid;
10041004
10051005
login_check_credentials();
10061006
if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; }
10071007
if( P("cancel") ){
@@ -1021,16 +1021,21 @@
10211021
if( P("date_override") && g.perm.Setup ){
10221022
@ <input type="hidden" name="date_override" value="%h(P("date_override"))">
10231023
}
10241024
zScript = ticket_newpage_code();
10251025
if( g.zLogin && g.zLogin[0] ){
1026
- uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin);
1026
+ int nEmail = 0;
1027
+ (void)Th_MaybeGetVar(g.interp, "private_contact", &nEmail);
1028
+ uid = nEmail>0
1029
+ ? 0 : db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin);
10271030
if( uid ){
1028
- zEmail = db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d",
1029
- uid);
1031
+ char * zEmail =
1032
+ db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d",
1033
+ uid);
10301034
if( zEmail ){
10311035
Th_Store("private_contact", zEmail);
1036
+ fossil_free(zEmail);
10321037
}
10331038
}
10341039
}
10351040
Th_Store("login", login_name());
10361041
Th_Store("date", db_text(0, "SELECT datetime('now')"));
10371042
--- src/tkt.c
+++ src/tkt.c
@@ -997,11 +997,11 @@
997 ** when you press submit - it just prints the ticket artifact at the
998 ** top of the screen.
999 */
1000 void tktnew_page(void){
1001 const char *zScript;
1002 char *zEmail = 0, *zNewUuid = 0;
1003 int uid;
1004
1005 login_check_credentials();
1006 if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; }
1007 if( P("cancel") ){
@@ -1021,16 +1021,21 @@
1021 if( P("date_override") && g.perm.Setup ){
1022 @ <input type="hidden" name="date_override" value="%h(P("date_override"))">
1023 }
1024 zScript = ticket_newpage_code();
1025 if( g.zLogin && g.zLogin[0] ){
1026 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin);
 
 
 
1027 if( uid ){
1028 zEmail = db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d",
1029 uid);
 
1030 if( zEmail ){
1031 Th_Store("private_contact", zEmail);
 
1032 }
1033 }
1034 }
1035 Th_Store("login", login_name());
1036 Th_Store("date", db_text(0, "SELECT datetime('now')"));
1037
--- src/tkt.c
+++ src/tkt.c
@@ -997,11 +997,11 @@
997 ** when you press submit - it just prints the ticket artifact at the
998 ** top of the screen.
999 */
1000 void tktnew_page(void){
1001 const char *zScript;
1002 char *zNewUuid = 0;
1003 int uid;
1004
1005 login_check_credentials();
1006 if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; }
1007 if( P("cancel") ){
@@ -1021,16 +1021,21 @@
1021 if( P("date_override") && g.perm.Setup ){
1022 @ <input type="hidden" name="date_override" value="%h(P("date_override"))">
1023 }
1024 zScript = ticket_newpage_code();
1025 if( g.zLogin && g.zLogin[0] ){
1026 int nEmail = 0;
1027 (void)Th_MaybeGetVar(g.interp, "private_contact", &nEmail);
1028 uid = nEmail>0
1029 ? 0 : db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin);
1030 if( uid ){
1031 char * zEmail =
1032 db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d",
1033 uid);
1034 if( zEmail ){
1035 Th_Store("private_contact", zEmail);
1036 fossil_free(zEmail);
1037 }
1038 }
1039 }
1040 Th_Store("login", login_name());
1041 Th_Store("date", db_text(0, "SELECT datetime('now')"));
1042

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button